Skip to content

Commit

Permalink
replaced container-list ep with pubtools-sign-cosign-signature-list (#…
Browse files Browse the repository at this point in the history
…229)

* replaced pubtools-sign-cosign-container-list ep with pubtools-sign-cosign-signature-list
  • Loading branch information
midnightercz authored Mar 14, 2024
1 parent 9e13928 commit 9e18063
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
9 changes: 4 additions & 5 deletions pubtools/_quay/signer_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down
19 changes: 14 additions & 5 deletions pubtools/_quay/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/test_iib_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
{},
),
]
Expand Down Expand Up @@ -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"],
{},
),
]
Expand Down Expand Up @@ -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"],
{},
),
]
Expand Down
25 changes: 25 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9e18063

Please sign in to comment.