-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(update-collection-v3): migrate otelevents.config.override
- Loading branch information
Mikołaj Świątek
committed
Nov 25, 2022
1 parent
5573f7e
commit 17408d9
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/go/cmd/update-collection-v3/migrations/events-config-merge/migrate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package eventsconfigmerge | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type InputValues struct { | ||
Otelevents struct { | ||
Config struct { | ||
Override map[string]interface{} `yaml:"override,omitempty"` | ||
} `yaml:"config,omitempty"` | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} `yaml:"otelevents,omitempty"` | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} | ||
|
||
type OutputValues struct { | ||
Otelevents Otelevents `yaml:"otelevents,omitempty"` | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} | ||
|
||
type Otelevents struct { | ||
Config Config `yaml:"config,omitempty"` | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} | ||
|
||
type Config struct { | ||
Merge map[string]interface{} `yaml:"merge,omitempty"` | ||
Override map[string]interface{} `yaml:"override,omitempty"` | ||
} | ||
|
||
func Migrate(inputYaml string) (outputYaml string, err error) { | ||
inputValues, err := parseValues(inputYaml) | ||
if err != nil { | ||
return "", fmt.Errorf("error parsing input yaml: %v", err) | ||
} | ||
|
||
outputValues, err := migrate(&inputValues) | ||
if err != nil { | ||
return "", fmt.Errorf("error migrating: %v", err) | ||
} | ||
|
||
buffer := bytes.Buffer{} | ||
encoder := yaml.NewEncoder(&buffer) | ||
encoder.SetIndent(2) | ||
err = encoder.Encode(outputValues) | ||
return buffer.String(), err | ||
} | ||
|
||
func parseValues(inputYaml string) (InputValues, error) { | ||
var inputValues InputValues | ||
err := yaml.Unmarshal([]byte(inputYaml), &inputValues) | ||
return inputValues, err | ||
} | ||
|
||
func migrate(inputValues *InputValues) (OutputValues, error) { | ||
outputValues := OutputValues{ | ||
Rest: inputValues.Rest, | ||
Otelevents: Otelevents{ | ||
Config: Config{ | ||
Merge: inputValues.Otelevents.Config.Override, | ||
}, | ||
Rest: inputValues.Otelevents.Rest, | ||
}, | ||
} | ||
return outputValues, nil | ||
} |
4 changes: 4 additions & 0 deletions
4
src/go/cmd/update-collection-v3/migrations/events-config-merge/testdata/basic.input.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
otelevents: | ||
config: | ||
override: | ||
key: value |
4 changes: 4 additions & 0 deletions
4
src/go/cmd/update-collection-v3/migrations/events-config-merge/testdata/basic.output.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
otelevents: | ||
config: | ||
merge: | ||
key: value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
otelevents: | ||
config: | ||
merge: | ||
key: value | ||
sumologic: | ||
accessId: xxx | ||
accessKey: yyy | ||
|