Skip to content

Commit

Permalink
Merge pull request #7975 from rikribbers/apim-user-data-source
Browse files Browse the repository at this point in the history
d/api_management_user - updating the username validation
  • Loading branch information
tombuildsstuff authored Aug 10, 2020
2 parents 6fafe18 + 1edfa53 commit 226f12b
Showing 1 changed file with 5 additions and 3 deletions.
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

0 comments on commit 226f12b

Please sign in to comment.