Skip to content

Commit

Permalink
Only accept valid context keys (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmholmes authored Jan 3, 2024
1 parent 0412459 commit 01faa49
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,29 @@ func CurrentContext() (*Context, error) {
return &context, nil
}

var acceptableKeys = []string{
"grafana.url",
"grafana.token",
"grafana.user",
"mimir.address",
"mimir.tenant-id",
"mimir.api-key",
"synthetic-monitoring.token",
"synthetic-monitoring.stack-id",
"synthetic-monitoring.metrics-id",
"synthetic-monitoring.logs-id",
}

func Set(path string, value string) error {
found := false
for _, key := range acceptableKeys {
if path == key {
found = true
}
}
if !found {
return fmt.Errorf("Key not recognised: %s", path)
}
ctx := viper.GetString(CURRENT_CONTEXT)
fullPath := fmt.Sprintf("contexts.%s.%s", ctx, path)
viper.Set(fullPath, value)
Expand Down

0 comments on commit 01faa49

Please sign in to comment.