oras-project / oras-py

ORAS Python SDK
https://oras-project.github.io/oras-py/
Apache License 2.0
39 stars 33 forks source link

Add `get_digest(container)` method on provider.Registry #143

Open hanikesn opened 4 months ago

hanikesn commented 4 months ago

It can often be quite useful to resolve a tag to the digest where an artifact is stored in the registry. To solve this I duplicated the code of Registry.get_manifest and compute the hash client side:

    @decorator.ensure_container
    def get_digest(self, container):
        self.load_configs(container)
        allowed_media_type = [defaults.default_manifest_media_type]
        headers = {"Accept": ";".join(allowed_media_type)}
        headers.update(self.headers)
        get_manifest = f"{self.prefix}://{container.manifest_url()}"  # type: ignore
        response = self.do_request(get_manifest, "GET", headers=headers)
        self._check_200_response(response)
        return f"sha256:{hashlib.sha256(response.content).hexdigest()}"
vsoch commented 4 months ago

This would be good to add to the repository, perhaps as an example or helper script?