Skip to content

Commit

Permalink
Hotfix for manifests list
Browse files Browse the repository at this point in the history
  • Loading branch information
NotGlop authored Mar 27, 2020
1 parent 5bf5237 commit 5413165
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docker_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
reg_service = ""

# Get Docker token (this function is useless for unauthenticated registries like Microsoft)
def get_auth_head(registry):
def get_auth_head(type):
resp = requests.get('{}?service={}&scope=repository:{}:pull'.format(auth_url, reg_service, repository), verify=False)
access_token = resp.json()['token']
auth_head = {'Authorization':'Bearer '+ access_token, 'Accept':'application/vnd.docker.distribution.manifest.v2+json'}
auth_head = {'Authorization':'Bearer '+ access_token, 'Accept': type}
return auth_head

# Docker style progress bar
Expand All @@ -69,12 +69,12 @@ def progress_bar(ublob, nb_traits):
sys.stdout.flush()

# Fetch manifest v2 and get image layer digests
auth_head = get_auth_head(registry)
auth_head = get_auth_head('application/vnd.docker.distribution.manifest.v2+json')
resp = requests.get('https://{}/v2/{}/manifests/{}'.format(registry, repository, tag), headers=auth_head, verify=False)
if (resp.status_code != 200):
print('[-] Cannot fetch manifest for {} [HTTP {}]'.format(repository, resp.status_code))
print(resp.content)
auth_head = {'Authorization':'Bearer '+ access_token, 'Accept':'application/vnd.docker.distribution.manifest.list.v2+json'}
auth_head = get_auth_head('application/vnd.docker.distribution.manifest.list.v2+json')
resp = requests.get('https://{}/v2/{}/manifests/{}'.format(registry, repository, tag), headers=auth_head, verify=False)
if (resp.status_code == 200):
print('[+] Manifests found for this tag (use the @digest format to pull the corresponding image):')
Expand Down Expand Up @@ -128,7 +128,7 @@ def progress_bar(ublob, nb_traits):
# Creating layer.tar file
sys.stdout.write(ublob[7:19] + ': Downloading...')
sys.stdout.flush()
auth_head = get_auth_head(registry) # refreshing token to avoid its expiration
auth_head = get_auth_head('application/vnd.docker.distribution.manifest.v2+json') # refreshing token to avoid its expiration
bresp = requests.get('https://{}/v2/{}/blobs/{}'.format(registry, repository, ublob), headers=auth_head, stream=True, verify=False)
if (bresp.status_code != 200): # When the layer is located at a custom URL
bresp = requests.get(layer['urls'][0], headers=auth_head, stream=True, verify=False)
Expand All @@ -151,7 +151,7 @@ def progress_bar(ublob, nb_traits):
nb_traits = nb_traits + 1
progress_bar(ublob, nb_traits)
acc = 0
sys.stdout.write("\r{}: Extracting ...{}".format(ublob[7:19], " "*50)) # Ugly but works everywhere
sys.stdout.write("\r{}: Extracting...{}".format(ublob[7:19], " "*50)) # Ugly but works everywhere
sys.stdout.flush()
with open(layerdir + '/layer.tar', "wb") as file: # Decompress gzip response
unzLayer = gzip.open(layerdir + '/layer_gzip.tar','rb')
Expand Down Expand Up @@ -195,7 +195,7 @@ def progress_bar(ublob, nb_traits):

# Create image tar and clean tmp folder
docker_tar = repo.replace('/', '_') + '_' + img + '.tar'
sys.stdout.write("Creating archive ...")
sys.stdout.write("Creating archive...")
sys.stdout.flush()
tar = tarfile.open(docker_tar, "w")
tar.add(imgdir, arcname=os.path.sep)
Expand Down

0 comments on commit 5413165

Please sign in to comment.