diff --git a/catalogue/catalogue.go b/catalogue/catalogue.go index 1ad806b4..144ab06c 100644 --- a/catalogue/catalogue.go +++ b/catalogue/catalogue.go @@ -11,6 +11,7 @@ import ( "time" "coopcloud.tech/abra/config" + "coopcloud.tech/abra/web" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" ) @@ -204,7 +205,7 @@ func readAppsCatalogueFS(target interface{}) error { } func readAppsCatalogueWeb(target interface{}) error { - if err := readJson(appsCatalogueURL, &target); err != nil { + if err := web.ReadJSON(appsCatalogueURL, &target); err != nil { return err } diff --git a/client/registry.go b/client/registry.go index 30ef1b67..e6c27b6e 100644 --- a/client/registry.go +++ b/client/registry.go @@ -1,7 +1,9 @@ package client import ( - "github.com/docker/distribution/reference" + "fmt" + + "coopcloud.tech/abra/web" ) type Tag struct { @@ -13,7 +15,13 @@ type Tags []Tag var registryURL = "https://registry.hub.docker.com/v1/repositories/%s/tags" -func ReadRegistryTags(image reference.Named, target interface{}) ([]string, error) { - // tagsUrl := fmt.Sprintf(registryURL, image.Name()) - return nil, nil +func GetRegistryTags(image string) (Tags, error) { + var tags Tags + + tagsUrl := fmt.Sprintf(registryURL, image) + if err := web.ReadJSON(tagsUrl, &tags); err != nil { + return tags, err + } + + return tags, nil } diff --git a/catalogue/common.go b/web/web.go similarity index 63% rename from catalogue/common.go rename to web/web.go index d2b22cb0..c1f8297b 100644 --- a/catalogue/common.go +++ b/web/web.go @@ -1,4 +1,4 @@ -package catalogue +package web import ( "encoding/json" @@ -6,7 +6,8 @@ import ( "time" ) -func readJson(url string, target interface{}) error { +// ReadJSON reads JSON and parses it into your chosen interface pointer +func ReadJSON(url string, target interface{}) error { httpClient := &http.Client{Timeout: 5 * time.Second} res, err := httpClient.Get(url) if err != nil {