Skip to content

Instantly share code, notes, and snippets.

@praveenkumar
Created June 13, 2022 11:58
Show Gist options
  • Save praveenkumar/f3e192cc1af339add8fb3a2e6761eb5d to your computer and use it in GitHub Desktop.
Save praveenkumar/f3e192cc1af339add8fb3a2e6761eb5d to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
type tags struct {
Name string `json:"name"`
Reversion bool `json:"reversion"`
StartTs int `json:"start_ts"`
ManifestDigest string `json:"manifest_digest"`
IsManifestList bool `json:"is_manifest_list"`
Size int `json:"size"`
LastModified string `json:"last_modified"`
EndTs int `json:"end_ts,omitempty"`
Expiration string `json:"expiration,omitempty"`
}
type tagResp struct {
Tags []tags `json:"tags"`
}
func main() {
resp, err := http.Get("https://quay.io/api/v1/repository/praveenkumar/sample/tag/?onlyActiveTags=true&limit=50")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
tagsResp := tagResp{}
err = json.Unmarshal(data, &tagsResp)
if err != nil {
log.Fatal(err)
}
releaseTag := "2.4"
manifestDigest := getManifestDigest(releaseTag, tagsResp)
fmt.Println(getBundleVersion(manifestDigest, tagsResp))
}
func getManifestDigest(releaseTag string, tagsResp tagResp) string {
for _, tag := range tagsResp.Tags {
if tag.Name == releaseTag {
return tag.ManifestDigest
}
}
return ""
}
func getBundleVersion(manifestDigest string, tagsResp tagResp) string {
for _, tag := range tagsResp.Tags {
if tag.ManifestDigest == manifestDigest {
return tag.Name
}
}
return ""
}
@praveenkumar
Copy link
Author

praveenkumar commented Jun 13, 2022

$ curl -H "Accept: application/json"  https://quay.io/api/v1/repository/praveenkumar/sample/tag/?onlyActiveTags=true | jq .
{
  "tags": [
    {
      "name": "v2",
      "reversion": false,
      "start_ts": 1655109107,
      "manifest_digest": "sha256:124b84e904576c7a06929e78d8bb8e0f7f8b0c8a1590a48f45e81fbea572928f",
      "is_manifest_list": false,
      "size": 129,
      "last_modified": "Mon, 13 Jun 2022 08:31:47 -0000"
    },
    {
      "name": "2.4",
      "reversion": false,
      "start_ts": 1655109099,
      "manifest_digest": "sha256:124b84e904576c7a06929e78d8bb8e0f7f8b0c8a1590a48f45e81fbea572928f",
      "is_manifest_list": false,
      "size": 129,
      "last_modified": "Mon, 13 Jun 2022 08:31:39 -0000"
    },
    {
      "name": "v1",
      "reversion": false,
      "start_ts": 1655107779,
      "manifest_digest": "sha256:bf6bda1aa8698556723363dd987fac20f0f42bf1ffcf95c06016ac18bb6edfc0",
      "is_manifest_list": false,
      "size": 108,
      "last_modified": "Mon, 13 Jun 2022 08:09:39 -0000"
    }
  ],
  "page": 1,
  "has_additional": false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment