Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce additional metadata field to Context #81

Merged
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
1 change: 1 addition & 0 deletions config/config_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ const (
KeyTelemetry = "telemetry"
KeyCLIId = "cliId"
KeySource = "source"
KeyAdditionalMetadata = "additionalMetadata"
)
23 changes: 18 additions & 5 deletions config/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,8 @@ func setContext(node *yaml.Node, ctx *configtypes.Context) (persist bool, err er
return false, errors.New("context name cannot be empty")
}

// Get Patch Strategies from config metadata
patchStrategies, err := GetConfigMetadataPatchStrategy()
if err != nil {
patchStrategies = make(map[string]string)
}
// Get Patch Strategies
patchStrategies := constructPatchStrategies()

var persistDiscoverySources bool

Expand Down Expand Up @@ -360,6 +357,22 @@ func setContext(node *yaml.Node, ctx *configtypes.Context) (persist bool, err er
return persistDiscoverySources || persist, err
}

// Get Patch Strategies from config metadata
// By default; AdditionalMetadata field will be patched in replace strategy if there are no patch strategies
func constructPatchStrategies() map[string]string {
patchStrategies, err := GetConfigMetadataPatchStrategy()
if err != nil {
patchStrategies = map[string]string{
"contexts.additionalMetadata": "replace",
}
}
// Verify if there are patch strategies defined for `contexts.additionalMetadata` if not set replace by default
if patchStrategies != nil && patchStrategies["contexts.additionalMetadata"] != "merge" {
patchStrategies["contexts.additionalMetadata"] = "replace"
}
return patchStrategies
}

func setCurrentContext(node *yaml.Node, ctx *configtypes.Context) (persist bool, err error) {
// Find current context node in the yaml node
keys := []nodeutils.Key{
Expand Down
Loading