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

fix: bin/grafana saves invalid yaml #544

Merged
merged 1 commit into from
Oct 6, 2021
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
2 changes: 1 addition & 1 deletion cmd/tools/grafana/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func checkToken(opts *options, ignoreConfig bool) error {
}
tools.SetChildContentS("grafana_api_token", opts.token)
fmt.Printf("saving config file [%s]\n", configPath)
if err = conf.SafeConfig(params, configPath); err != nil {
if err = conf.SaveConfig(params, configPath); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func LoadHarvestConfig(configPath string) error {
return nil
}

func SafeConfig(n *node.Node, fp string) error {
func SaveConfig(n *node.Node, fp string) error {
return tree.Export(n, "yaml", fp)
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/tree/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ func Dump(root *node.Node) ([]byte, error) {

func dumpRecursive(node *node.Node, data *[][]byte, depth int) {
indentation := bytes.Repeat([]byte(" "), depth)
if len(node.GetName()) != 0 && len(node.GetContent()) != 0 {
parentName := "Root"
if node.GetParent() != nil {
parentName = node.GetParent().GetNameS()
}
// workaround to handle list of maps
if parentName == "labels" {
*data = append(*data, joinAll(indentation, []byte("- "), node.GetName(), []byte(": "), node.GetContent()))
} else if len(node.GetName()) != 0 && len(node.GetContent()) != 0 && parentName != "labels" {
*data = append(*data, joinAll(indentation, node.GetName(), []byte(": "), node.GetContent()))
} else if len(node.GetName()) != 0 {
*data = append(*data, joinAll(indentation, node.GetName(), []byte(":")))
Expand Down