Chromium Code Reviews| Index: go/src/infra/tools/cipd/common.go |
| diff --git a/go/src/infra/tools/cipd/common.go b/go/src/infra/tools/cipd/common.go |
| index 3bcc9da209552737dc63e307f5fe07c2c64f27a4..9f424b25f96ae1c27e3f917170471be19f60dacf 100644 |
| --- a/go/src/infra/tools/cipd/common.go |
| +++ b/go/src/infra/tools/cipd/common.go |
| @@ -10,6 +10,7 @@ import ( |
| "io" |
| "io/ioutil" |
| "regexp" |
| + "strings" |
| "infra/libs/build" |
| ) |
| @@ -20,10 +21,13 @@ const packageServiceDir = ".cipdpkg" |
| // Name of the directory inside an installation root reserved for cipd stuff. |
| const siteServiceDir = ".cipd" |
| -// packageNameRe is a Regular expression for a package name: <word>/<word/<word> |
| +// packageNameRe is a regular expression for a package name: <word>/<word/<word> |
| // Package names must be lower case. |
| var packageNameRe = regexp.MustCompile(`^([a-z0-9_\-]+/)*[a-z0-9_\-]+$`) |
| +// instanceTagKeyRe is a regular expression for a tag key. |
| +var instanceTagKeyRe = regexp.MustCompile(`^[a-z0-9_\-]+$`) |
| + |
| // Name of the manifest file inside the package. |
| const manifestName = packageServiceDir + "/manifest.json" |
| @@ -58,6 +62,21 @@ func ValidateInstanceID(s string) error { |
| return nil |
| } |
| +// ValidateInstanceTag returns error is a string doesn't look like a valid tag. |
|
nodir
2015/05/07 04:19:02
s/is/if
Vadim Sh.
2015/05/07 05:07:58
Done.
|
| +func ValidateInstanceTag(t string) error { |
| + chunks := strings.Split(t, ":") |
|
nodir
2015/05/07 04:19:02
strings.SplitN(t, ":", 2)
otherwise it is inconsi
Vadim Sh.
2015/05/07 05:07:58
Good catch.
|
| + if len(chunks) != 2 { |
| + return fmt.Errorf("The string %q doesn't look a tag (a key:value pair)", t) |
|
nodir
2015/05/07 04:19:02
typo: look like
Vadim Sh.
2015/05/07 05:07:58
Done.
|
| + } |
| + if len(t) > 400 { |
| + return fmt.Errorf("The tag is too long: %q", t) |
| + } |
| + if !instanceTagKeyRe.MatchString(chunks[0]) { |
| + return fmt.Errorf("Invalid tag key in %q. Should be a lowercase word.", t) |
| + } |
| + return nil |
| +} |
| + |
| // DefaultServiceURL returns URL to a backend to use by default. |
| func DefaultServiceURL() string { |
| if build.ReleaseBuild { |