11<# PSScriptInfo
2- .VERSION 1.0.2
2+ .VERSION 1.0.3
33.GUID 6b1307f7-7098-4c65-9a86-8478840ad4cd
44.AUTHOR Code Dx
55#>
@@ -64,6 +64,7 @@ function New-CodeDxDeployment([string] $codeDxDnsName,
6464 [string []] $serviceAnnotationsCodeDx ,
6565 [string ] $ingressControllerNamespace ,
6666 [string []] $ingressAnnotations ,
67+ [string ] $caCertsFilename ,
6768 [string ] $caCertsFilePwd ,
6869 [string ] $externalDbUrl ,
6970 [string ] $externalDbUser ,
@@ -73,7 +74,8 @@ function New-CodeDxDeployment([string] $codeDxDnsName,
7374 [switch ] $enablePSPs ,
7475 [switch ] $enableNetworkPolicies ,
7576 [switch ] $configureTls ,
76- [switch ] $skipDatabase ) {
77+ [switch ] $skipDatabase ,
78+ [switch ] $offlineMode ) {
7779
7880 if (-not (Test-Namespace $namespace )) {
7981 New-Namespace $namespace
@@ -197,14 +199,14 @@ mariadb:
197199 backup:
198200 size: {14}Gi
199201{22}
200- cacertsFile: ''
202+ cacertsFile: '{30} '
201203cacertsFilePwd: '{21}'
202204codedxProps:
203205 internalExtra:
204206 - type: values
205207 key: codedx-offline-props
206208 values:
207- - "codedx.offline-mode = true "
209+ - "codedx.offline-mode = {31} "
208210{29}
209211'@ -f (Get-CodeDxPdSecretName $releaseName ), $tomcatImage , $imagePullSecretYaml , `
210212$psp , $networkPolicy , `
@@ -220,7 +222,7 @@ $defaultKeyStorePwd, `
220222$codeDxTomcatPortNumber , $codeDxTlsTomcatPortNumber , `
221223$serviceTypeCodeDx , (ConvertTo-YamlMap $serviceAnnotationsCodeDx ), `
222224$enableDb , $ingressNginxAssumption , `
223- $externalDb
225+ $externalDb , $caCertsFilename , $offlineMode .ToString ().ToLower()
224226
225227 $valuesFile = ' codedx-values.yaml'
226228 $values | out-file $valuesFile - Encoding ascii - Force
@@ -428,54 +430,32 @@ function Get-RunningCodeDxPodName([string] $codedxNamespace) {
428430 $name
429431}
430432
431- function Set-TrustedCerts ([string ] $workDir ,
433+ function Get-RunningCodeDxKeystore ([string ] $codedxNamespace , [string ] $outPath ) {
434+
435+ $podName = Get-RunningCodeDxPodName $codedxNamespace
436+ $podFile = " $podName `:/usr/local/openjdk-8/jre/lib/security/cacerts"
437+
438+ kubectl - n $codedxNamespace cp $podFile $outPath
439+ if ($LASTEXITCODE -ne 0 ) {
440+ throw " Unable to copy out cacerts file from '$podFile ', kubectl exited with code $LASTEXITCODE ."
441+ }
442+ }
443+
444+ function Set-TrustedCerts ([string ] $workDir ,
432445 [string ] $waitSeconds ,
433446 [string ] $codedxNamespace ,
434447 [string ] $codedxReleaseName ,
435448 [string []] $extraValuesPaths ,
436449 [string ] $adminPwd ,
437- [string ] $caCertsFilePwd ,
438- [string ] $caCertsFileNewPwd ,
450+ [string ] $keystorePwd ,
439451 [string ] $externalDbUser ,
440452 [string ] $externalDbPwd ,
441- [string []] $trustedCertPaths ,
442453 [switch ] $offlineMode ) {
443454
444- $caCertsFilePath = ' ./cacerts'
445- if (test-path $caCertsFilePath ) {
446- remove-item $caCertsFilePath - force
447- }
448-
449- $chartFolder = (join-path $workDir codedx- kubernetes/ codedx)
450- $chartFolderCaCertsFilePath = join-path $chartFolder $caCertsFilePath
451-
452- # if cacerts already exists in the chart folder via -extraCodeDxChartFilesPaths, use
453- # that copy; otherwise, pull a copy from the running Code Dx pod
454- if (test-path $chartFolderCaCertsFilePath ) {
455- copy-item $chartFolderCaCertsFilePath $caCertsFilePath
456- } else {
457- $podName = Get-RunningCodeDxPodName $codedxNamespace
458- $podFile = " $podName `:/usr/local/openjdk-8/jre/lib/security/cacerts"
459-
460- kubectl - n $codedxNamespace cp $podFile $caCertsFilePath
461- if ($LASTEXITCODE -ne 0 ) {
462- throw " Unable to copy out cacerts file, kubectl exited with code $LASTEXITCODE ."
463- }
464- }
465-
466- # set cacerts password
467- $keystorePwd = $caCertsFilePwd
468- if (' ' -ne $caCertsFileNewPwd -and $caCertsFilePwd -ne $caCertsFileNewPwd ) {
469- $keystorePwd = $caCertsFileNewPwd
470- }
471- Set-KeystorePassword $caCertsFilePath $caCertsFilePwd $keystorePwd
472455 New-CodeDxPdSecret $codedxNamespace $codedxReleaseName $adminPwd $keystorePwd $externalDbUser $externalDbPwd
473-
474- Import-TrustedCaCerts $caCertsFilePath $keystorePwd $trustedCertPaths
475-
476- # move edited cacerts file to chart directory where it can be found during chart install
477- copy-item $caCertsFilePath $chartFolder - Force
478-
456+
457+ $chartFolder = (join-path $workDir codedx- kubernetes/ codedx)
458+
479459 $values = @'
480460cacertsFile: cacerts
481461codedxProps:
@@ -752,3 +732,30 @@ function Get-CommonName([string] $name) {
752732 }
753733 $name.TrimEnd (' -' )
754734}
735+
736+ function Get-TrustedCaCertsFilePwd ([string ] $currentPwd , [string ] $newPwd ) {
737+
738+ $pwd = $currentPwd
739+ if (' ' -ne $newPwd -and $pwd -ne $newPwd ) {
740+ $pwd = $newPwd
741+ }
742+ $pwd
743+ }
744+
745+ function New-TrustedCaCertsFile ([string ] $basePath ,
746+ [string ] $currentPwd , [string ] $newPwd ,
747+ [string []] $certPathsToImport ,
748+ [string ] $destinationDirectory ) {
749+
750+ $filePath = " ./cacerts"
751+ if (Test-Path $filePath ) {
752+ Remove-Item $filePath - force
753+ }
754+ Copy-Item $basePath $filePath
755+
756+ $pwd = (Get-TrustedCaCertsFilePwd $currentPwd $newPwd )
757+ Set-KeystorePassword $filePath $currentPwd $pwd
758+
759+ Import-TrustedCaCerts $filePath $pwd $certPathsToImport
760+ Copy-Item $filePath $destinationDirectory - Force
761+ }
0 commit comments