@@ -110,18 +110,13 @@ check_file_exists() {
110110" " "
111111Extract the error message from a command's output.
112112
113- :param command : The command to execute .
113+ :param error_output : The output containing the error message .
114114:return: The extracted error message or a default message if none is found.
115115" " "
116116extract_error_message () {
117- local command=$1
118- local error_output
117+ local error_output=$1
119118 local extracted_message
120119
121- set +e # Temporarily disable exit on error
122- error_output=$( $command 2>&1 )
123- set -e # Re-enable exit on error
124-
125120 extracted_message=$( echo " $error_output " | grep -oP ' (?<=Message: ).*' | head -n 1)
126121 if [[ -z " $extracted_message " ]]; then
127122 extracted_message=" An unknown error occurred. See full error details above."
@@ -186,17 +181,27 @@ check_msi_permissions() {
186181
187182 # Attempt to access Key Vault to verify permissions
188183 log " INFO" " Verifying permissions on Key Vault: $key_vault_name ..."
189- error_message=$( extract_error_message " az keyvault secret list --vault-name \" $key_vault_name \" " )
190- if [[ $? -ne 0 ]]; then
191- log " ERROR" " Azure CLI error: $error_message "
184+ set +e # Temporarily disable exit on error
185+ error_message=$( az keyvault secret list --vault-name " $key_vault_name " 2>&1 )
186+ az_exit_code=$? # Capture the exit code of the az command
187+ set -e # Re-enable exit on error
188+
189+ if [[ $az_exit_code -ne 0 ]]; then
190+ extracted_message=$( extract_error_message " $error_message " )
191+ log " ERROR" " Azure CLI error: $extracted_message "
192192 exit 1
193193 fi
194194
195195 # Attempt to retrieve the secret value and handle errors
196196 log " INFO" " Retrieving secret '$secret_name ' from Key Vault '$key_vault_name '..."
197- secret_value=$( extract_error_message " az keyvault secret show --vault-name \" $key_vault_name \" --name \" $secret_name \" --query \" value\" -o tsv" )
198- if [[ $? -ne 0 ]]; then
199- log " ERROR" " Failed to retrieve secret '$secret_name ' from Key Vault '$key_vault_name ': $secret_value "
197+ set +e # Temporarily disable exit on error
198+ secret_value=$( az keyvault secret show --vault-name " $key_vault_name " --name " $secret_name " --query " value" -o tsv 2>&1 )
199+ az_exit_code=$? # Capture the exit code of the az command
200+ set -e # Re-enable exit on error
201+
202+ if [[ $az_exit_code -ne 0 ]]; then
203+ extracted_message=$( extract_error_message " $secret_value " )
204+ log " ERROR" " Failed to retrieve secret '$secret_name ' from Key Vault '$key_vault_name ': $extracted_message "
200205 exit 1
201206 fi
202207
@@ -317,6 +322,17 @@ main() {
317322 check_file_exists " $SYSTEM_PARAMS " \
318323 " sap-parameters.yaml not found in WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME directory."
319324
325+ # log "INFO" "Checking if the SSH key or password file exists..."
326+ # if [[ "$AUTHENTICATION_TYPE" == "SSHKEY" ]]; then
327+ # check_file_exists "${cmd_dir}/../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME/ssh_key.ppk" \
328+ # "ssh_key.ppk not found in WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME directory."
329+ # elif [[ "$AUTHENTICATION_TYPE" == "VMPASSWORD" ]]; then
330+ # check_file_exists "${cmd_dir}/../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME/password" \
331+ # "password file not found in WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME directory."
332+ # elif [[ "$AUTHENTICATION_TYPE" == "KEYVAULT" ]]; then
333+ # log "INFO" "Key Vault authentication selected. Ensure Key Vault parameters are set."
334+ # fi
335+
320336 # Extract secret_name from sap-parameters.yaml
321337 secret_name=$( grep " ^secret_name:" " $SYSTEM_PARAMS " | awk ' {split($0,a,": "); print a[2]}' | xargs)
322338
0 commit comments