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

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

Issue 1145423002: cipd: Client can resolve tags to instance IDs. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: resolve subcommand 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
Index: go/src/infra/tools/cipd/client.go
diff --git a/go/src/infra/tools/cipd/client.go b/go/src/infra/tools/cipd/client.go
index ab4b763ebd32efb2a9ab04909176abea2caa0fc6..29bbf580dabee743849e4d114f561168a2100688 100644
--- a/go/src/infra/tools/cipd/client.go
+++ b/go/src/infra/tools/cipd/client.go
@@ -276,6 +276,23 @@ func (client *Client) UploadToCAS(sha1 string, data io.ReadSeeker, session *Uplo
}
}
+// ResolveVersion converts an instance ID, a tag or a ref into a concrete Pin
+// by contacting the backend.
+func (client *Client) ResolveVersion(packageName, version string) (common.Pin, error) {
+ if err := common.ValidatePackageName(packageName); err != nil {
+ return common.Pin{}, err
+ }
+ // Is it instance ID already? Don't bother calling the backend.
+ if common.ValidateInstanceID(version) == nil {
+ return common.Pin{PackageName: packageName, InstanceID: version}, nil
+ }
+ if err := common.ValidateInstanceVersion(version); err != nil {
+ return common.Pin{}, err
+ }
+ client.Log.Infof("cipd: resolving version %q of %q...", version, packageName)
+ return client.remote.resolveVersion(packageName, version)
+}
+
// RegisterInstance makes the package instance available for clients by
// uploading it to the storage and registering it in the package repository.
// 'instance' is a package instance to register.
@@ -414,10 +431,8 @@ func (client *Client) FetchAndDeployInstance(root string, pin common.Pin) error
// by EnsurePackages function. It is a text file where each line has a form:
// <package name> <desired version>. Whitespaces are ignored. Lines that start
// with '#' are ignored. Version can be specified as instance ID, tag or ref.
-// Will resolve tags and refs to concrete instance IDs.
+// Will resolve tags and refs to concrete instance IDs by calling the backend.
func (client *Client) ProcessEnsureFile(r io.Reader) ([]common.Pin, error) {
- // TODO(vadimsh): Resolve tags to instance IDs.
-
lineNo := 0
makeError := func(msg string) error {
return fmt.Errorf("Failed to parse desired state (line %d): %s", lineNo, msg)
@@ -450,13 +465,17 @@ func (client *Client) ProcessEnsureFile(r io.Reader) ([]common.Pin, error) {
if err != nil {
return nil, makeError(err.Error())
}
- err = common.ValidateInstanceID(tokens[1])
+ err = common.ValidateInstanceVersion(tokens[1])
if err != nil {
return nil, makeError(err.Error())
}
// Good enough.
- out = append(out, common.Pin{PackageName: tokens[0], InstanceID: tokens[1]})
+ pin, err := client.ResolveVersion(tokens[0], tokens[1])
+ if err != nil {
+ return nil, err
+ }
+ out = append(out, pin)
}
return out, nil
@@ -565,6 +584,8 @@ type remote interface {
fetchACL(packagePath string) ([]PackageACL, error)
modifyACL(packagePath string, changes []PackageACLChange) error
+ resolveVersion(packageName, version string) (common.Pin, error)
+
initiateUpload(sha1 string) (*UploadSession, error)
finalizeUpload(sessionID string) (bool, error)
registerInstance(pin common.Pin) (*registerInstanceResponse, error)

Powered by Google App Engine
This is Rietveld 408576698