Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,3 +774,14 @@ func Clean(props map[string]string, line string) string {
}
return line
}

// expandEnvVars replaces $KEY or ${KEY} with its environment variable value
// only if the variable is present in the environment.
// If not present, $KEY or ${KEY} will remain in the config text.
func ExpandEnvVars(text string) string {
for key, value := range g.KVArrToMap(os.Environ()...) {
text = strings.ReplaceAll(text, "$"+key+"", value)
text = strings.ReplaceAll(text, "${"+key+"}", value)
}
return text
}
19 changes: 4 additions & 15 deletions core/sling/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (cfg *Config) Unmarshal(cfgStr string) (err error) {
}()

// expand variables
cfgStr = expandEnvVars(cfgStr)
cfgStr = env.ExpandEnvVars(cfgStr)

cfgBytes := []byte(cfgStr)
_, errStat := os.Stat(cfgStr)
Expand Down Expand Up @@ -1644,7 +1644,7 @@ type CDCOptions struct {
SnapshotRunDuration *string `json:"snapshot_run_duration,omitempty" yaml:"snapshot_run_duration,omitempty"`

// Batching
RunMaxEvents *int `json:"run_max_events,omitempty" yaml:"run_max_events,omitempty"`
RunMaxEvents *int `json:"run_max_events,omitempty" yaml:"run_max_events,omitempty"`
RunMaxDuration *string `json:"run_max_duration,omitempty" yaml:"run_max_duration,omitempty"`

// Delete behavior
Expand Down Expand Up @@ -1834,8 +1834,8 @@ var TargetDBOptionsDefault = TargetOptions{
}

var CDCOptionsDefault = CDCOptions{
RunMaxEvents: g.Int(100000),
RunMaxDuration: g.String("10m"),
RunMaxEvents: g.Int(100000),
RunMaxDuration: g.String("10m"),
SnapshotStart: g.String("now"),
SoftDelete: g.Bool(false),
RetryAttempts: g.Int(3),
Expand Down Expand Up @@ -2033,17 +2033,6 @@ func castKeyArray(keyI any) (key []string) {
return
}

// expandEnvVars replaces $KEY or ${KEY} with its environment variable value
// only if the variable is present in the environment.
// If not present, $KEY or ${KEY} will remain in the config text.
func expandEnvVars(text string) string {
for key, value := range g.KVArrToMap(os.Environ()...) {
text = strings.ReplaceAll(text, "$"+key+"", value)
text = strings.ReplaceAll(text, "${"+key+"}", value)
}
return text
}

func cleanConnURL(payload, connURL string) string {
cleanSource := strings.Split(connURL, "://")[0] + "://"
payload = strings.ReplaceAll(payload, g.Marshal(connURL), g.Marshal(cleanSource))
Expand Down
2 changes: 1 addition & 1 deletion core/sling/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ReplicationConfig struct {
maps replicationConfigMaps // raw maps for validation
state *ReplicationState

CDCRunner CDCRunner
CDCRunner CDCRunner `json:"-"`
}

type CDCRunner interface {
Expand Down