Skip to content

Commit f43bf26

Browse files
committed
move authentication options to the root level
1 parent c715368 commit f43bf26

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

cycode/cli/app.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def export_if_needed_on_close(ctx: typer.Context) -> None:
6363
printer.export()
6464

6565

66+
_AUTH_RICH_HELP_PANEL = 'Authentication options'
6667
_COMPLETION_RICH_HELP_PANEL = 'Completion options'
6768

6869

@@ -83,6 +84,20 @@ def app_callback(
8384
Optional[str],
8485
typer.Option(hidden=True, help='Characteristic JSON object that lets servers identify the application.'),
8586
] = None,
87+
client_secret: Annotated[
88+
Optional[str],
89+
typer.Option(
90+
help='Specify a Cycode client secret for this specific scan execution.',
91+
rich_help_panel=_AUTH_RICH_HELP_PANEL,
92+
),
93+
] = None,
94+
client_id: Annotated[
95+
Optional[str],
96+
typer.Option(
97+
help='Specify a Cycode client ID for this specific scan execution.',
98+
rich_help_panel=_AUTH_RICH_HELP_PANEL,
99+
),
100+
] = None,
86101
_: Annotated[
87102
Optional[bool],
88103
typer.Option(
@@ -122,6 +137,9 @@ def app_callback(
122137
if output == OutputTypeOption.JSON:
123138
no_progress_meter = True
124139

140+
ctx.obj['client_id'] = client_id
141+
ctx.obj['client_secret'] = client_secret
142+
125143
ctx.obj['progress_bar'] = get_progress_bar(hidden=no_progress_meter, sections=SCAN_PROGRESS_BAR_SECTIONS)
126144

127145
ctx.obj['console_printer'] = ConsolePrinter(ctx)

cycode/cli/apps/ai_remediation/ai_remediation_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def ai_remediation_command(
2424
* `cycode ai-remediation <detection_id>`: View remediation guidance
2525
* `cycode ai-remediation <detection_id> --fix`: Apply suggested fixes
2626
"""
27-
client = get_scan_cycode_client()
27+
client = get_scan_cycode_client(ctx)
2828

2929
try:
3030
remediation_markdown = client.get_ai_remediation(detection_id)

cycode/cli/apps/report/sbom/path/path_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def path_command(
2424
) -> None:
2525
add_breadcrumb('path')
2626

27-
client = get_report_cycode_client()
27+
client = get_report_cycode_client(ctx)
2828
report_parameters = ctx.obj['report_parameters']
2929
output_format = report_parameters.output_format
3030
output_file = ctx.obj['output_file']

cycode/cli/apps/report/sbom/repository_url/repository_url_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def repository_url_command(
2020
progress_bar.start()
2121
progress_bar.set_section_length(SbomReportProgressBarSection.PREPARE_LOCAL_FILES)
2222

23-
client = get_report_cycode_client()
23+
client = get_report_cycode_client(ctx)
2424
report_parameters = ctx.obj['report_parameters']
2525
output_file = ctx.obj['output_file']
2626
output_format = report_parameters.output_format

cycode/cli/apps/scan/scan_command.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from cycode.cli.utils.get_api_client import get_scan_cycode_client
1414
from cycode.cli.utils.sentry import add_breadcrumb
1515

16-
_AUTH_RICH_HELP_PANEL = 'Authentication options'
1716
_EXPORT_RICH_HELP_PANEL = 'Export options'
1817
_SCA_RICH_HELP_PANEL = 'SCA options'
1918
_SECRET_RICH_HELP_PANEL = 'Secret options'
@@ -30,20 +29,6 @@ def scan_command(
3029
case_sensitive=False,
3130
),
3231
] = ScanTypeOption.SECRET,
33-
client_secret: Annotated[
34-
Optional[str],
35-
typer.Option(
36-
help='Specify a Cycode client secret for this specific scan execution.',
37-
rich_help_panel=_AUTH_RICH_HELP_PANEL,
38-
),
39-
] = None,
40-
client_id: Annotated[
41-
Optional[str],
42-
typer.Option(
43-
help='Specify a Cycode client ID for this specific scan execution.',
44-
rich_help_panel=_AUTH_RICH_HELP_PANEL,
45-
),
46-
] = None,
4732
show_secret: Annotated[
4833
bool, typer.Option('--show-secret', help='Show Secrets in plain text.', rich_help_panel=_SECRET_RICH_HELP_PANEL)
4934
] = False,
@@ -143,7 +128,7 @@ def scan_command(
143128

144129
ctx.obj['show_secret'] = show_secret
145130
ctx.obj['soft_fail'] = soft_fail
146-
ctx.obj['client'] = get_scan_cycode_client(client_id, client_secret, not ctx.obj['show_secret'])
131+
ctx.obj['client'] = get_scan_cycode_client(ctx)
147132
ctx.obj['scan_type'] = scan_type
148133
ctx.obj['sync'] = sync
149134
ctx.obj['severity_threshold'] = severity_threshold

cycode/cli/apps/status/get_cli_status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_cli_status(ctx: 'Context') -> CliStatus:
2222
supported_modules_status = CliSupportedModulesStatus()
2323
if is_authenticated:
2424
try:
25-
client = get_scan_cycode_client()
25+
client = get_scan_cycode_client(ctx)
2626
supported_modules_preferences = client.get_supported_modules_preferences()
2727

2828
supported_modules_status.secret_scanning = supported_modules_preferences.secret_scanning

cycode/cli/utils/get_api_client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from cycode.cyclient.client_creator import create_report_client, create_scan_client
77

88
if TYPE_CHECKING:
9+
import typer
10+
911
from cycode.cyclient.report_client import ReportClient
1012
from cycode.cyclient.scan_client import ScanClient
1113

@@ -23,15 +25,16 @@ def _get_cycode_client(
2325
return create_client_func(client_id, client_secret, hide_response_log)
2426

2527

26-
def get_scan_cycode_client(
27-
client_id: Optional[str] = None, client_secret: Optional[str] = None, hide_response_log: bool = True
28-
) -> 'ScanClient':
28+
def get_scan_cycode_client(ctx: 'typer.Context') -> 'ScanClient':
29+
client_id = ctx.obj.get('client_id')
30+
client_secret = ctx.obj.get('client_secret')
31+
hide_response_log = not ctx.obj['show_secret']
2932
return _get_cycode_client(create_scan_client, client_id, client_secret, hide_response_log)
3033

3134

32-
def get_report_cycode_client(
33-
client_id: Optional[str] = None, client_secret: Optional[str] = None, hide_response_log: bool = True
34-
) -> 'ReportClient':
35+
def get_report_cycode_client(ctx: 'typer.Context', hide_response_log: bool = True) -> 'ReportClient':
36+
client_id = ctx.obj.get('client_id')
37+
client_secret = ctx.obj.get('client_secret')
3538
return _get_cycode_client(create_report_client, client_id, client_secret, hide_response_log)
3639

3740

0 commit comments

Comments
 (0)