Merge pull request #1299 from thaJeztah/store_cleanup

store: move regex to where it's used
This commit is contained in:
CrazyMax 2022-08-31 19:35:05 +02:00 committed by GitHub
commit aeac42be47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"os"
"path/filepath"
"regexp"
"sort"
"github.com/docker/docker/pkg/ioutils"
@ -199,8 +198,6 @@ type current struct {
Global bool
}
var namePattern = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\.\-_]*$`)
func toHash(in string) string {
return digest.FromBytes([]byte(in)).Hex()[:20]
}

View File

@ -2,12 +2,15 @@ package store
import (
"os"
"regexp"
"strings"
"github.com/docker/docker/pkg/namesgenerator"
"github.com/pkg/errors"
)
var namePattern = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\.\-_]*$`)
func ValidateName(s string) (string, error) {
if !namePattern.MatchString(s) {
return "", errors.Errorf("invalid name %s, name needs to start with a letter and may not contain symbols, except ._-", s)