summaryrefslogtreecommitdiffstats
path: root/pkg/registry
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2026-01-07 23:39:53 +0000
committerLeonardo Bishop <me@leonardobishop.net>2026-01-07 23:39:53 +0000
commit03cd6bdfbd473dba3f3dc50a1b15e389aac5bc70 (patch)
tree5fea2b1840e298aaab953add749fb9226bd4a710 /pkg/registry
Initial commit
Diffstat (limited to 'pkg/registry')
-rw-r--r--pkg/registry/list.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/pkg/registry/list.go b/pkg/registry/list.go
new file mode 100644
index 0000000..0c6073f
--- /dev/null
+++ b/pkg/registry/list.go
@@ -0,0 +1,62 @@
+package registry
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+)
+
+type RegistryClient struct {
+ URL string
+ Username string
+ Password string
+}
+
+type CatalogResponse struct {
+ Repositories []string `json:"repositories"`
+}
+
+func (c *RegistryClient) ListRepositories() ([]string, error) {
+ repos := []string{}
+ last := ""
+ pageSize := 100
+
+ for {
+ url := fmt.Sprintf("%s/v2/_catalog?n=%d", c.URL, pageSize)
+ if last != "" {
+ url += "&last=" + last
+ }
+
+ req, _ := http.NewRequest("GET", url, nil)
+ if c.Username != "" {
+ req.SetBasicAuth(c.Username, c.Password)
+ }
+
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ body, _ := io.ReadAll(resp.Body)
+ return nil, fmt.Errorf("registry returned %d: %s", resp.StatusCode, body)
+ }
+
+ var catalog CatalogResponse
+ if err := json.NewDecoder(resp.Body).Decode(&catalog); err != nil {
+ return nil, err
+ }
+
+ repos = append(repos, catalog.Repositories...)
+
+ if len(catalog.Repositories) < pageSize {
+ break
+ }
+
+ last = catalog.Repositories[len(catalog.Repositories)-1]
+ }
+
+ return repos, nil
+}