MCPcopy Index your code
hub / github.com/coder/coder / GroupNameValid

Function GroupNameValid

codersdk/name.go:102–119  ·  view source on GitHub ↗

GroupNameValid returns whether the input string is a valid group name.

(str string)

Source from the content-addressed store, hash-verified

100
101// GroupNameValid returns whether the input string is a valid group name.
102func 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

Callers 4

initFunction · 0.92
parseGroupFunction · 0.92
TestGroupNameValidFunction · 0.92
groupCreateMethod · 0.92

Calls 2

NewMethod · 0.65
ErrorfMethod · 0.45

Tested by 1

TestGroupNameValidFunction · 0.74