UserSecretNameValid validates a user secret name. Names are used in API route path segments, so they must not include route separators.
(s string)
| 212 | // UserSecretNameValid validates a user secret name. Names are used in |
| 213 | // API route path segments, so they must not include route separators. |
| 214 | func 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). |