mirror of https://github.com/docker/docs.git
Move regex compilation to outside var for optimization
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
parent
aff9eb929a
commit
a64ffd4ae9
|
@ -26,6 +26,9 @@ var ValidRoles = map[string]string{
|
||||||
CanonicalTimestampRole: CanonicalTimestampRole,
|
CanonicalTimestampRole: CanonicalTimestampRole,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regex for validating delegation names
|
||||||
|
var delegationRegexp = regexp.MustCompile("^[-a-z0-9_/]+$")
|
||||||
|
|
||||||
// ErrNoSuchRole indicates the roles doesn't exist
|
// ErrNoSuchRole indicates the roles doesn't exist
|
||||||
type ErrNoSuchRole struct {
|
type ErrNoSuchRole struct {
|
||||||
Role string
|
Role string
|
||||||
|
@ -117,7 +120,6 @@ func ValidRole(name string) bool {
|
||||||
func IsDelegation(role string) bool {
|
func IsDelegation(role string) bool {
|
||||||
targetsBase := ValidRoles[CanonicalTargetsRole] + "/"
|
targetsBase := ValidRoles[CanonicalTargetsRole] + "/"
|
||||||
|
|
||||||
delegationRegexp := regexp.MustCompile("^[-a-z0-9_/]+$")
|
|
||||||
whitelistedChars := delegationRegexp.MatchString(role)
|
whitelistedChars := delegationRegexp.MatchString(role)
|
||||||
|
|
||||||
// Limit size of full role string to 255 chars for db column size limit
|
// Limit size of full role string to 255 chars for db column size limit
|
||||||
|
|
Loading…
Reference in New Issue