Skip to content

Instantly share code, notes, and snippets.

@northtyphoon
Last active March 9, 2023 08:01
Show Gist options
  • Save northtyphoon/f10b35c90fc425a9b109f66991f7d036 to your computer and use it in GitHub Desktop.
Save northtyphoon/f10b35c90fc425a9b109f66991f7d036 to your computer and use it in GitHub Desktop.
# Prerequisite
# 1) Install azure-cli curl, jq

registry="myregistry.azurecr.io"
scope_catalog="registry:catalog:*"
scope_repo_metadata="repository:*:metadata_read"

# az login --identity
acr_refresh_token=$(az acr login --name $registry --expose-token | jq -r ".accessToken")

# POST request to get access_token
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=refresh_token&service=$registry&scope=$scope_catalog&scope=$scope_repo_metadata&refresh_token=$acr_refresh_token" https://$registry/oauth2/token | jq -r ".access_token"

# Alternative GET request to get access_token
#acr_credential=$(echo -n "00000000-0000-0000-0000-000000000000:$acr_refresh_token" | base64 -w0)
#curl -H "Authorization: Basic $acr_credential" "https://$registry/oauth2/token?service=$registry&scope=$scope_catalog&scope=$scope_repo_metadata" | jq -r ".access_token"

# list repositories 
repos=$(curl -H "Authorization: Bearer $acr_access_token" https://$registry/acr/v1/_catalog | jq -r ".repositories[]")

for repo in $repos; do
  # list tags 
  curl -H "Authorization: Bearer $acr_access_token" https://$registry/acr/v1/$repo/_tags | jq -r ".tags"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment