Skip to content

Instantly share code, notes, and snippets.

@cgddrd
Created May 22, 2018 12:18
Show Gist options
  • Save cgddrd/1e7ecee731030ccd90534a4b314fe097 to your computer and use it in GitHub Desktop.
Save cgddrd/1e7ecee731030ccd90534a4b314fe097 to your computer and use it in GitHub Desktop.
docker_registry_v2_manage.py
import requests
REGISTRY_URL = "http://<HOST>/v2/"
proxies = {
"http": None,
"https": None,
}
def get_repositories():
resp = requests.get(REGISTRY_URL + "_catalog", proxies=proxies)
return resp.json()['repositories']
def get_tags(repository):
resp = requests.get(REGISTRY_URL + repository + "/tags/list", proxies=proxies)
return resp.json()
def delete_digest(repository, digest):
requests.delete(REGISTRY_URL + repository + "/manifests/" + digest, proxies=proxies)
def get_digest(repository, tag):
url = "{}{}/manifests/{}".format(REGISTRY_URL, repository, tag)
headers = {"Accept": "application/vnd.docker.distribution.manifest.v2+json"}
resp = requests.get(url, headers=headers, proxies=proxies)
print(resp)
return resp.headers.get("Docker-Content-Digest")
def clear_registry_tag(tag="latest"):
digest = get_digest('repo', tag)
delete_digest('repo', digest)
def main():
print(get_repositories())
print(get_tags('repo'))
print(get_digest('repo', 'tag'))
clear_registry_tag()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment