Created
June 13, 2022 11:58
-
-
Save praveenkumar/f3e192cc1af339add8fb3a2e6761eb5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" | |
} |
Author
praveenkumar
commented
Jun 13, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment