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

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

Issue 1194803002: Add a package listing API to cipd. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 6 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/remote.go
diff --git a/go/src/infra/tools/cipd/remote.go b/go/src/infra/tools/cipd/remote.go
index 8856d7ce57a9a8d366183939b511dd036e26712d..f29da688ef964b50480e8d4d9f0e95fc717e8f51 100644
--- a/go/src/infra/tools/cipd/remote.go
+++ b/go/src/infra/tools/cipd/remote.go
@@ -126,7 +126,7 @@ func (r *remoteImpl) makeRequest(path, method string, request, response interfac
if resp.StatusCode == 403 || resp.StatusCode == 401 {
return ErrAccessDenined
}
- return fmt.Errorf("Unexpected reply (HTTP %d):\n%s", resp.StatusCode, string(body))
+ return fmt.Errorf("Unexpected reply (HTTP %d):\n%s", resp.StatusCode, string(responseBody))
}
return ErrBackendInaccessible
@@ -418,6 +418,32 @@ func (r *remoteImpl) attachTags(pin common.Pin, tags []string) error {
return fmt.Errorf("Unexpected status when attaching tags: %s", reply.Status)
}
+func (r *remoteImpl) listPackages(path string, recursive bool) ([]string, []string, error) {
+ endpoint, err := packageEndpoint(path, recursive)
+ if err != nil {
+ return nil, nil, err
+ }
+ var reply struct {
+ Status string `json:"status"`
+ ErrorMessage string `json:"error_message"`
+ Packages []string `json:"packages"`
+ Directories []string `json:"directories"`
+ }
+ err = r.makeRequest(endpoint, "GET", nil, &reply)
+ if err != nil {
+ return nil, nil, err
+ }
+ switch reply.Status {
+ case "SUCCESS":
+ packages := reply.Packages
+ directories := reply.Directories
+ return packages, directories, nil
+ case "ERROR":
+ return nil, nil, errors.New(reply.ErrorMessage)
+ }
+ return nil, nil, fmt.Errorf("Unexpected list packages status: %s", reply.Status)
+}
+
////////////////////////////////////////////////////////////////////////////////
func instanceEndpoint(pin common.Pin) (string, error) {
@@ -441,6 +467,17 @@ func aclEndpoint(packagePath string) (string, error) {
return "repo/v1/acl?" + params.Encode(), nil
}
+func packageEndpoint(path string, recursive bool) (string, error) {
Vadim Sh. 2015/06/23 00:08:35 nit: packageSearchEndpoint
estaab 2015/06/23 02:26:14 Done.
+ params := url.Values{}
+ params.Add("path", path)
+ recursiveString := "false"
+ if recursive {
+ recursiveString = "true"
+ }
+ params.Add("recursive", recursiveString)
+ return "repo/v1/package/search?" + params.Encode(), nil
+}
+
func tagsEndpoint(pin common.Pin, tags []string) (string, error) {
err := common.ValidatePin(pin)
if err != nil {

Powered by Google App Engine
This is Rietveld 408576698