Merge pull request #427 from docker/delegation-var

Move regex compilation to outside var for optimization
This commit is contained in:
Riyaz Faizullabhoy 2016-01-07 09:50:47 -08:00
commit 320d565f3b
1 changed files with 3 additions and 1 deletions

View File

@ -26,6 +26,9 @@ var ValidRoles = map[string]string{
CanonicalTimestampRole: CanonicalTimestampRole,
}
// Regex for validating delegation names
var delegationRegexp = regexp.MustCompile("^[-a-z0-9_/]+$")
// ErrNoSuchRole indicates the roles doesn't exist
type ErrNoSuchRole struct {
Role string
@ -117,7 +120,6 @@ func ValidRole(name string) bool {
func IsDelegation(role string) bool {
targetsBase := ValidRoles[CanonicalTargetsRole] + "/"
delegationRegexp := regexp.MustCompile("^[-a-z0-9_/]+$")
whitelistedChars := delegationRegexp.MatchString(role)
// Limit size of full role string to 255 chars for db column size limit