code.gitea.io/gitea@v1.21.7/services/secrets/validation.go (about)

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