From e6b5a5d4e764da341f58148dbafa1822714379bd Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Thu, 22 Jun 2023 19:23:28 -0400 Subject: [PATCH] Add options for workflows [noissue] --- pulpcore/cli/gem/content.py | 4 +++ pulpcore/cli/gem/distribution.py | 16 ++++++++++- pulpcore/cli/gem/remote.py | 12 ++++++++ pulpcore/cli/gem/repository.py | 29 +++++++++++++++++++ tests/scripts/pulp_gem/test_content.sh | 31 +++++++++++++++++++++ tests/scripts/pulp_gem/test_distribution.sh | 3 ++ tests/scripts/pulp_gem/test_remote.sh | 4 +-- 7 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 tests/scripts/pulp_gem/test_content.sh diff --git a/pulpcore/cli/gem/content.py b/pulpcore/cli/gem/content.py index bcccf65..e0d5b44 100644 --- a/pulpcore/cli/gem/content.py +++ b/pulpcore/cli/gem/content.py @@ -90,6 +90,9 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, content_type: str) -> click.option( "--version", callback=lookup_callback("version", PulpGemContentContext), expose_value=False ), + click.option( + "--checksum", callback=lookup_callback("checksum", PulpGemContentContext), expose_value=False + ) ] create_options = [ click.option( @@ -107,6 +110,7 @@ def content(ctx: click.Context, pulp_ctx: PulpCLIContext, content_type: str) -> decorators=[ click.option("--name"), click.option("--version"), + click.option("--checksum"), ] ) ) diff --git a/pulpcore/cli/gem/distribution.py b/pulpcore/cli/gem/distribution.py index 2be6cd0..9f57546 100644 --- a/pulpcore/cli/gem/distribution.py +++ b/pulpcore/cli/gem/distribution.py @@ -1,6 +1,10 @@ import click from pulp_glue.common.i18n import get_translation -from pulp_glue.gem.context import PulpGemDistributionContext, PulpGemRepositoryContext +from pulp_glue.gem.context import ( + PulpGemDistributionContext, + PulpGemRemoteContext, + PulpGemRepositoryContext, +) from pulpcore.cli.common.generic import ( PulpCLIContext, common_distribution_create_options, @@ -37,6 +41,15 @@ ), ) +remote_option = resource_option( + "--remote", + default_plugin="gem", + default_type="gem", + context_table={"gem:gem": PulpGemRemoteContext}, + href_pattern=PulpGemRemoteContext.HREF_PATTERN, + help=_("Remote to be used for pull-through caching."), +) + @pulp_group() @click.option( @@ -66,6 +79,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpCLIContext, distribution_type ), ), repository_option, + remote_option, pulp_labels_option, ] create_options = common_distribution_create_options + update_options diff --git a/pulpcore/cli/gem/remote.py b/pulpcore/cli/gem/remote.py index 8877bb8..9711186 100644 --- a/pulpcore/cli/gem/remote.py +++ b/pulpcore/cli/gem/remote.py @@ -10,6 +10,7 @@ href_option, label_command, list_command, + load_json_callback, name_option, pass_pulp_context, pulp_group, @@ -46,6 +47,17 @@ def remote(ctx: click.Context, pulp_ctx: PulpCLIContext, remote_type: str) -> No click.option( "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) ), + click.option( + "--includes", + callback=load_json_callback, + help=_("Gem allow list. Dictionary of form 'gem:version-specifier/null'"), + ), + click.option( + "--excludes", + callback=load_json_callback, + help=_("Gem block list. Dictionary of form 'gem:version-specifier/null'"), + ), + click.option("--prereleases/--no-prereleases", default=None, help=_("Include prereleases in sync")), ] remote.add_command(list_command(decorators=remote_filter_options)) diff --git a/pulpcore/cli/gem/repository.py b/pulpcore/cli/gem/repository.py index ffee767..5d40828 100644 --- a/pulpcore/cli/gem/repository.py +++ b/pulpcore/cli/gem/repository.py @@ -11,11 +11,13 @@ from pulpcore.cli.common.generic import ( PulpCLIContext, create_command, + create_content_json_callback, destroy_command, href_option, label_command, label_select_option, list_command, + lookup_callback, name_option, pass_pulp_context, pass_repository_context, @@ -74,6 +76,30 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, repo_type: str) -> pulp_labels_option, ] create_options = update_options + [click.option("--name", required=True)] +content_checksum_option = click.option( + "--checksum", callback=lookup_callback("checksum", PulpGemContentContext), expose_value=False +) +content_json_callback = create_content_json_callback(PulpGemContentContext) +modify_options = [ + click.option( + "--add-content", + callback=content_json_callback, + help=_( + """JSON string with a list of objects to add to the repository. + Each object should have the key: "href" or "checksum" + The argument prefixed with the '@' can be the path to a JSON file with a list of objects.""" + ), + ), + click.option( + "--remove-content", + callback=content_json_callback, + help=_( + """JSON string with a list of objects to remove from the repository. + Each object should have the key: "href" or "checksum" + The argument prefixed with the '@' can be the path to a JSON file with a list of objects.""" + ), + ), +] repository.add_command(list_command(decorators=[label_select_option])) repository.add_command(show_command(decorators=lookup_options)) @@ -86,6 +112,9 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, repo_type: str) -> repository.add_command( repository_content_command( contexts={"gem": PulpGemContentContext}, + add_decorators=[href_option, content_checksum_option], + remove_decorators=[href_option, content_checksum_option], + modify_decorators=modify_options, ) ) diff --git a/tests/scripts/pulp_gem/test_content.sh b/tests/scripts/pulp_gem/test_content.sh new file mode 100644 index 0000000..bc5dd7a --- /dev/null +++ b/tests/scripts/pulp_gem/test_content.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# shellcheck source=tests/scripts/config.source +. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source + +pulp debug has-plugin --name "gem" || exit 23 + +cleanup() { + rm "amber-1.0.0.gem" + pulp gem repository destroy --name "cli_test_gem_repository" || true + pulp gem repository destroy --name "cli_test_gem_upload_repository" || true + pulp orphan cleanup --protection-time 0 || true +} +trap cleanup EXIT + +# Test gem upload +wget "https://fixtures.pulpproject.org/gem/gems/amber-1.0.0.gem" +sha256=$(sha256sum "amber-1.0.0.gem" | cut -d' ' -f1) + +expect_succ pulp gem repository create --name "cli_test_gem_upload_repository" +expect_succ pulp gem content upload --file "amber-1.0.0.gem" --repository "cli_test_gem_upload_repository" +expect_succ pulp artifact list --sha256 "$sha256" +expect_succ pulp gem content list --checksum "$sha256" +content_href="$(echo "$OUTPUT" | tr '\r\n' ' ' | jq -r .[0].pulp_href)" +expect_succ pulp gem content show --href "$content_href" + +expect_succ pulp gem repository create --name "cli_test_gem_repository" +expect_succ pulp gem repository content add --repository "cli_test_gem_repository" --href "$content_href" +expect_succ pulp gem repository content remove --repository "cli_test_gem_repository" --checksum "$sha256" +expect_succ pulp gem repository content modify --repository "cli_test_gem_repository" --add-content "[{\"checksum\":\"$sha256\"}]" +expect_succ pulp gem repository content list --repository "cli_test_gem_repository" diff --git a/tests/scripts/pulp_gem/test_distribution.sh b/tests/scripts/pulp_gem/test_distribution.sh index 0bcfd69..3cc7e8f 100755 --- a/tests/scripts/pulp_gem/test_distribution.sh +++ b/tests/scripts/pulp_gem/test_distribution.sh @@ -38,6 +38,9 @@ expect_succ pulp gem distribution update \ --distribution "cli_test_gem_distro" \ --base-path "cli_test_gem_distro" \ --publication "$PUBLICATION_HREF" +expect_succ pulp gem distribution update \ + --distribution "cli_test_gem_distro" \ + --remote "cli_test_gem_remote" expect_succ curl "$curl_opt" --head --fail "$PULP_BASE_URL/pulp/content/cli_test_gem_distro/specs.4.8" diff --git a/tests/scripts/pulp_gem/test_remote.sh b/tests/scripts/pulp_gem/test_remote.sh index 11b85a9..18b140b 100755 --- a/tests/scripts/pulp_gem/test_remote.sh +++ b/tests/scripts/pulp_gem/test_remote.sh @@ -12,9 +12,9 @@ trap cleanup EXIT expect_succ pulp gem remote list -expect_succ pulp gem remote create --name "cli_test_gem_remote" --url "$GEM_REMOTE_URL" +expect_succ pulp gem remote create --name "cli_test_gem_remote" --url "$GEM_REMOTE_URL" --includes '{"panda":null}' -expect_succ pulp gem remote update --remote "cli_test_gem_remote" --policy "on_demand" +expect_succ pulp gem remote update --remote "cli_test_gem_remote" --policy "on_demand" --prereleases expect_succ pulp gem remote show --remote "cli_test_gem_remote" expect_succ pulp gem remote list