Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preset headers to get_manifest request #121

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pre-commit
black==23.3.0
black==24.1.0
isort
flake8
mypy==0.961
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: gh-pages

- name: Create conda environment
run: conda create --quiet -c conda-forge --name oraspy
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install Oras and Dependencies
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
root=$PWD
source activate oraspy
cd /tmp
git clone https://github.com/oras-project/oras-py
cd oras-py
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Check Spelling
uses: crate-ci/typos@7ad296c72fa8265059cc03d1eda562fbdfcd6df2 # v1.9.0
with:
files: ./docs ./README.md

- name: Setup Environment
run: conda create --quiet --name oras pre-commit
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Lint Oras Python
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate oras
python --version
python3 -m pip install pre-commit
python3 -m pip install black
make develop
make lint

Expand All @@ -30,16 +33,15 @@ jobs:
- 5000:5000
steps:
- uses: actions/checkout@v3
- name: Setup Environment
run: conda create --quiet --name oras requests
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Test Oras Python
env:
registry_host: localhost
registry_port: ${{ job.services.registry.ports[5000] }}
REGISTRY_STORAGE_DELETE_ENABLED: "true"
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate oras
pip install --upgrade pip setuptools
make install
make test
13 changes: 5 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- name: Install
run: conda create --quiet --name oras twine
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install dependencies
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate oras
pip install -e .
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASS }}
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate oras
python setup.py sdist bdist_wheel
twine upload dist/*
4 changes: 2 additions & 2 deletions .github/workflows/update-contributors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Tributors Update
uses: con/tributors@master
env:
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
echo "PULL_REQUEST_BODY=Tributors update automated pull request." >> $GITHUB_ENV

- name: Open Pull Request
uses: vsoch/pull-request-action@50f22f6d146226ee6b73b7a001f26a3d4579f360 # 1.0.22
uses: vsoch/pull-request-action@master
if: ${{ env.OPEN_PULL_REQUEST == '1' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 19 additions & 4 deletions oras/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion oras/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
NAME = "oras"
Expand Down