You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validation.go 638B

12345678910111213141516171819202122232425
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package secrets
  4. import (
  5. "regexp"
  6. "code.gitea.io/gitea/modules/util"
  7. )
  8. // https://docs.github.com/en/actions/security-guides/encrypted-secrets#naming-your-secrets
  9. var (
  10. namePattern = regexp.MustCompile("(?i)^[A-Z_][A-Z0-9_]*$")
  11. forbiddenPrefixPattern = regexp.MustCompile("(?i)^GIT(EA|HUB)_")
  12. ErrInvalidName = util.NewInvalidArgumentErrorf("invalid secret name")
  13. )
  14. func ValidateName(name string) error {
  15. if !namePattern.MatchString(name) || forbiddenPrefixPattern.MatchString(name) {
  16. return ErrInvalidName
  17. }
  18. return nil
  19. }