@@ -83,6 +83,16 @@ function Validate-Mode {
83
83
}
84
84
}
85
85
86
+ # Function to validate an environment value i.e. prod or staging
87
+ function Validate-Env {
88
+ param ($env_val )
89
+
90
+ if ($env_val -ne " prod" -and $env_val -ne " staging" ) {
91
+ Write-Host " Invalid env value. Please enter either prod or staging."
92
+ exit 1
93
+ }
94
+ }
95
+
86
96
# Function to display URL using IP address and port
87
97
# Run docker ps -l command and store the output
88
98
function Display-DockerUrl {
@@ -149,6 +159,37 @@ function Check-ActionDirectory {
149
159
return $action_dir
150
160
}
151
161
162
+ # Function to check if the CLI directory exists
163
+ function Check-CliDirectory {
164
+ param ($cli_dir )
165
+
166
+ if (-not $cli_dir ) {
167
+ Write-Host " CLI directory not provided!"
168
+ exit 1
169
+ }
170
+
171
+ if (-not (Test-Path - Path $cli_dir - PathType Container)) {
172
+ Write-Host " CLI directory not found!"
173
+ exit 1
174
+ }
175
+
176
+ # return valid cli directory
177
+ return $cli_dir
178
+ }
179
+
180
+ # Function to check if the output path directory exists
181
+ function Check-OutputDirectory {
182
+ param ($output_path )
183
+
184
+ if (-not (Test-Path - Path $output_path - PathType Container)) {
185
+ Write-Host " Output path directory not found!"
186
+ exit 1
187
+ }
188
+
189
+ # return valid cli directory
190
+ return $output_path
191
+ }
192
+
152
193
function Stop-CRA {
153
194
if (Test-Path " $BITOCRALOCKFILE " ) {
154
195
Write-Host " Stopping the CRA..."
@@ -294,7 +335,11 @@ $optional_params_cli = @(
294
335
" static_analysis" ,
295
336
" dependency_check" ,
296
337
" dependency_check.snyk_auth_token" ,
297
- " cra_version"
338
+ " cra_version" ,
339
+ " env" ,
340
+ " cli_path" ,
341
+ " output_path"
342
+ " git.domain"
298
343
)
299
344
300
345
# Parameters that are required/optional in mode server
@@ -312,6 +357,9 @@ $optional_params_server = @(
312
357
" dependency_check.snyk_auth_token" ,
313
358
" server_port" ,
314
359
" cra_version"
360
+ " env"
361
+ " cli_path"
362
+ " git.domain"
315
363
)
316
364
317
365
$bee_params = @ (
@@ -337,9 +385,9 @@ if ($props[$param_cra_version] -ne '') {
337
385
$docker_pull = " docker pull bitoai/cra:${cra_version} "
338
386
339
387
# Construct the docker run command
340
- $docker_cmd = " docker run --rm -it"
388
+ $docker_init_cmd = " docker run --rm -it"
341
389
if (-not ([string ]::IsNullOrEmpty($action_directory ))) {
342
- $docker_cmd = " docker run --rm -it -v ${action_directory} :/action_dir"
390
+ $docker_init_cmd = " docker run --rm -it -v ${action_directory} :/action_dir"
343
391
}
344
392
345
393
$required_params = $required_params_cli
@@ -348,6 +396,7 @@ $mode = "cli"
348
396
$param_mode = " mode"
349
397
$server_port = " 10051"
350
398
$param_server_port = " server_port"
399
+ $docker_cmd = " "
351
400
# handle if CRA is starting in server mode using start command.
352
401
if ($force_mode ) {
353
402
$props [$param_mode ] = $force_mode
@@ -378,7 +427,7 @@ foreach ($param in $required_params) {
378
427
foreach ($param in $optional_params ) {
379
428
if ($param -eq " dependency_check.snyk_auth_token" -and $props [" dependency_check" ] -eq " True" ) {
380
429
Ask- For- Param $param $false
381
- } elseif ($param -ne " dependency_check.snyk_auth_token" ) {
430
+ } elseif ($param -ne " dependency_check.snyk_auth_token" -and $param -ne " env " -and $param -ne " cli_path " -and $param -ne " output_path " -and $param -ne " git.domain " ) {
382
431
Ask- For- Param $param $false
383
432
}
384
433
}
@@ -393,8 +442,9 @@ foreach ($param in $required_params + $bee_params + $optional_params) {
393
442
$server_port = $props [$param ]
394
443
$docker_cmd += " --$param =$ ( $props [$param ]) "
395
444
} elseif ($param -eq " pr_url" ) {
396
- Validate- Url $props [$param ]
397
- $docker_cmd += " --$param =$ ( $props [$param ]) review"
445
+ $trimmedUrl = $props [$param ].Trim()
446
+ Validate- Url $trimmedUrl
447
+ $docker_cmd += " --$param =$ ( $trimmedUrl ) review"
398
448
} elseif ($param -eq " git.provider" ) {
399
449
$validated_gitprovider = Validate- GitProvider $props [$param ]
400
450
$docker_cmd += " --$param =$validated_gitprovider "
@@ -410,12 +460,27 @@ foreach ($param in $required_params + $bee_params + $optional_params) {
410
460
} elseif ($param -eq " mode" ) {
411
461
Validate- Mode $props [$param ]
412
462
$docker_cmd += " --$param =$ ( $props [$param ]) "
463
+ } elseif ($param -eq " env" ) {
464
+ Validate- Env $props [$param ]
465
+ $docker_cmd += " --$param =$ ( $props [$param ]) "
466
+ } elseif ($param -eq " cli_path" ) {
467
+ $cli_dir = Check- CliDirectory $ ($props [$param ])
468
+ $docker_init_cmd += " -v ${cli_dir} :/cli_dir"
469
+ } elseif ($param -eq " output_path" ) {
470
+ if ($ ($props [$param ]) -ne $null -and $ ($props [$param ]) -ne " " ) {
471
+ $output_path = Check- OutputDirectory $ ($props [$param ])
472
+ if ($output_path -ne $null -and $output_path -ne " " ) {
473
+ $docker_init_cmd += " -v '${output_path} :/output_path'"
474
+ $docker_cmd += " --$param =/output_path"
475
+ }
476
+ }
413
477
} else {
414
478
$docker_cmd += " --$param =$ ( $props [$param ]) "
415
479
}
416
480
}
417
481
}
418
482
483
+ $docker_cmd = $docker_init_cmd + $docker_cmd
419
484
$param_bito_access_key = " bito_cli.bito.access_key"
420
485
$param_git_access_token = " git.access_token"
421
486
if ($mode -eq " server" ) {
0 commit comments