blueprints: support custom ports for OCI blueprints (#5727)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-05-23 13:52:50 +02:00 committed by Jens Langhammer
parent 573517bf0a
commit 554a26442d
No known key found for this signature in database
2 changed files with 30 additions and 2 deletions

View File

@ -32,6 +32,29 @@ class TestBlueprintOCI(TransactionTestCase):
"foo",
)
def test_successful_port(self):
"""Successful retrieval with custom port"""
with Mocker() as mocker:
mocker.get(
"https://ghcr.io:1234/v2/goauthentik/blueprints/test/manifests/latest",
json={
"layers": [
{
"mediaType": OCI_MEDIA_TYPE,
"digest": "foo",
}
]
},
)
mocker.get("https://ghcr.io:1234/v2/goauthentik/blueprints/test/blobs/foo", text="foo")
self.assertEqual(
BlueprintInstance(
path="oci://ghcr.io:1234/goauthentik/blueprints/test:latest"
).retrieve(),
"foo",
)
def test_manifests_error(self):
"""Test manifests request erroring"""
with Mocker() as mocker:

View File

@ -39,11 +39,16 @@ class BlueprintOCIClient:
self.logger = get_logger().bind(url=self.sanitized_url)
self.ref = "latest"
# Remove the leading slash of the path to convert it to an image name
path = self.url.path[1:]
if ":" in self.url.path:
if ":" in path:
# if there's a colon in the path, use everything after it as a ref
path, _, self.ref = path.partition(":")
base_url = f"https://{self.url.hostname}"
if self.url.port:
base_url += f":{self.url.port}"
self.client = NewClient(
f"https://{self.url.hostname}",
base_url,
WithUserAgent(authentik_user_agent()),
WithUsernamePassword(self.url.username, self.url.password),
WithDefaultName(path),