Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Unified Diff: go/src/infra/tools/cipd/common.go

Issue 1130733007: cipd: Add -tag option to 'create' and 'pkg-register' subcomands. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/common_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e4c2859eb2f84ce73d9bbc8f6d6a23ab3e01a9b2 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 if a string doesn't look like a valid tag.
+func ValidateInstanceTag(t string) error {
+ chunks := strings.SplitN(t, ":", 2)
+ if len(chunks) != 2 {
+ return fmt.Errorf("The string %q doesn't look like a tag (a key:value pair)", t)
+ }
+ 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 {
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/common_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698