ReadConfigFile attempts to read the config file, if it exists
()
| 933 | |
| 934 | // ReadConfigFile attempts to read the config file, if it exists |
| 935 | func (mctx *MigrationContext) ReadConfigFile() error { |
| 936 | mctx.configMutex.Lock() |
| 937 | defer mctx.configMutex.Unlock() |
| 938 | |
| 939 | if mctx.ConfigFile == "" { |
| 940 | return nil |
| 941 | } |
| 942 | cfg, err := ini.Load(mctx.ConfigFile) |
| 943 | if err != nil { |
| 944 | return err |
| 945 | } |
| 946 | |
| 947 | if cfg.Section("client").HasKey("user") { |
| 948 | mctx.config.Client.User = cfg.Section("client").Key("user").String() |
| 949 | } |
| 950 | |
| 951 | if cfg.Section("client").HasKey("password") { |
| 952 | mctx.config.Client.Password = cfg.Section("client").Key("password").String() |
| 953 | } |
| 954 | |
| 955 | if cfg.Section("osc").HasKey("chunk_size") { |
| 956 | mctx.config.Osc.Chunk_Size, err = cfg.Section("osc").Key("chunk_size").Int64() |
| 957 | if err != nil { |
| 958 | return fmt.Errorf("unable to read osc chunk size: %w", err) |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | if cfg.Section("osc").HasKey("max_load") { |
| 963 | mctx.config.Osc.Max_Load = cfg.Section("osc").Key("max_load").String() |
| 964 | } |
| 965 | |
| 966 | if cfg.Section("osc").HasKey("replication_lag_query") { |
| 967 | mctx.config.Osc.Replication_Lag_Query = cfg.Section("osc").Key("replication_lag_query").String() |
| 968 | } |
| 969 | |
| 970 | if cfg.Section("osc").HasKey("max_lag_millis") { |
| 971 | mctx.config.Osc.Max_Lag_Millis, err = cfg.Section("osc").Key("max_lag_millis").Int64() |
| 972 | if err != nil { |
| 973 | return fmt.Errorf("unable to read max lag millis: %w", err) |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | // We accept user & password in the form "${SOME_ENV_VARIABLE}" in which case we pull |
| 978 | // the given variable from os env |
| 979 | if submatch := envVariableRegexp.FindStringSubmatch(mctx.config.Client.User); len(submatch) > 1 { |
| 980 | mctx.config.Client.User = os.Getenv(submatch[1]) |
| 981 | } |
| 982 | if submatch := envVariableRegexp.FindStringSubmatch(mctx.config.Client.Password); len(submatch) > 1 { |
| 983 | mctx.config.Client.Password = os.Getenv(submatch[1]) |
| 984 | } |
| 985 | |
| 986 | return nil |
| 987 | } |
| 988 | |
| 989 | // getGhostTriggerName generates the name of a ghost trigger, based on original trigger name |
| 990 | // or a given trigger name |