diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ec7a9..863b5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are: The versions coincide with releases on pip. Only major versions will be released as tags on Github. ## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x) + - Introduce the option to not refresh headers when fetching manifests when pulling artifacts (0.1.27) - To make it available for more OCI registries, the value of config used when `manifest_config` is not specified in `client.push()` has been changed from a pure empty string to `{}` (0.1.26) - refactor tests using fixtures and rework pre-commit configuration (0.1.25) - eliminate the additional subdirectory creation while pulling an image to a custom output directory (0.1.24) diff --git a/oras/provider.py b/oras/provider.py index db0ac3a..0abd2d5 100644 --- a/oras/provider.py +++ b/oras/provider.py @@ -757,8 +757,10 @@ def push(self, *args, **kwargs) -> requests.Response: # Config is just another layer blob! logger.debug(f"Preparing config {conf}") - with temporary_empty_config() if config_file is None else nullcontext( - config_file + with ( + temporary_empty_config() + if config_file is None + else nullcontext(config_file) ) as config_file: response = self.upload_blob(config_file, container, conf) @@ -780,6 +782,8 @@ def pull(self, *args, **kwargs) -> List[str]: :type allowed_media_type: list or None :param overwrite: if output file exists, overwrite :type overwrite: bool + :param refresh_headers: if true, headers are refreshed when fetching manifests + :type refresh_headers: bool :param manifest_config_ref: save manifest config to this file :type manifest_config_ref: str :param outdir: output directory path @@ -788,9 +792,12 @@ def pull(self, *args, **kwargs) -> List[str]: :type target: str """ allowed_media_type = kwargs.get("allowed_media_type") + refresh_headers = kwargs.get("refresh_headers") + if refresh_headers is None: + refresh_headers = True container = self.get_container(kwargs["target"]) self.load_configs(container, configs=kwargs.get("config_path")) - manifest = self.get_manifest(container, allowed_media_type) + manifest = self.get_manifest(container, allowed_media_type, refresh_headers) outdir = kwargs.get("outdir") or oras.utils.get_tmpdir() overwrite = kwargs.get("overwrite", True) @@ -830,7 +837,10 @@ def pull(self, *args, **kwargs) -> List[str]: @decorator.ensure_container def get_manifest( - self, container: container_type, allowed_media_type: Optional[list] = None + self, + container: container_type, + allowed_media_type: Optional[list] = None, + refresh_headers: bool = True, ) -> dict: """ Retrieve a manifest for a package. @@ -839,11 +849,16 @@ def get_manifest( :type container: oras.container.Container or str :param allowed_media_type: one or more allowed media types :type allowed_media_type: str + :param refresh_headers: if true, headers are refreshed + :type refresh_headers: bool """ if not allowed_media_type: allowed_media_type = [oras.defaults.default_manifest_media_type] headers = {"Accept": ";".join(allowed_media_type)} + if not refresh_headers: + 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) diff --git a/oras/version.py b/oras/version.py index 8432dbd..b13c0b1 100644 --- a/oras/version.py +++ b/oras/version.py @@ -2,7 +2,7 @@ __copyright__ = "Copyright The ORAS Authors." __license__ = "Apache-2.0" -__version__ = "0.1.26" +__version__ = "0.1.27" AUTHOR = "Vanessa Sochat" EMAIL = "vsoch@users.noreply.github.com" NAME = "oras"