in images/controller/pkg/util.go [140:171]
func ListGCRImageTags(image string, authToken string) (ImageListResponse, error) {
listResp := ImageListResponse{}
gcrRepo := ExtractGCRRepoFromImage(image)
if len(gcrRepo) == 0 {
return listResp, fmt.Errorf("could not determine tag or digest from image: %s", image)
}
url := fmt.Sprintf("https://gcr.io/v2/%s/tags/list", gcrRepo)
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", authToken))
resp, err := client.Do(req)
if err != nil {
return listResp, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return listResp, err
}
if resp.StatusCode != http.StatusOK {
return listResp, fmt.Errorf("%v", string(body))
}
if err := json.Unmarshal(body, &listResp); err != nil {
return listResp, err
}
return listResp, nil
}