From 9e18063baffb6d9186c08aa02c329799cfa2354a Mon Sep 17 00:00:00 2001 From: Jindrich Luza Date: Thu, 14 Mar 2024 16:02:10 +0100 Subject: [PATCH] replaced container-list ep with pubtools-sign-cosign-signature-list (#229) * replaced pubtools-sign-cosign-container-list ep with pubtools-sign-cosign-signature-list --- pubtools/_quay/signer_wrapper.py | 9 ++++----- pubtools/_quay/utils/misc.py | 19 ++++++++++++++----- requirements-test.txt | 1 + tests/test_iib_operations.py | 18 +++++++++--------- tests/test_utils.py | 25 +++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/pubtools/_quay/signer_wrapper.py b/pubtools/_quay/signer_wrapper.py index 44210594..9a43f70c 100644 --- a/pubtools/_quay/signer_wrapper.py +++ b/pubtools/_quay/signer_wrapper.py @@ -6,8 +6,7 @@ import json import io - -from typing import Optional, List, Dict, Any, Tuple, Generator +from typing import Optional, List, Dict, Any, Tuple, Generator, cast from marshmallow import Schema, fields, EXCLUDE @@ -501,9 +500,9 @@ def _list_signatures(self, repository: str, tag: str) -> List[Tuple[str, str]]: + f":{tag}" ) existing_signatures = run_entrypoint( - ("pubtools-sign", "modules", "pubtools-sign-cosign-container-list"), - "pubtools-sign-cosign-container-list", - [full_reference], + ("pubtools-sign", "modules", "pubtools-sign-cosign-signature-list"), + None, + [cast(str, self.config_file), full_reference], {}, ) if existing_signatures[0]: diff --git a/pubtools/_quay/utils/misc.py b/pubtools/_quay/utils/misc.py index 6ff7efc1..93a625ca 100644 --- a/pubtools/_quay/utils/misc.py +++ b/pubtools/_quay/utils/misc.py @@ -12,7 +12,7 @@ import sys import textwrap import time -from typing import Any, Callable, Dict, Generator, cast +from typing import Any, Callable, Dict, Generator, cast, Optional from concurrent import futures @@ -138,7 +138,10 @@ def capture_stdout() -> Generator[StringIO, None, None]: @contextlib.contextmanager def setup_entry_point_cli( - entry_tuple: tuple[str, str, str], name: str, args: list[str], environ_vars: dict[str, Any] + entry_tuple: tuple[str, str, str], + name: Optional[str], + args: list[str], + environ_vars: dict[str, Any], ) -> Generator[Callable[[], Any], None, None]: """ Set up an entrypoint as a context manager. @@ -164,9 +167,15 @@ def setup_entry_point_cli( os.environ[key] = environ_vars[key] entry_point_func = pkg_resources.load_entry_point(*entry_tuple) if args: - func_args = [name] + if name: + func_args = [name] + else: + func_args = [] func_args.extend(args) - yield functools.partial(entry_point_func, func_args) + if entry_tuple[1] == "console_scripts": + yield functools.partial(entry_point_func, func_args) + else: + yield functools.partial(entry_point_func, *func_args) else: yield entry_point_func finally: @@ -179,7 +188,7 @@ def setup_entry_point_cli( def run_entrypoint( entry_tuple: tuple[str, str, str], - name: str, + name: Optional[str], args: list[str], environ_vars: dict[str, Any], capture_out: bool = True, diff --git a/requirements-test.txt b/requirements-test.txt index d6882def..ccb3c5a4 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -5,6 +5,7 @@ pylint<3.0.0 pytest-pylint pytest-cov pubtools-pyxis +pubtools-sign pyrsistent==0.15.7;python_version<'3.0' pushcollector PyHamcrest diff --git a/tests/test_iib_operations.py b/tests/test_iib_operations.py index 1e72fca8..3981565c 100644 --- a/tests/test_iib_operations.py +++ b/tests/test_iib_operations.py @@ -596,9 +596,9 @@ def test_task_iib_add_bundles_operator_ns( {}, ), mock.call( - ("pubtools-sign", "modules", "pubtools-sign-cosign-container-list"), - "pubtools-sign-cosign-container-list", - ["quay.io//some-namespace/operators----index-image:8"], + ("pubtools-sign", "modules", "pubtools-sign-cosign-signature-list"), + None, + ["test-config.yml", "quay.io//some-namespace/operators----index-image:8"], {}, ), ] @@ -1002,9 +1002,9 @@ def test_task_iib_build_from_scratch( {}, ), mock.call( - ("pubtools-sign", "modules", "pubtools-sign-cosign-container-list"), - "pubtools-sign-cosign-container-list", - ["quay.io//some-namespace/operators----index-image:8"], + ("pubtools-sign", "modules", "pubtools-sign-cosign-signature-list"), + None, + ["test-config.yml", "quay.io//some-namespace/operators----index-image:8"], {}, ), ] @@ -1314,9 +1314,9 @@ def test_task_iib_build_from_scratch_operator_ns( {}, ), mock.call( - ("pubtools-sign", "modules", "pubtools-sign-cosign-container-list"), - "pubtools-sign-cosign-container-list", - ["quay.io//some-namespace/operators----index-image:8"], + ("pubtools-sign", "modules", "pubtools-sign-cosign-signature-list"), + None, + ["test-config.yml", "quay.io//some-namespace/operators----index-image:8"], {}, ), ] diff --git a/tests/test_utils.py b/tests/test_utils.py index 1457c5ff..5f508691 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -52,6 +52,31 @@ def side_effect_entrypoint(*args): compare_logs(caplog, expected_logs) +def test_run_entrypoint_mod(caplog): + def side_effect_entrypoint(*args): + LOG.warning("log generated by entrypoint") + LOG.info("environment variable: {0}".format(os.environ["PYXIS_PASSWORD"])) + return {"return": "value"} + + with mock_entry_point( + "pubtools-sign", "modules", "pubtools-sign-cosign-signature-list" + ) as entrypoint: + entrypoint.side_effect = side_effect_entrypoint + ret_val = misc.run_entrypoint( + ("pubtools-sign", "modules", "pubtools-sign-cosign-signature-list"), + None, + ["some-ep-argument"], + {"PYXIS_PASSWORD": "some-password"}, + ) + expected_logs = [ + "Running task with arguments:", + "pubtools-sign-cosign-signature-list some-ep-argument", + "log generated by entrypoint", + "environment variable: some-password", + ] + compare_logs(caplog, expected_logs) + + def test_run_entrypoint_without_args(caplog): def side_effect_entrypoint(*args): LOG.warning("log generated by entrypoint")