Skip to content

Commit c22a91e

Browse files
committed
Add support to vuln report for pulp_python plugin
closes: #1272
1 parent 293aef9 commit c22a91e

File tree

8 files changed

+87
-1
lines changed

8 files changed

+87
-1
lines changed

CHANGES/1272.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support to vulnerability report for pulp_python plugin.

pulp-glue/pulp_glue/common/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,10 @@ def repair(self) -> t.Any:
14171417
"""
14181418
return self.call("repair", parameters={self.HREF: self.pulp_href}, body={})
14191419

1420+
def scan(self) -> t.Any:
1421+
self.needs_capability("scan")
1422+
return self.call("scan", parameters={self.HREF: self.pulp_href})
1423+
14201424

14211425
class PulpRepositoryContext(PulpEntityContext):
14221426
"""Base class for repository contexts."""

pulp-glue/pulp_glue/core/context.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,11 @@ def find(self, **kwargs: t.Any) -> t.Any:
618618

619619
def replicate(self) -> t.Any:
620620
return self.call("replicate", parameters={self.HREF: self.pulp_href})
621+
622+
623+
class PulpVulnerabilityReportContext(PulpEntityContext):
624+
ENTITY = _("vulnerability report")
625+
ENTITIES = _("vulnerability reports")
626+
ID_PREFIX = "vuln_report"
627+
HREF = "vulnerability_report_href"
628+
NEEDS_PLUGINS = [PluginRequirement("core", specifier=">=3.85.3")]

pulp-glue/pulp_glue/python/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class PulpPythonRepositoryVersionContext(PulpRepositoryVersionContext):
101101
HREF = "python_python_repository_version_href"
102102
ID_PREFIX = "repositories_python_python_versions"
103103
NEEDS_PLUGINS = [PluginRequirement("python", specifier=">=3.1.0")]
104+
CAPABILITIES = {"scan": [PluginRequirement("python", specifier=">=3.21.0")]}
104105

105106

106107
class PulpPythonRepositoryContext(PulpRepositoryContext):

pulp_cli/generic.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ def version_command(**kwargs: t.Any) -> click.Command:
15151515
"""
15161516
A factory that creates a repository version command group.
15171517
1518-
This group contains `list`, `show`, `destroy` and `repair` subcommands.
1518+
This group contains `list`, `show`, `destroy`, `repair` and `scan` subcommands.
15191519
If `list_only=True` is passed, only the `list` command will be instantiated.
15201520
Repository lookup options can be provided in `decorators`.
15211521
"""
@@ -1549,6 +1549,19 @@ def repair(
15491549
result = repository_version_ctx.repair()
15501550
pulp_ctx.output_result(result)
15511551

1552+
@callback.command()
1553+
@repository_lookup_option
1554+
@version_option
1555+
@pass_repository_version_context
1556+
@pass_pulp_context
1557+
def scan(
1558+
pulp_ctx: PulpCLIContext,
1559+
repository_version_ctx: PulpRepositoryVersionContext,
1560+
/,
1561+
) -> None:
1562+
result = repository_version_ctx.scan()
1563+
pulp_ctx.output_result(result)
1564+
15521565
return callback
15531566

15541567

pulpcore/cli/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pulpcore.cli.core.upload import upload
2626
from pulpcore.cli.core.upstream_pulp import upstream_pulp
2727
from pulpcore.cli.core.user import user
28+
from pulpcore.cli.core.vulnerability_report import vulnerability_report
2829
from pulpcore.cli.core.worker import worker
2930

3031

@@ -52,6 +53,7 @@ def mount(main: click.Group, **kwargs: t.Any) -> None:
5253
main.add_command(upload)
5354
main.add_command(upstream_pulp)
5455
main.add_command(user)
56+
main.add_command(vulnerability_report)
5557
main.add_command(worker)
5658

5759
_orig_get_command = main.get_command
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import click
2+
from pulp_glue.common.i18n import get_translation
3+
from pulp_glue.core.context import PulpVulnerabilityReportContext
4+
5+
from pulpcore.cli.common.generic import (
6+
PulpCLIContext,
7+
href_option,
8+
list_command,
9+
pass_pulp_context,
10+
pulp_group,
11+
show_command,
12+
)
13+
14+
translation = get_translation(__package__)
15+
_ = translation.gettext
16+
17+
lookup_options = [href_option]
18+
19+
20+
@pulp_group()
21+
@pass_pulp_context
22+
@click.pass_context
23+
def vulnerability_report(ctx: click.Context, pulp_ctx: PulpCLIContext, /) -> None:
24+
ctx.obj = PulpVulnerabilityReportContext(pulp_ctx)
25+
26+
27+
vulnerability_report.add_command(list_command())
28+
vulnerability_report.add_command(show_command(decorators=lookup_options))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
# shellcheck source=tests/scripts/config.source
5+
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source
6+
7+
cleanup() {
8+
pulp python repository destroy --name python || true
9+
pulp python remote destroy --name python || true
10+
pulp file repository destroy --name file-repo || true
11+
pulp orphan cleanup --protection-time=0
12+
}
13+
trap cleanup EXIT
14+
15+
pulp debug has-plugin --name "core" --specifier ">=3.85.3" || exit 0
16+
pulp debug has-plugin --name "python" --specifier ">=3.21.0" || exit 0
17+
18+
# create a test repository
19+
pulp python repository create --name python
20+
pulp python remote create --name python --url "https://pypi.org/" --includes '["django==5.2.1"]'
21+
pulp python repository sync --name python --remote python
22+
23+
expect_succ pulp python repository version scan --repository python
24+
VULN_REPORT=$(echo "$OUTPUT" | jq .pulp_href -r)
25+
expect_succ pulp vulnerability-report show --href "$VULN_REPORT"
26+
27+
# test with non-implemented content type
28+
pulp file repository create --name file-repo
29+
expect_fail pulp file repository version scan --repository file-repo

0 commit comments

Comments
 (0)