Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
Jess Frazelle 2016-12-19 22:36:05 -08:00
parent 7b01d03664
commit e451b94f87
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
4 changed files with 34 additions and 5 deletions

View file

@ -105,7 +105,7 @@ func main() {
Usage: "list all repositories", Usage: "list all repositories",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
// get the repositories via catalog // get the repositories via catalog
repos, err := r.Catalog() repos, err := r.Catalog("")
if err != nil { if err != nil {
return err return err
} }

View file

@ -1,18 +1,39 @@
package registry package registry
import (
"fmt"
"github.com/peterhellberg/link"
)
type catalogResponse struct { type catalogResponse struct {
Repositories []string `json:"repositories"` Repositories []string `json:"repositories"`
} }
// Catalog returns the repositories in a registry. // Catalog returns the repositories in a registry.
func (r *Registry) Catalog() ([]string, error) { func (r *Registry) Catalog(u string) ([]string, error) {
url := r.url("/v2/_catalog") if u == "" {
u = "/v2/_catalog"
}
url := r.url(u)
r.Logf("registry.catalog url=%s", url) r.Logf("registry.catalog url=%s", url)
var response catalogResponse var response catalogResponse
if _, err := r.getJSON(url, &response); err != nil { h, err := r.getJSON(url, &response)
if err != nil {
return nil, err return nil, err
} }
fmt.Printf("header: %#v\n", h)
for _, l := range link.ParseHeader(h) {
if l.Rel == "next" {
repos, err := r.Catalog(l.URI)
if err != nil {
return nil, err
}
response.Repositories = append(response.Repositories, repos...)
}
}
return response.Repositories, nil return response.Repositories, nil
} }

View file

@ -240,7 +240,7 @@ type v1Compatibility struct {
func createStaticIndex(r *registry.Registry, staticDir string) error { func createStaticIndex(r *registry.Registry, staticDir string) error {
updating = true updating = true
logrus.Info("fetching catalog") logrus.Info("fetching catalog")
repoList, err := r.Catalog() repoList, err := r.Catalog("")
if err != nil { if err != nil {
return fmt.Errorf("getting catalog failed: %v", err) return fmt.Errorf("getting catalog failed: %v", err)
} }

8
vendor/manifest vendored
View file

@ -104,6 +104,14 @@
"path": "/libcontainer/user", "path": "/libcontainer/user",
"notests": true "notests": true
}, },
{
"importpath": "github.com/peterhellberg/link",
"repository": "https://github.com/peterhellberg/link",
"vcs": "git",
"revision": "d1cebc7ea14a5fc0de7cb4a45acae773161642c6",
"branch": "master",
"notests": true
},
{ {
"importpath": "github.com/urfave/cli", "importpath": "github.com/urfave/cli",
"repository": "https://github.com/urfave/cli", "repository": "https://github.com/urfave/cli",