Skip to content

Commit fb49f2f

Browse files
authored
Add option to refresh (current behaviour) or keep previous headers when fetching manifests (#123)
* bumped version and add note to changelog * added refresh_headers as an option for fetching manifests * fix line endings Signed-off-by: Kavish Punchoo <kavish.punchoo@bertelsmann.de>
1 parent 0b46d19 commit fb49f2f

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x)
17+
- Introduce the option to not refresh headers when fetching manifests when pulling artifacts (0.1.27)
1718
- 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)
1819
- refactor tests using fixtures and rework pre-commit configuration (0.1.25)
1920
- eliminate the additional subdirectory creation while pulling an image to a custom output directory (0.1.24)

oras/provider.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,10 @@ def push(self, *args, **kwargs) -> requests.Response:
757757

758758
# Config is just another layer blob!
759759
logger.debug(f"Preparing config {conf}")
760-
with temporary_empty_config() if config_file is None else nullcontext(
761-
config_file
760+
with (
761+
temporary_empty_config()
762+
if config_file is None
763+
else nullcontext(config_file)
762764
) as config_file:
763765
response = self.upload_blob(config_file, container, conf)
764766

@@ -780,6 +782,8 @@ def pull(self, *args, **kwargs) -> List[str]:
780782
:type allowed_media_type: list or None
781783
:param overwrite: if output file exists, overwrite
782784
:type overwrite: bool
785+
:param refresh_headers: if true, headers are refreshed when fetching manifests
786+
:type refresh_headers: bool
783787
:param manifest_config_ref: save manifest config to this file
784788
:type manifest_config_ref: str
785789
:param outdir: output directory path
@@ -788,9 +792,12 @@ def pull(self, *args, **kwargs) -> List[str]:
788792
:type target: str
789793
"""
790794
allowed_media_type = kwargs.get("allowed_media_type")
795+
refresh_headers = kwargs.get("refresh_headers")
796+
if refresh_headers is None:
797+
refresh_headers = True
791798
container = self.get_container(kwargs["target"])
792799
self.load_configs(container, configs=kwargs.get("config_path"))
793-
manifest = self.get_manifest(container, allowed_media_type)
800+
manifest = self.get_manifest(container, allowed_media_type, refresh_headers)
794801
outdir = kwargs.get("outdir") or oras.utils.get_tmpdir()
795802
overwrite = kwargs.get("overwrite", True)
796803

@@ -830,7 +837,10 @@ def pull(self, *args, **kwargs) -> List[str]:
830837

831838
@decorator.ensure_container
832839
def get_manifest(
833-
self, container: container_type, allowed_media_type: Optional[list] = None
840+
self,
841+
container: container_type,
842+
allowed_media_type: Optional[list] = None,
843+
refresh_headers: bool = True,
834844
) -> dict:
835845
"""
836846
Retrieve a manifest for a package.
@@ -839,11 +849,16 @@ def get_manifest(
839849
:type container: oras.container.Container or str
840850
:param allowed_media_type: one or more allowed media types
841851
:type allowed_media_type: str
852+
:param refresh_headers: if true, headers are refreshed
853+
:type refresh_headers: bool
842854
"""
843855
if not allowed_media_type:
844856
allowed_media_type = [oras.defaults.default_manifest_media_type]
845857
headers = {"Accept": ";".join(allowed_media_type)}
846858

859+
if not refresh_headers:
860+
headers.update(self.headers)
861+
847862
get_manifest = f"{self.prefix}://{container.manifest_url()}" # type: ignore
848863
response = self.do_request(get_manifest, "GET", headers=headers)
849864
self._check_200_response(response)

oras/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright The ORAS Authors."
33
__license__ = "Apache-2.0"
44

5-
__version__ = "0.1.26"
5+
__version__ = "0.1.27"
66
AUTHOR = "Vanessa Sochat"
77
EMAIL = "vsoch@users.noreply.github.com"
88
NAME = "oras"

0 commit comments

Comments
 (0)