Skip to content
Open
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
15 changes: 11 additions & 4 deletions python_on_whales/components/manifest/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@

class ManifestList(ReloadableObjectFromJson):
def __init__(
self, client_config: ClientConfig, reference: str, is_immutable_id=False
self,
client_config: ClientConfig,
reference: str,
is_immutable_id=False,
insecure: bool = False,
):
self.reference = reference
self.insecure = insecure
super().__init__(client_config, "name", reference, is_immutable_id)

def __enter__(self):
Expand All @@ -25,7 +30,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.remove()

def _fetch_inspect_result_json(self, reference):
json_str = run(self.docker_cmd + ["manifest", "inspect", reference])
cmd = self.docker_cmd + ["manifest", "inspect", reference]
cmd.add_flag("--insecure", self.insecure)
json_str = run(cmd)
return json.loads(json_str)

def _parse_json_object(
Expand Down Expand Up @@ -126,9 +133,9 @@ def create(
self.client_config, run(full_cmd)[22:], is_immutable_id=True
)

def inspect(self, x: str) -> ManifestList:
def inspect(self, x: str, insecure: bool = False) -> ManifestList:
"""Returns a Docker manifest list object."""
return ManifestList(self.client_config, x)
return ManifestList(self.client_config, x, insecure=insecure)

def push(self, x: str, purge: bool = False, quiet: bool = False):
"""Push a manifest list to a repository.
Expand Down
26 changes: 26 additions & 0 deletions tests/python_on_whales/components/test_manifest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
from typing import Generator
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -70,3 +71,28 @@ def test_manifest_platform_variant(platform_variant_manifest: Image):
assert "linux" in repr(platform_variant_manifest.os)
assert "arm" in repr(platform_variant_manifest.architecture)
assert "v7" in repr(platform_variant_manifest.variant)


@pytest.mark.parametrize("insecure", [False, True])
def test_manifest_inspect_insecure_flag(docker_client: DockerClient, insecure: bool):
ref = "busybox:latest"

fake_json = {
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [],
}

with patch("python_on_whales.components.manifest.cli_wrapper.run") as mock_run:
mock_run.return_value = json.dumps(fake_json)

manifest: ManifestList = docker_client.manifest.inspect(ref, insecure=insecure)

assert manifest.insecure == insecure

cmd = list(mock_run.call_args[0][0])

if insecure:
assert "--insecure" in cmd
else:
assert "--insecure" not in cmd
Loading