Skip to content

Instantly share code, notes, and snippets.

@psftw
Created December 8, 2016 20:26
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 psftw/9b37268a8a238c68c96ece57064c93f7 to your computer and use it in GitHub Desktop.
Save psftw/9b37268a8a238c68c96ece57064c93f7 to your computer and use it in GitHub Desktop.
import json
import requests
# only care about manifest list or v2 manifests
manifest_header = ' '.join([
'application/vnd.docker.distribution.manifest.list.v2+json',
'application/vnd.docker.distribution.manifest.v2+json'])
def scan_repo(repo, tags=None):
# get auth token
s = requests.Session()
token = s.get('https://auth.docker.io/token?service=registry.docker.io' +
'&scope=repository:%s:pull' % repo).json()['token']
s.headers.update({'Authorization': 'Bearer %s' % token})
# get all tag names if not specified
if tags is None:
tags = s.get('https://registry-1.docker.io/v2/%s/tags/list' % repo) \
.json()
tags = tags['tags']
if len(tags) == 0:
raise 'no tags? giving up'
# get manifest list (TODO) or manifest
data = {}
s.headers.update({'Accept': manifest_header})
for tag in tags:
print 'scanning: %s:%s' % (repo, tag)
manifest = s.get('https://registry-1.docker.io/v2/%s/manifests/%s' %
(repo, tag)).json()
for blobsum in manifest['fsLayers']:
print blobsum['blobSum']
with open('manifest.json', 'w') as f:
f.write(json.dumps(manifest, indent=4))
if __name__ == '__main__':
scan_repo('library/ruby', ['latest'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment