Skip to content

Commit ac4ab39

Browse files
committed
Input cleanup in deploy-certificate.sh
This brings deploy-certificate.sh up to parity with the input validation changes made in deploy-config.sh. Adds some more input validation for certificate parameters.
1 parent be7ef10 commit ac4ab39

File tree

2 files changed

+75
-168
lines changed

2 files changed

+75
-168
lines changed

src/deploy-certificate.sh

Lines changed: 75 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/bin/bash
2-
set -euo pipefail
2+
set -eo pipefail
33
IFS=$'\n\t'
44

55
for i in "$@"
66
do
77
case $i in
8-
--subscription_id=*)
8+
--subscription-id=*)
99
subscription_id="${i#*=}"
1010
shift
1111
;;
12-
--resource_group_name=*)
12+
--resource-group-name=*)
1313
resource_group_name="${i#*=}"
1414
shift
1515
;;
16-
--nginx_deployment_name=*)
16+
--nginx-deployment-name=*)
1717
nginx_deployment_name="${i#*=}"
1818
shift
1919
;;
20-
--nginx_resource_location=*)
20+
--nginx-resource-location=*)
2121
nginx_resource_location="${i#*=}"
2222
shift
2323
;;
@@ -30,40 +30,51 @@ case $i in
3030
shift
3131
;;
3232
*)
33-
echo "Not matched option '${i#*=}' passed in."
33+
echo "Unknown option '${i}' passed in."
3434
exit 1
3535
;;
3636
esac
3737
done
3838

39-
if [[ ! -v subscription_id ]];
40-
then
41-
echo "Please set 'subscription-id' ..."
42-
exit 1
39+
# Validate Required Parameters
40+
missing_params=()
41+
if [ -z "$subscription_id" ]; then
42+
missing_params+=("subscription-id")
4343
fi
44-
if [[ ! -v resource_group_name ]];
45-
then
46-
echo "Please set 'resource-group-name' ..."
47-
exit 1
44+
if [ -z "$resource_group_name" ]; then
45+
missing_params+=("resource-group-name")
4846
fi
49-
if [[ ! -v nginx_deployment_name ]];
50-
then
51-
echo "Please set 'nginx-deployment-name' ..."
52-
exit 1
47+
if [ -z "$nginx_deployment_name" ]; then
48+
missing_params+=("nginx-deployment-name")
5349
fi
54-
if [[ ! -v nginx_resource_location ]];
55-
then
56-
echo "Please set 'nginx-resource-location' ..."
57-
exit 1
50+
if [ -z "$nginx_resource_location" ]; then
51+
missing_params+=("nginx-resource-location")
5852
fi
59-
if [[ ! -v certificates ]];
60-
then
61-
echo "Please set 'nginx-certificates' ..."
53+
if [ -z "$certificates" ]; then
54+
missing_params+=("certificates")
55+
fi
56+
57+
# Check and print if any required params are missing
58+
if [ ${#missing_params[@]} -gt 0 ]; then
59+
echo "Error: Missing required variables in the workflow:"
60+
echo "${missing_params[*]}"
6261
exit 1
6362
fi
6463

64+
# Synchronize the NGINX certificates to the NGINXaaS for Azure deployment.
65+
66+
echo "Synchronizing NGINX certificates"
67+
echo "Subscription ID: $subscription_id"
68+
echo "Resource group name: $resource_group_name"
69+
echo "NGINXaaS for Azure deployment name: $nginx_deployment_name"
70+
echo "NGINXaaS for Azure Location: $nginx_resource_location"
71+
echo ""
72+
6573
az account set -s "$subscription_id" --verbose
6674

75+
echo "Installing the az nginx extension if not already installed."
76+
az extension add --name nginx --allow-preview true
77+
6778
count=$(echo "$certificates" | jq '. | length')
6879
for (( i=0; i<count; i++ ));
6980
do
@@ -72,68 +83,52 @@ do
7283
nginx_key_file=$(echo "$certificates" | jq -r '.['"$i"'].keyVirtualPath')
7384
keyvault_secret=$(echo "$certificates" | jq -r '.['"$i"'].keyvaultSecret')
7485

75-
do_nginx_arm_deployment=1
76-
err_msg=" "
77-
if [ -z "$nginx_cert_name" ] || [ "$nginx_cert_name" = "null" ]
78-
then
79-
err_msg+="nginx_cert_name is empty;"
80-
do_nginx_arm_deployment=0
86+
# Validate certificate parameters
87+
missing_cert_params=()
88+
if [ -z "$nginx_cert_name" ] || [ "$nginx_cert_name" = "null" ]; then
89+
missing_cert_params+=("certificateName")
8190
fi
82-
if [ -z "$nginx_cert_file" ] || [ "$nginx_cert_file" = "null" ]
83-
then
84-
err_msg+="nginx_cert_file is empty;"
85-
do_nginx_arm_deployment=0
91+
if [ -z "$nginx_cert_file" ] || [ "$nginx_cert_file" = "null" ]; then
92+
missing_cert_params+=("certificateVirtualPath")
8693
fi
87-
if [ -z "$nginx_key_file" ] || [ "$nginx_key_file" = "null" ]
88-
then
89-
err_msg+="nginx_key_file is empty;"
90-
do_nginx_arm_deployment=0
94+
if [ -z "$nginx_key_file" ] || [ "$nginx_key_file" = "null" ]; then
95+
missing_cert_params+=("keyVirtualPath")
9196
fi
92-
if [ -z "$keyvault_secret" ] || [ "$keyvault_secret" = "null" ]
93-
then
94-
err_msg+="keyvault_secret is empty;"
95-
do_nginx_arm_deployment=0
97+
if [ -z "$keyvault_secret" ] || [ "$keyvault_secret" = "null" ]; then
98+
missing_cert_params+=("keyvaultSecret")
9699
fi
97100

98-
echo "Synchronizing NGINX certificate"
99-
echo "Subscription ID: $subscription_id"
100-
echo "Resource group name: $resource_group_name"
101-
echo "NGINXaaS for Azure deployment name: $nginx_deployment_name"
102-
echo "NGINXaaS for Azure Location: $nginx_resource_location"
103-
echo ""
104-
echo "NGINXaaS for Azure cert name: $nginx_cert_name"
105-
echo "NGINXaaS for Azure cert file location: $nginx_cert_file"
106-
echo "NGINXaaS for Azure key file location: $nginx_key_file"
101+
if [ ${#missing_cert_params[@]} -gt 0 ]; then
102+
echo "Skipping certificate $i deployment due to missing parameters:"
103+
echo "${missing_cert_params[*]}"
104+
echo ""
105+
continue
106+
fi
107+
108+
echo "Processing certificate: $nginx_cert_name"
109+
echo "Certificate file location: $nginx_cert_file"
110+
echo "Key file location: $nginx_key_file"
107111
echo ""
108112

109-
echo "Installing the az nginx extension if not already installed."
110-
az extension add --name nginx --allow-preview true
113+
az_cmd=(
114+
"az"
115+
"nginx"
116+
"deployment"
117+
"certificate"
118+
"create"
119+
"--resource-group" "$resource_group_name"
120+
"--certificate-name" "$nginx_cert_name"
121+
"--deployment-name" "$nginx_deployment_name"
122+
"--certificate-path" "$nginx_cert_file"
123+
"--key-path" "$nginx_key_file"
124+
"--key-vault-secret-id" "$keyvault_secret"
125+
"--verbose"
126+
)
111127

112-
if [ $do_nginx_arm_deployment -eq 1 ]
113-
then
114-
az_cmd=(
115-
"az"
116-
"nginx"
117-
"deployment"
118-
"certificate"
119-
"create"
120-
"--resource-group" "$resource_group_name"
121-
"--certificate-name" "$nginx_cert_name"
122-
"--deployment-name" "$nginx_deployment_name"
123-
"--certificate-path" "$nginx_cert_file"
124-
"--key-path" "$nginx_key_file"
125-
"--key-vault-secret-id" "$keyvault_secret"
126-
"--verbose"
127-
)
128-
if [[ "$debug" == true ]]; then
129-
az_cmd+=("--debug")
130-
echo "${az_cmd[@]}"
131-
fi
132-
set +e
133-
"${az_cmd[@]}"
134-
set -e
135-
else
136-
echo "Skipping JSON object $i cert deployment with error:$err_msg"
137-
echo ""
128+
if [[ "$debug" == true ]]; then
129+
az_cmd+=("--debug")
130+
echo "${az_cmd[@]}"
138131
fi
132+
133+
"${az_cmd[@]}"
139134
done

src/deploy.sh

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)