Skip to content

Instantly share code, notes, and snippets.

@steve-heslouin
Last active September 20, 2023 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steve-heslouin/1dbc0734dc2075853f259c356fb15286 to your computer and use it in GitHub Desktop.
Save steve-heslouin/1dbc0734dc2075853f259c356fb15286 to your computer and use it in GitHub Desktop.
Get tags from Google container registry docker image
from google.auth import load_credentials_from_file
import google.auth.transport.requests
import requests
hostname = "us.gcr.io" # could also be gcr.io
project_name = ""
image_name = ""
service_account_path_file = ""
scope = 'https://www.googleapis.com/auth/cloud-platform.read-only'
cred, project = load_credentials_from_file(
filename=service_account_path_file,
scopes=[scope])
request = google.auth.transport.requests.Request()
cred.refresh(request)
headers = {
"Authorization": f"Bearer {cred.token}"
}
req = requests.get(f"https://{hostname}/v2/{project_name}/{image_name}/tags/list", headers=headers)
print(req.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment