GroupNameValid returns whether the input string is a valid group name.
(str string)
| 100 | |
| 101 | // GroupNameValid returns whether the input string is a valid group name. |
| 102 | func GroupNameValid(str string) error { |
| 103 | // We want to support longer names for groups to allow users to sync their |
| 104 | // group names with their identity providers without manual mapping. Related |
| 105 | // to: https://github.com/coder/coder/issues/15184 |
| 106 | limit := 255 |
| 107 | if len(str) > limit { |
| 108 | return xerrors.New(fmt.Sprintf("must be <= %d characters", limit)) |
| 109 | } |
| 110 | // Avoid conflicts with routes like /groups/new and /groups/create. |
| 111 | if str == "new" || str == "create" { |
| 112 | return xerrors.Errorf("cannot use %q as a name", str) |
| 113 | } |
| 114 | matched := UsernameValidRegex.MatchString(str) |
| 115 | if !matched { |
| 116 | return xerrors.New("must be alphanumeric with hyphens") |
| 117 | } |
| 118 | return nil |
| 119 | } |
| 120 | |
| 121 | // NormalizeUserRealName normalizes a user name such that it will pass |
| 122 | // validation by UserRealNameValid. This is done to avoid blocking |