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

d/api_management_user - updating the username validation #7975

Merged
merged 6 commits into from
Aug 10, 2020
Merged
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
8 changes: 5 additions & 3 deletions azurerm/helpers/validate/api_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validate
import (
"fmt"
"regexp"
"strings"
)

func ApiManagementChildName(v interface{}, k string) (warnings []string, errors []error) {
Expand All @@ -29,10 +30,11 @@ func ApiManagementServiceName(v interface{}, k string) (warnings []string, error
func ApiManagementUserName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)

// TODO: confirm this

if strings.HasPrefix(value, "-") || strings.HasSuffix(value, "-") {
errors = append(errors, fmt.Errorf("%q may not start or end with '-' character", k))
}
// from the portal: `The field may contain only numbers, letters, and dash (-) sign when preceded and followed by number or a letter.`
if matched := regexp.MustCompile(`(^[a-zA-Z0-9])([a-zA-Z0-9-]{1,78})([a-zA-Z0-9]$)`).Match([]byte(value)); !matched {
if matched := regexp.MustCompile(`(^([a-zA-Z0-9-]{1,80})$)`).Match([]byte(value)); !matched {
errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes up to 80 characters in length", k))
}

Expand Down