Skip to content

Commit 38fe934

Browse files
authored
STAC-22970: Installation scripts support STS_SKIP_SSL, STS_CA_CERT_BASE64_DATA, and STS_CA_CERT_path (#105)
1 parent 6305484 commit 38fe934

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

scripts/publish/installers/install.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ new-module -name "StsCliInstaller" -scriptblock {
1616
param (
1717
[string]$StsUrl, # url of the StackState instance to configure (empty means don't configure)
1818
[string]$StsApiToken, # API-TOKEN of the StackState instance to configure (empty means don't configure)
19-
[string]$StsCliVersion # version of the CLI to install (empty means latest)
19+
[string]$StsCliVersion, # version of the CLI to install (empty means latest)
20+
[string]$StsCaCertPath, # Path to CA certificate file for HTTPS verification
21+
[string]$StsCaCertBase64Data, # Base64 encoded CA certificate data for HTTPS verification
22+
[string]$StsSkipSsl # Skip SSL verification (if set, CA cert options are ignored)
2023
)
2124
# Stop on first error
2225
$ErrorActionPreference = "Stop"
@@ -66,7 +69,15 @@ new-module -name "StsCliInstaller" -scriptblock {
6669

6770
# Configure the CLI if config parameters have been set
6871
if ($StsUrl -and $StsApiToken) {
69-
& sts context save --url $StsUrl --api-token $StsApiToken
72+
if ($StsSkipSsl -eq "true") {
73+
& sts context save --url $StsUrl --api-token $StsApiToken --skip-ssl $StsSkipSsl
74+
} elseif ($StsCaCertPath) {
75+
& sts context save --url $StsUrl --api-token $StsApiToken --ca-cert-path $StsCaCertPath
76+
} elseif ($StsCaCertBase64Data) {
77+
& sts context save --url $StsUrl --api-token $StsApiToken --ca-cert-base64-data $StsCaCertBase64Data
78+
} else {
79+
& sts context save --url $StsUrl --api-token $StsApiToken
80+
}
7081
if ($LastExitCode -ne 0) {
7182
return
7283
}

scripts/publish/installers/install.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# STS_URL - url of the StackState instance to configure (empty means don't configure)
88
# STS_API_TOKEN - API-TOKEN of the StackState instance to configure (empty means don't configure)
99
# STS_CLI_LOCATION - Path you want to install CLI (empty means `/usr/local/bin`)
10+
# STS_CA_CERT_PATH - Path to CA certificate file for HTTPS verification
11+
# STS_CA_CERT_BASE64_DATA - Base64 encoded CA certificate data for HTTPS verification
12+
# STS_SKIP_SSL - Skip SSL verification (if set, CA cert options are ignored)
1013
#-----------------------------------
1114

1215
#!/usr/bin/env bash
@@ -75,9 +78,32 @@ fi
7578
# Verify that 'sts' works
7679
${TARGET_CLI_PATH}/sts > /dev/null 2>&1
7780

81+
# Validate SSL/CA certificate environment variables
82+
if [[ -n "${STS_SKIP_SSL}" ]]; then
83+
if [[ -n "${STS_CA_CERT_PATH}" || -n "${STS_CA_CERT_BASE64_DATA}" ]]; then
84+
printf "${RED}[WARNING]${NO_COLOR} STS_SKIP_SSL is set, ignoring STS_CA_CERT_PATH and STS_CA_CERT_BASE64_DATA\n"
85+
fi
86+
elif [[ -n "${STS_CA_CERT_PATH}" && -n "${STS_CA_CERT_BASE64_DATA}" ]]; then
87+
printf "${RED}[WARNING]${NO_COLOR} Both STS_CA_CERT_PATH and STS_CA_CERT_BASE64_DATA are set, STS_CA_CERT_PATH takes precedence\n"
88+
fi
89+
7890
# Configure the CLI if config parameters have been set
7991
if [[ -n "${STS_URL}" && -n "${STS_API_TOKEN}" ]]; then
80-
${TARGET_CLI_PATH}/sts context save --url ${STS_URL} --api-token ${STS_API_TOKEN}
92+
if [[ -n "${STS_SKIP_SSL}" ]]; then
93+
COMMAND="${TARGET_CLI_PATH}/sts context save --url ${STS_URL} --api-token ${STS_API_TOKEN} --skip-ssl"
94+
elif [[ -n "${STS_CA_CERT_PATH}" ]]; then
95+
COMMAND="${TARGET_CLI_PATH}/sts context save --url ${STS_URL} --api-token ${STS_API_TOKEN} --ca-cert-path ${STS_CA_CERT_PATH}"
96+
elif [[ -n "${STS_CA_CERT_BASE64_DATA}" ]]; then
97+
COMMAND="${TARGET_CLI_PATH}/sts context save --url ${STS_URL} --api-token ${STS_API_TOKEN} --ca-cert-base64-data ${STS_CA_CERT_BASE64_DATA}"
98+
else
99+
COMMAND="${TARGET_CLI_PATH}/sts context save --url ${STS_URL} --api-token ${STS_API_TOKEN}"
100+
fi
101+
${COMMAND}
102+
if [[ $? -ne 0 ]]; then
103+
error "Failed to configure the CLI with the provided parameters. Please check your STS_URL and STS_API_TOKEN."
104+
else
105+
printf "Successfully configured the CLI with the provided parameters.\n"
106+
fi
81107
fi
82108

83109
if [ "$(whereis sts)" == "" ]; then

0 commit comments

Comments
 (0)