Skip to content

Instantly share code, notes, and snippets.

@nobiit
Created April 25, 2023 16:14
Show Gist options
  • Save nobiit/702b15467e0141083df7a85178bd2f93 to your computer and use it in GitHub Desktop.
Save nobiit/702b15467e0141083df7a85178bd2f93 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
owner=${1:?}
username=${2:?}
password=${3:?}
function docker_api {
curl -s "https://hub.docker.com/v2/${@}"
}
function docker_api_post {
docker_api "${@}" -d @- -H 'Content-Type: application/json'
}
function docker_api_with_token {
docker_api "${@}" -H "Authorization: Bearer ${TOKEN}"
}
function list_repositories {
docker_api_with_token "repositories/${owner}/?page_size=100&page=1" | jq -r '.results[] | select(.status_description == "active") | .name'
}
TOKEN=$(jq -rn "$(printf '.username = "%s" | .password = "%s" | tojson' "${username}" "${password}")" | docker_api_post users/login | jq -r .token)
for repo in $(list_repositories); do
echo "${repo}"
docker_api_with_token "repositories/${owner}/${repo}/" -X DELETE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment