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(serviceaccount): update regex pattern for description #552

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/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