Created
March 20, 2017 05:28
-
-
Save xiaket/d6e0a77c5f7bda8753057b322b06355d to your computer and use it in GitHub Desktop.
Get the list of images and tags for a Docker Hub repo
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
import json | |
import sys | |
import requests | |
AUTH ={ | |
'username': "xiaket", | |
'password': "YourPasswordHere", | |
} | |
def login(): | |
response = requests.post( | |
'https://hub.docker.com/v2/users/login/', | |
headers={'Content-type': 'application/json'}, | |
data=json.dumps(AUTH), | |
) | |
if not response.ok: | |
sys.stderr.write("Login failed: %s\n" % response.text['detail']) | |
sys.exit(1) | |
return response.json()['token'] | |
def get_repo_images(repo, token): | |
return requests.get( | |
'https://hub.docker.com/v2/repositories/%s/tags/?page_size=500' % repo, | |
headers={'Authorization': 'JWT %s' % token}, | |
) | |
def main(): | |
token = login() | |
get_repo_images('gitlab/gitlab-ce', token) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment