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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package cipd 5 package cipd
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
11 "io/ioutil" 11 "io/ioutil"
12 "regexp" 12 "regexp"
13 "strings"
13 14
14 "infra/libs/build" 15 "infra/libs/build"
15 ) 16 )
16 17
17 // Name of the directory inside the package reserved for cipd stuff. 18 // Name of the directory inside the package reserved for cipd stuff.
18 const packageServiceDir = ".cipdpkg" 19 const packageServiceDir = ".cipdpkg"
19 20
20 // Name of the directory inside an installation root reserved for cipd stuff. 21 // Name of the directory inside an installation root reserved for cipd stuff.
21 const siteServiceDir = ".cipd" 22 const siteServiceDir = ".cipd"
22 23
23 // packageNameRe is a Regular expression for a package name: <word>/<word/<word> 24 // packageNameRe is a regular expression for a package name: <word>/<word/<word>
24 // Package names must be lower case. 25 // Package names must be lower case.
25 var packageNameRe = regexp.MustCompile(`^([a-z0-9_\-]+/)*[a-z0-9_\-]+$`) 26 var packageNameRe = regexp.MustCompile(`^([a-z0-9_\-]+/)*[a-z0-9_\-]+$`)
26 27
28 // instanceTagKeyRe is a regular expression for a tag key.
29 var instanceTagKeyRe = regexp.MustCompile(`^[a-z0-9_\-]+$`)
30
27 // Name of the manifest file inside the package. 31 // Name of the manifest file inside the package.
28 const manifestName = packageServiceDir + "/manifest.json" 32 const manifestName = packageServiceDir + "/manifest.json"
29 33
30 // Format version to write to the manifest file. 34 // Format version to write to the manifest file.
31 const manifestFormatVersion = "1" 35 const manifestFormatVersion = "1"
32 36
33 // Manifest defines structure of manifest.json file. 37 // Manifest defines structure of manifest.json file.
34 type Manifest struct { 38 type Manifest struct {
35 FormatVersion string `json:"format_version"` 39 FormatVersion string `json:"format_version"`
36 PackageName string `json:"package_name"` 40 PackageName string `json:"package_name"`
(...skipping 14 matching lines...) Expand all
51 return fmt.Errorf("Not a valid package instance ID \"%s\": not 4 0 bytes", s) 55 return fmt.Errorf("Not a valid package instance ID \"%s\": not 4 0 bytes", s)
52 } 56 }
53 for _, c := range s { 57 for _, c := range s {
54 if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')) { 58 if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')) {
55 return fmt.Errorf("Not a valid package instance ID \"%s\ ": wrong char %c", s, c) 59 return fmt.Errorf("Not a valid package instance ID \"%s\ ": wrong char %c", s, c)
56 } 60 }
57 } 61 }
58 return nil 62 return nil
59 } 63 }
60 64
65 // ValidateInstanceTag returns error if a string doesn't look like a valid tag.
66 func ValidateInstanceTag(t string) error {
67 chunks := strings.SplitN(t, ":", 2)
68 if len(chunks) != 2 {
69 return fmt.Errorf("The string %q doesn't look like a tag (a key: value pair)", t)
70 }
71 if len(t) > 400 {
72 return fmt.Errorf("The tag is too long: %q", t)
73 }
74 if !instanceTagKeyRe.MatchString(chunks[0]) {
75 return fmt.Errorf("Invalid tag key in %q. Should be a lowercase word.", t)
76 }
77 return nil
78 }
79
61 // DefaultServiceURL returns URL to a backend to use by default. 80 // DefaultServiceURL returns URL to a backend to use by default.
62 func DefaultServiceURL() string { 81 func DefaultServiceURL() string {
63 if build.ReleaseBuild { 82 if build.ReleaseBuild {
64 return "https://chrome-infra-packages.appspot.com" 83 return "https://chrome-infra-packages.appspot.com"
65 } 84 }
66 return "https://chrome-infra-packages-dev.appspot.com" 85 return "https://chrome-infra-packages-dev.appspot.com"
67 } 86 }
68 87
69 // readManifest reads and decodes manifest JSON from io.Reader. 88 // readManifest reads and decodes manifest JSON from io.Reader.
70 func readManifest(r io.Reader) (Manifest, error) { 89 func readManifest(r io.Reader) (Manifest, error) {
(...skipping 19 matching lines...) Expand all
90 return err 109 return err
91 } 110 }
92 111
93 // userAgent returns user agent string to send with each request. 112 // userAgent returns user agent string to send with each request.
94 func userAgent() string { 113 func userAgent() string {
95 if build.ReleaseBuild { 114 if build.ReleaseBuild {
96 return "cipd 1.0 release" 115 return "cipd 1.0 release"
97 } 116 }
98 return "cipd 1.0 testing" 117 return "cipd 1.0 testing"
99 } 118 }
OLDNEW
« 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