Skip to content

Commit

Permalink
Add options for workflows
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
gerrod3 committed Jun 26, 2023
1 parent 03aef76 commit e6b5a5d
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pulpcore/cli/gem/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"),
]
)
)
Expand Down
16 changes: 15 additions & 1 deletion pulpcore/cli/gem/distribution.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions pulpcore/cli/gem/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
href_option,
label_command,
list_command,
load_json_callback,
name_option,
pass_pulp_context,
pulp_group,
Expand Down Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions pulpcore/cli/gem/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand All @@ -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,
)
)

Expand Down
31 changes: 31 additions & 0 deletions tests/scripts/pulp_gem/test_content.sh
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions tests/scripts/pulp_gem/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/pulp_gem/test_remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e6b5a5d

Please sign in to comment.