-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add configurable support for both raw and base64 uploads (#109)
* add configurable support for both raw and base64 uploads * add tests for IncomingCollectionStream * add changelog fragment * update readme
- Loading branch information
Showing
8 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
bugfixes: | ||
- The collection publish endpoint required the file data to be base64 encoded. This worked for ``ansible-core>=2.10`` but did not work with Ansible 2.9 or other clients that were not aware of the need. Galactory can now detect and accept both raw bytes and base64 encoded content (https://github.com/briantist/galactory/issues/105). | ||
|
||
minor_changes: | ||
- The option ``UPLOAD_FORMAT`` has been added to control the behavior of upload format detection. Auto-detection is attempted when the option is not set or set to ``auto``. Set it to ``base64`` to only accept base64-encoded content, or set it to ``raw`` to only accept unencoded content (https://github.com/briantist/galactory/pull/109). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# (c) 2023 Brian Scholer (@briantist) | ||
|
||
import pytest | ||
import tarfile | ||
|
||
from pathlib import Path | ||
from base64io import Base64IO | ||
from galactory.utilities import IncomingCollectionStream | ||
|
||
|
||
@pytest.fixture | ||
def collection_tarball(virtual_fs_repo: Path, tmp_path: Path): | ||
collection = next(virtual_fs_repo.glob("**/*.tar.gz")) | ||
gz_path = tmp_path / collection.name | ||
with tarfile.open(gz_path, mode='w:gz') as tar: | ||
tar.add(collection) | ||
return gz_path | ||
|
||
|
||
@pytest.fixture | ||
def base64_tarball(collection_tarball: Path, tmp_path: Path): | ||
b64_path = tmp_path / f"{collection_tarball.name}.b64" | ||
with open(collection_tarball, mode='rb') as raw, open(b64_path, mode='wb') as w, Base64IO(w) as f: | ||
f.write(raw.read()) | ||
return b64_path | ||
|
||
|
||
class TestIncomingCollectionStream: | ||
@pytest.mark.parametrize('format', [None, 'auto', 'undefined', 'raw']) | ||
def test_raw(self, collection_tarball: Path, format: str): | ||
with open(collection_tarball, mode='rb') as f: | ||
assert IncomingCollectionStream.detected_stream(f) is f | ||
assert IncomingCollectionStream(f, format=format) | ||
|
||
@pytest.mark.parametrize('format', [None, 'auto', 'undefined', 'base64']) | ||
def test_base64(self, base64_tarball: Path, format: str): | ||
with open(base64_tarball, mode='rb') as f: | ||
assert isinstance(IncomingCollectionStream.detected_stream(f), Base64IO) | ||
assert isinstance(IncomingCollectionStream(f, format=format), Base64IO) |