-
Notifications
You must be signed in to change notification settings - Fork 4
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 otellogs.config.override
- Loading branch information
Mikołaj Świątek
committed
Nov 28, 2022
1 parent
eb88c15
commit 01ffa3a
Showing
6 changed files
with
91 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/otellogs-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 otellogsconfigmerge | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type InputValues struct { | ||
Otellogs struct { | ||
Config struct { | ||
Override map[string]interface{} `yaml:"override,omitempty"` | ||
} `yaml:"config,omitempty"` | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} `yaml:"otellogs,omitempty"` | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} | ||
|
||
type OutputValues struct { | ||
Otellogs Otellogs `yaml:"otellogs,omitempty"` | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} | ||
|
||
type Otellogs 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, | ||
Otellogs: Otellogs{ | ||
Config: Config{ | ||
Merge: inputValues.Otellogs.Config.Override, | ||
}, | ||
Rest: inputValues.Otellogs.Rest, | ||
}, | ||
} | ||
return outputValues, nil | ||
} |
4 changes: 4 additions & 0 deletions
4
src/go/cmd/update-collection-v3/migrations/otellogs-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 @@ | ||
otellogs: | ||
config: | ||
override: | ||
key: value |
4 changes: 4 additions & 0 deletions
4
src/go/cmd/update-collection-v3/migrations/otellogs-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 @@ | ||
otellogs: | ||
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