Skip to content

Commit 9ad47bc

Browse files
CM-63882 - Added scanType validation
1 parent 865aa40 commit 9ad47bc

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

cycode/cli/apps/scan/scan_command.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
def scan_command(
3232
ctx: typer.Context,
3333
scan_type: Annotated[
34-
ScanTypeOption,
34+
list[ScanTypeOption],
3535
typer.Option(
3636
'--scan-type',
3737
'-t',
3838
help='Specify the type of scan you wish to execute.',
3939
case_sensitive=False,
4040
),
41-
] = ScanTypeOption.SECRET,
41+
] = (ScanTypeOption.SECRET,),
4242
soft_fail: Annotated[
4343
bool, typer.Option('--soft-fail', help='Run the scan without failing; always return a non-error status code.')
4444
] = False,
@@ -126,6 +126,16 @@ def scan_command(
126126
* `cycode scan commit-history <PATH>`: Scan the commit history of a local Git repository.
127127
128128
"""
129+
if len(scan_type) > 1:
130+
raise typer.BadParameter(
131+
f'Only one scan type can be specified per command. '
132+
f'Got: {", ".join(str(t) for t in scan_type)}. '
133+
f'Run a separate command for each scan type.',
134+
param_hint='-t/--scan-type',
135+
)
136+
137+
resolved_scan_type = scan_type[0]
138+
129139
if export_file and export_type is None:
130140
raise typer.BadParameter(
131141
'Export type must be specified when --export-file is provided.',
@@ -140,7 +150,7 @@ def scan_command(
140150
ctx.obj['show_secret'] = show_secret
141151
ctx.obj['soft_fail'] = soft_fail
142152
ctx.obj['stop_on_error'] = stop_on_error
143-
ctx.obj['scan_type'] = scan_type
153+
ctx.obj['scan_type'] = resolved_scan_type
144154
ctx.obj['sync'] = sync
145155
ctx.obj['severity_threshold'] = severity_threshold
146156
ctx.obj['monitor'] = monitor
@@ -158,9 +168,9 @@ def scan_command(
158168
# Get remote URL from current working directory
159169
remote_url = _try_get_git_remote_url(os.getcwd())
160170

161-
remote_scan_config = scan_client.get_scan_configuration_safe(scan_type, remote_url)
171+
remote_scan_config = scan_client.get_scan_configuration_safe(resolved_scan_type, remote_url)
162172
if remote_scan_config:
163-
excluder.apply_scan_config(str(scan_type), remote_scan_config)
173+
excluder.apply_scan_config(str(resolved_scan_type), remote_scan_config)
164174

165175
ctx.obj['scan_config'] = remote_scan_config
166176

0 commit comments

Comments
 (0)