Skip to content

Commit

Permalink
fix(serviceaccount): update regex pattern for description
Browse files Browse the repository at this point in the history
  • Loading branch information
Enda Phelan committed Apr 9, 2021
1 parent 1cdfad8 commit 8bb60e5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/rhoas/pkged.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/commands/rhoas_serviceaccount_create.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $ rhoas serviceaccount create --file-location=./service-acct-credentials.json
=== Options

....
--description string Description for the service account.
--description string Description for the service account. Only alphanumeric characters and '-', '.', ',' are accepted.
--file-format string Format in which to save the service account credentials. Choose from: "env", "json", "properties"
--file-location string Sets a custom file location to save the credentials.
--name string Name of the service account.
Expand Down
4 changes: 2 additions & 2 deletions locales/cmd/serviceaccount/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ one = 'service account name cannot exceed {{.MaxNameLen}} characters'
one = 'invalid service account name "{{.Name}}"; only lowercase letters (a-z), numbers, and "-" are accepted'

[serviceAccount.common.validation.description.error.invalidChars]
one = 'invalid service account description "{{.Description}}"; only alphanumeric characters are accepted'
one = 'invalid service account description; only alphanumeric characters and "-", ".", "," are accepted.'

[serviceAccount.common.validation.description.error.lengthError]
one = 'service account description cannot exceed {{.MaxNameLen}} characters'
one = 'service account description cannot exceed {{.MaxLen}} characters'
2 changes: 1 addition & 1 deletion locales/cmd/serviceaccount/create/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ one = 'Name of the service account.'

[serviceAccount.create.flag.description.description]
description = 'Description for --description flag'
one = 'Description for the service account.'
one = "Description for the service account. Only alphanumeric characters and '-', '.', ',' are accepted."

[serviceAccount.create.error.couldNotCreate]
description = 'Error message when service account could not be created'
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/serviceaccount/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ func runInteractivePrompt(opts *Options) (err error) {
return err
}

promptDescription := &survey.Multiline{Message: localizer.MustLocalizeFromID("serviceAccount.create.input.description.message")}
promptDescription := &survey.Multiline{
Message: localizer.MustLocalizeFromID("serviceAccount.create.input.description.message"),
Help: localizer.MustLocalizeFromID("serviceAccount.create.flag.description.description"),
}

err = survey.AskOne(promptDescription, &opts.description, survey.WithValidator(validation.ValidateDescription))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/serviceaccount/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
maxNameLength = 50
minNameLength = 1
// description validation rules
legalDescriptionChars = "^[a-zA-Z0-9\\s]*$"
legalDescriptionChars = "^[a-zA-Z0-9.,\\-\\s]*$"
maxDescriptionLength = 255
)

Expand Down Expand Up @@ -76,7 +76,7 @@ func ValidateDescription(val interface{}) error {
return errors.New(localizer.MustLocalize(&localizer.Config{
MessageID: "serviceAccount.common.validation.description.error.lengthError",
TemplateData: map[string]interface{}{
"MaxNameLen": maxDescriptionLength,
"MaxLen": maxDescriptionLength,
},
}))
}
Expand Down

0 comments on commit 8bb60e5

Please sign in to comment.