Skip to content

Instantly share code, notes, and snippets.

@geberl
Created April 30, 2019 06:48
Show Gist options
  • Save geberl/fb1ea0391f3c4911c085e5ba5fee2f3f to your computer and use it in GitHub Desktop.
Save geberl/fb1ea0391f3c4911c085e5ba5fee2f3f to your computer and use it in GitHub Desktop.
#! /usr/bin/python3
# -*- coding: utf-8 -*-
import requests
def get_token(auth_url, image_name):
payload = {
'service': 'registry.docker.io',
'scope': 'repository:library/{image}:pull'.format(image=image_name)
}
r = requests.get(auth_url + '/token', params=payload)
if not r.status_code == 200:
print("Error status {}".format(r.status_code))
raise Exception("Could not get auth token")
j = r.json()
return j['token']
token = get_token('https://auth.docker.io', 'openjdk')
print(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment