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

Unified Diff: cipd/client/cipd/remote.go

Issue 2509803002: Add cipd selfupdate command. (Closed)
Patch Set: Add additional early-exit Created 4 years, 1 month 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 | « cipd/client/cipd/install_client_windows.go ('k') | cipd/client/cipd/remote_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cipd/client/cipd/remote.go
diff --git a/cipd/client/cipd/remote.go b/cipd/client/cipd/remote.go
index 3cd5bfa64a5d3d646ccd4d019e9538a8cbed0d7c..db899f9aa3f550399702f7821acfcfd8243615b7 100644
--- a/cipd/client/cipd/remote.go
+++ b/cipd/client/cipd/remote.go
@@ -347,6 +347,42 @@ func (r *remoteImpl) fetchInstance(ctx context.Context, pin common.Pin) (*fetchI
return nil, fmt.Errorf("unexpected reply status: %s", reply.Status)
}
+func (r *remoteImpl) fetchClientBinaryInfo(ctx context.Context, pin common.Pin) (*fetchClientBinaryInfoResponse, error) {
+ params, err := instanceParams(pin)
+ if err != nil {
+ return nil, err
+ }
+ endpoint := "repo/v1/client?" + params
+ var reply struct {
+ Status string `json:"status"`
+ ErrorMessage string `json:"error_message"`
+ Instance packageInstanceMsg `json:"instance"`
+ ClientBinary clientBinary `json:"client_binary"`
+ }
+ err = r.makeRequest(ctx, endpoint, "GET", nil, &reply)
+ if err != nil {
+ return nil, err
+ }
+ switch reply.Status {
+ case "SUCCESS":
+ ts, err := convertTimestamp(reply.Instance.RegisteredTs)
+ if err != nil {
+ return nil, err
+ }
+ return &fetchClientBinaryInfoResponse{
+ &InstanceInfo{pin, reply.Instance.RegisteredBy, UnixTime(ts)},
+ &reply.ClientBinary,
+ }, nil
+ case "PACKAGE_NOT_FOUND":
+ return nil, fmt.Errorf("package %q is not registered", pin.PackageName)
+ case "INSTANCE_NOT_FOUND":
+ return nil, fmt.Errorf("package %q doesn't have instance %q", pin.PackageName, pin.InstanceID)
+ case "ERROR":
+ return nil, errors.New(reply.ErrorMessage)
+ }
+ return nil, fmt.Errorf("unexpected reply status: %s", reply.Status)
+}
+
func (r *remoteImpl) fetchTags(ctx context.Context, pin common.Pin, tags []string) ([]TagInfo, error) {
endpoint, err := tagsEndpoint(pin, tags)
if err != nil {
@@ -724,14 +760,19 @@ func packageEndpoint(packageName string) (string, error) {
return "repo/v1/package?" + params.Encode(), nil
}
-func instanceEndpoint(pin common.Pin) (string, error) {
+func instanceParams(pin common.Pin) (string, error) {
if err := common.ValidatePin(pin); err != nil {
return "", err
}
params := url.Values{}
params.Add("package_name", pin.PackageName)
params.Add("instance_id", pin.InstanceID)
- return "repo/v1/instance?" + params.Encode(), nil
+ return params.Encode(), nil
+}
+
+func instanceEndpoint(pin common.Pin) (string, error) {
+ params, err := instanceParams(pin)
+ return "repo/v1/instance?" + params, err
}
func aclEndpoint(packagePath string) (string, error) {
« no previous file with comments | « cipd/client/cipd/install_client_windows.go ('k') | cipd/client/cipd/remote_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698