Skip to content

Commit

Permalink
add refresh_headers as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
kavish-p committed Jan 29, 2024
1 parent 1426e5b commit d2f1f6d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions oras/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,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
Expand All @@ -788,9 +790,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)

Expand Down Expand Up @@ -830,7 +835,7 @@ 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.
Expand All @@ -839,11 +844,15 @@ 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)}
headers.update(self.headers)

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)
Expand Down

0 comments on commit d2f1f6d

Please sign in to comment.