Skip to content

Commit

Permalink
error instead of overwriting existing slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed May 22, 2020
1 parent 7144a13 commit 01342a8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kotsadm/pkg/redact/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func SetRedactYaml(name, slug, description string, enabled, newRedact bool, yaml
slug = getSlug(newRedactorSpec.Name)
}

if _, ok := configMap.Data[slug]; ok {
// the target slug already exists - this is an error
return nil, fmt.Errorf("refusing to create new redact spec with name %s - slug %s already exists", newRedactorSpec.Name, slug)
}

// create the new redactor
redactorEntry.Metadata = RedactorList{
Name: newRedactorSpec.Name,
Expand All @@ -209,6 +214,12 @@ func SetRedactYaml(name, slug, description string, enabled, newRedact bool, yaml

if slug != getSlug(newRedactorSpec.Name) && newRedactorSpec.Name != "" {
// changing name

if _, ok := configMap.Data[getSlug(newRedactorSpec.Name)]; ok {
// the target slug already exists - this is an error
return nil, fmt.Errorf("refusing to change slug from %s to %s as that already exists", slug, getSlug(newRedactorSpec.Name))
}

delete(configMap.Data, slug)
slug = getSlug(newRedactorSpec.Name)
redactorEntry.Metadata.Slug = slug
Expand Down

0 comments on commit 01342a8

Please sign in to comment.