Skip to content

Commit bffdd37

Browse files
author
Yasen Trahnov
committed
styling and commands cleanup
1 parent 3ea8e76 commit bffdd37

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

pulp-glue-console/pulp_glue/console/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PulpVulnerabilityReportContext(PulpEntityContext):
1212
ID_PREFIX = "vuln_report"
1313
HREF = "service_vulnerability_report_href"
1414

15-
def upload(self, file: t.IO[bytes], chunk_size: int = 1000000) -> dict:
15+
def upload(self, file: t.IO[bytes], chunk_size: int = 1000000) -> t.Dict[str, t.Any]:
1616
"""Upload a vulnerability report from a JSON file.
1717
1818
Args:
@@ -30,4 +30,4 @@ def upload(self, file: t.IO[bytes], chunk_size: int = 1000000) -> dict:
3030
body={"package_json": file_content},
3131
validate_body=False,
3232
)
33-
return response
33+
return t.cast(t.Dict[str, t.Any], response)

pulpcore/cli/console/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from pulp_glue.common.openapi import OpenAPI, _Response
66

77

8-
def mount(main: click.Group, **kwargs) -> None:
8+
def mount(main: click.Group, **kwargs: t.Any) -> None:
99
# Store the original _parse_response method
1010
original_parse_response = OpenAPI._parse_response
1111

1212
# Define our custom implementation that handles 202 responses (Original one throws an error)
13-
def custom_parse_response(self, method_spec: t.Dict[str, t.Any], response: _Response) -> t.Any:
13+
def custom_parse_response(
14+
self: OpenAPI, method_spec: t.Dict[str, t.Any], response: _Response
15+
) -> t.Any:
1416
# Handle 202 responses directly
1517
if response.status_code == 202:
1618
content_type = response.headers.get("content-type")
@@ -21,15 +23,14 @@ def custom_parse_response(self, method_spec: t.Dict[str, t.Any], response: _Resp
2123
# For all other responses, use the original implementation
2224
return original_parse_response(self, method_spec, response)
2325

24-
# Apply the patch
25-
OpenAPI._parse_response = custom_parse_response
26+
setattr(OpenAPI, "_parse_response", custom_parse_response)
2627

2728
# Continue with normal mounting
2829
from pulpcore.cli.console.vulnerability import attach_vulnerability_commands
2930

3031
@main.group()
31-
def console():
32+
def console() -> None:
3233
"""Pulp Console commands."""
3334
pass
3435

35-
attach_vulnerability_commands(console)
36+
attach_vulnerability_commands(console) # type: ignore

pulpcore/cli/console/vulnerability.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import click
22
from pulp_glue.common.context import PulpContext
33
from pulp_glue.console.context import PulpVulnerabilityReportContext
4+
from typing import IO, Any, Optional
45

56
from pulpcore.cli.common.generic import (
67
PulpCLIContext,
8+
PulpEntityContext,
79
chunk_size_option,
8-
create_command,
910
destroy_command,
1011
href_option,
1112
list_command,
@@ -15,7 +16,7 @@
1516
)
1617

1718

18-
def attach_vulnerability_commands(console_group):
19+
def attach_vulnerability_commands(console_group: click.Group) -> None:
1920
@console_group.group()
2021
@pass_pulp_context
2122
@click.pass_context
@@ -28,8 +29,7 @@ def vulnerability(ctx: click.Context, pulp_ctx: PulpContext, /) -> None:
2829
# Add commands to the vulnerability group
2930
vulnerability.add_command(list_command())
3031
vulnerability.add_command(show_command(decorators=lookup_options))
31-
vulnerability.add_command(destroy_command())
32-
vulnerability.add_command(create_command())
32+
vulnerability.add_command(upload())
3333

3434
@vulnerability.command()
3535
@click.option(
@@ -40,11 +40,12 @@ def vulnerability(ctx: click.Context, pulp_ctx: PulpContext, /) -> None:
4040
@pass_pulp_context
4141
def upload(
4242
pulp_ctx: PulpCLIContext,
43-
vulnerability_ctx: PulpVulnerabilityReportContext,
43+
vulnerability_ctx: PulpEntityContext,
4444
/,
45-
file: click.File,
45+
file: IO[bytes],
4646
chunk_size: int,
4747
) -> None:
4848
"""Upload a vulnerability report JSON file."""
49+
assert isinstance(vulnerability_ctx, PulpVulnerabilityReportContext)
4950
result = vulnerability_ctx.upload(file, chunk_size)
5051
pulp_ctx.output_result(result)

0 commit comments

Comments
 (0)