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

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
« no previous file with comments | « go/src/infra/tools/cipd/client_test.go ('k') | go/src/infra/tools/cipd/remote_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/remote.go
diff --git a/go/src/infra/tools/cipd/remote.go b/go/src/infra/tools/cipd/remote.go
index 985428e5021cb2e9fcd60b3c3eac186075e4bc57..7898d6da05c096f346f5c64b846a36567298ce8b 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
@@ -450,6 +450,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 := packageSearchEndpoint(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) {
@@ -484,6 +510,17 @@ func refEndpoint(packageName string, ref string) (string, error) {
return "repo/v1/ref?" + params.Encode(), nil
}
+func packageSearchEndpoint(path string, recursive bool) (string, error) {
+ 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) {
if err := common.ValidatePin(pin); err != nil {
return "", err
« no previous file with comments | « go/src/infra/tools/cipd/client_test.go ('k') | go/src/infra/tools/cipd/remote_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698