Skip to content

Commit

Permalink
remove 'name' param form request
Browse files Browse the repository at this point in the history
if no name present in yaml, give it a name like 'redactor-5'
  • Loading branch information
laverya committed May 22, 2020
1 parent b25a58d commit 15353b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
3 changes: 1 addition & 2 deletions kotsadm/pkg/handlers/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type ListRedactorsResponse struct {
}

type PostRedactorMetadata struct {
Name string `json:"name"`
Enabled bool `json:"enabled"`
Description string `json:"description"`
New bool `json:"new"`
Expand Down Expand Up @@ -312,7 +311,7 @@ func SetRedactMetadataAndYaml(w http.ResponseWriter, r *http.Request) {
return
}

newRedactor, err := redact.SetRedactYaml(updateRedactRequest.Name, redactorSlug, updateRedactRequest.Description, updateRedactRequest.Enabled, updateRedactRequest.New, []byte(updateRedactRequest.Redactor))
newRedactor, err := redact.SetRedactYaml(redactorSlug, updateRedactRequest.Description, updateRedactRequest.Enabled, updateRedactRequest.New, []byte(updateRedactRequest.Redactor))
if err != nil {
logger.Error(err)
metadataResponse.Error = "failed to update redactor"
Expand Down
18 changes: 5 additions & 13 deletions kotsadm/pkg/redact/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func SetRedactSpec(spec string) (string, error) {
}

// updates/creates an individual redact with the provided metadata and yaml
func SetRedactYaml(name, slug, description string, enabled, newRedact bool, yamlBytes []byte) (*RedactorMetadata, error) {
func SetRedactYaml(slug, description string, enabled, newRedact bool, yamlBytes []byte) (*RedactorMetadata, error) {
// parse yaml as redactor
newRedactorSpec := v1beta1.Redact{}
err := yaml.Unmarshal(yamlBytes, &newRedactorSpec)
Expand All @@ -181,15 +181,12 @@ func SetRedactYaml(name, slug, description string, enabled, newRedact bool, yaml
redactorEntry := RedactorMetadata{}
redactString, ok := configMap.Data[slug]
if !ok || newRedact {
// if name is not set in yaml or the request, take the name from the slug
// if name is not set in yaml, autogenerate a name
// if name is set, create the slug from the name
if newRedactorSpec.Name == "" && name == "" {
newRedactorSpec.Name = slug
if newRedactorSpec.Name == "" {
newRedactorSpec.Name = fmt.Sprintf("redactor-%d", len(configMap.Data)+1)
slug = getSlug(newRedactorSpec.Name)
} else {
// name in request overrides name in yaml
if name != "" {
newRedactorSpec.Name = name
}
slug = getSlug(newRedactorSpec.Name)
}

Expand All @@ -211,11 +208,6 @@ func SetRedactYaml(name, slug, description string, enabled, newRedact bool, yaml
return nil, errors.Wrapf(err, "unable to parse redactor %s", slug)
}

// name in request overrides name in spec
if name != newRedactorSpec.Name && name != "" {
newRedactorSpec.Name = name
}

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

Expand Down

0 comments on commit 15353b2

Please sign in to comment.