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

Function UserSecretNameValid

codersdk/usersecretvalidation.go:214–228  ·  view source on GitHub ↗

UserSecretNameValid validates a user secret name. Names are used in API route path segments, so they must not include route separators.

(s string)

Source from the content-addressed store, hash-verified

212// UserSecretNameValid validates a user secret name. Names are used in
213// API route path segments, so they must not include route separators.
214func UserSecretNameValid(s string) error {
215 if strings.TrimSpace(s) == "" {
216 return xerrors.New("Name is required.")
217 }
218
219 if strings.TrimSpace(s) != s {
220 return xerrors.New("Name must not have leading or trailing whitespace.")
221 }
222
223 if strings.ContainsAny(s, "/?#") {
224 return xerrors.New("Name must not contain /, ?, or #.")
225 }
226
227 return nil
228}
229
230// UserSecretEnvNameValid validates an environment variable name for
231// a user secret. Empty string is allowed (means no env injection).

Callers 2

TestUserSecretNameValidFunction · 0.92

Calls 1

NewMethod · 0.65

Tested by 1

TestUserSecretNameValidFunction · 0.74