Debian Codegraph @

codebuild/mqtt5_test_setup.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # Get the S3 URL containing all of the MQTT5 testing environment variables passed in to the bash script
4 testing_env_bucket=$1
5 region=$2
6
7 # Make sure we have something:
8 if [scip-shell system . . `[`. "${testing_env_bucket}" != "" ] && [scip-shell system . . `[`. "${region}" != "" ]; then
9 echoscip-shell system . . echo. "S3 bucket for environment variables found and region"
10 else
11 echoscip-shell system . . echo. "Could not get S3 bucket for environment variables and/or region."
12 echoscip-shell system . . echo. "You need to run this script and pass the S3 URL of the file containing"
13 echoscip-shell system . . echo. "all of the environment variables to set, as well as the secrets for certificates and private keys"
14 echoscip-shell system . . echo. ""
15 echoscip-shell system . . echo. "Example: mqtt5_test_setup.sh s3://<bucket>/<file> <region>"
16 echoscip-shell system . . echo. ""
17 echoscip-shell system . . echo. "When finished, run 'cleanup' to remove the files downloaded:"
18 echoscip-shell system . . echo. ""
19 echoscip-shell system . . echo. "Example: mqtt5_test_setup.sh s3://<bucket>/<file> cleanup"
20 echoscip-shell system . . echo. ""
21 return 1
22 fi
23
24 # Is this just a request to clean up?
25 # NOTE: This blindly assumes there is a environment_files.txt file
26 if [scip-shell system . . `[`. "${region}" != "cleanup" ]; then
27 sleepscip-shell system . . sleep. 0.1 # we have to do something to do an else...
28 else
29 echoscip-shell system . . echo. "Undoing environment variables"
30 unset $(grepscip-shell system . . grep. -v '^#' ${PWD}/environment_files.txt | xargsscip-shell system . . xargs. | cutscip-shell system . . cut. -d "=" -f 1)
31 unset AWS_TEST_MQTT5_CERTIFICATE_FILE
32 unset AWS_TEST_MQTT5_KEY_FILE
33 unset AWS_TEST_MQTT5_IOT_CERTIFICATE_PATH
34 unset AWS_TEST_MQTT5_IOT_KEY_PATH
35
36 echoscip-shell system . . echo. "Cleaning up resources..."
37 rmscip-shell system . . rm. "${PWD}/environment_files.txt"
38 rmscip-shell system . . rm. "${PWD}/crt_certificate.pem"
39 rmscip-shell system . . rm. "${PWD}/crt_privatekey.pem"
40 rmscip-shell system . . rm. "${PWD}/iot_certificate.pem"
41 rmscip-shell system . . rm. "${PWD}/iot_privatekey.pem"
42
43 echoscip-shell system . . echo. "Success!"
44 return 0
45 fi
46
47 # Get the file from S3
48 aws s3 cp ${testing_env_bucket} ${PWD}/environment_files.txt
49 testing_env_file=$( catscip-shell system . . cat. environment_files.txt )
50 # Make sure we have data of some form
51 if [scip-shell system . . `[`. "${testing_env_file}" != "" ]; then
52 echoscip-shell system . . echo. "Environment variables secret found"
53 else
54 echoscip-shell system . . echo. "Could not get environment variables from secrets!"
55 return 1
56 fi
57
58 # Make all the variables in mqtt5_environment_variables.txt exported
59 # so we can run MQTT5 tests
60 export $(grepscip-shell system . . grep. -v '^#' environment_files.txt | xargsscip-shell system . . xargs.)
61
62 # CRT/non-builder certificate and key processing
63 # Get the certificate and key secrets (dumps straight to a file)
64 crt_cert_file=$(aws secretsmanager get-secret-value --secret-id "${AWS_TEST_MQTT5_CERTIFICATE_FILE_SECRET}" --query "SecretString" --region ${region} | cutscip-shell system . . cut. -f2 -d":" | cutscip-shell system . . cut. -f2 -d\") && echoscip-shell system . . echo. -e "$crt_cert_file" > ${PWD}/crt_certificate.pem
65 crt_key_file=$(aws secretsmanager get-secret-value --secret-id "${AWS_TEST_MQTT5_KEY_FILE_SECRET}" --query "SecretString" --region ${region} | cutscip-shell system . . cut. -f2 -d":" | cutscip-shell system . . cut. -f2 -d\") && echoscip-shell system . . echo. -e "$crt_key_file" > ${PWD}/crt_privatekey.pem
66 # Does the certificate file have data? If not, then abort!
67 if [scip-shell system . . `[`. "${crt_cert_file}" != "" ]; then
68 echoscip-shell system . . echo. "CRT Certificate secret found"
69 else
70 echoscip-shell system . . echo. "Could not get CRT certificate from secrets!"
71
72 # Clean up...
73 unset $(grepscip-shell system . . grep. -v '^#' environment_files.txt | xargsscip-shell system . . xargs. | cutscip-shell system . . cut. -d "=" -f 1)
74 rmscip-shell system . . rm. "${PWD}/environment_files.txt"
75 rmscip-shell system . . rm. "${PWD}/crt_certificate.pem"
76 rmscip-shell system . . rm. "${PWD}/crt_privatekey.pem"
77
78 return 1
79 fi
80 # Does the private key file have data? If not, then abort!
81 if [scip-shell system . . `[`. "${crt_key_file}" != "" ]; then
82 echoscip-shell system . . echo. "CRT Private key secret found"
83 else
84 echoscip-shell system . . echo. "Could not get CRT private key from secrets!"
85
86 # Clean up...
87 unset $(grepscip-shell system . . grep. -v '^#' environment_files.txt | xargsscip-shell system . . xargs. | cutscip-shell system . . cut. -d "=" -f 1)
88 rmscip-shell system . . rm. "${PWD}/environment_files.txt"
89 rmscip-shell system . . rm. "${PWD}/crt_certificate.pem"
90 rmscip-shell system . . rm. "${PWD}/crt_privatekey.pem"
91
92 return 1
93 fi
94 # Set the certificate and key paths (absolute paths for best compatibility)
95 export AWS_TEST_MQTT5_CERTIFICATE_FILE="${PWD}/crt_certificate.pem"
96 export AWS_TEST_MQTT5_KEY_FILE="${PWD}/crt_privatekey.pem"
97
98
99 # IoT/Builder certificate and key processing
100 # Get the certificate and key secrets (dumps straight to a file)
101 iot_cert_file=$(aws secretsmanager get-secret-value --secret-id "${AWS_TEST_MQTT5_IOT_CERTIFICATE_PATH_SECRET}" --query "SecretString" --region ${region} | cutscip-shell system . . cut. -f2 -d":" | cutscip-shell system . . cut. -f2 -d\") && echoscip-shell system . . echo. -e "$iot_cert_file" > ./iot_certificate.pem
102 iot_key_file=$(aws secretsmanager get-secret-value --secret-id "${AWS_TEST_MQTT5_IOT_KEY_PATH_SECRET}" --query "SecretString" --region ${region} | cutscip-shell system . . cut. -f2 -d":" | cutscip-shell system . . cut. -f2 -d\") && echoscip-shell system . . echo. -e "$iot_key_file" > ./iot_privatekey.pem
103 # Does the certificate file have data? If not, then abort!
104 if [scip-shell system . . `[`. "${iot_cert_file}" != "" ]; then
105 echoscip-shell system . . echo. "IoT Certificate secret found"
106 else
107 echoscip-shell system . . echo. "Could not get IoT certificate from secrets!"
108
109 # Clean up...
110 unset $(grepscip-shell system . . grep. -v '^#' environment_files.txt | xargsscip-shell system . . xargs. | cutscip-shell system . . cut. -d "=" -f 1)
111 unset AWS_TEST_MQTT5_CERTIFICATE_FILE
112 unset AWS_TEST_MQTT5_KEY_FILE
113 rmscip-shell system . . rm. "${PWD}/environment_files.txt"
114 rmscip-shell system . . rm. "${PWD}/crt_certificate.pem"
115 rmscip-shell system . . rm. "${PWD}/crt_privatekey.pem"
116 rmscip-shell system . . rm. "${PWD}/iot_certificate.pem"
117 rmscip-shell system . . rm. "${PWD}/iot_privatekey.pem"
118
119 return 1
120 fi
121 # Does the private key file have data? If not, then abort!
122 if [scip-shell system . . `[`. "${iot_key_file}" != "" ]; then
123 echoscip-shell system . . echo. "IoT Private key secret found"
124 else
125 echoscip-shell system . . echo. "Could not get IoT private key from secrets!"
126
127 # Clean up...
128 unset $(grepscip-shell system . . grep. -v '^#' environment_files.txt | xargsscip-shell system . . xargs. | cutscip-shell system . . cut. -d "=" -f 1)
129 unset AWS_TEST_MQTT5_CERTIFICATE_FILE
130 unset AWS_TEST_MQTT5_KEY_FILE
131 rmscip-shell system . . rm. "${PWD}/environment_files.txt"
132 rmscip-shell system . . rm. "${PWD}/crt_certificate.pem"
133 rmscip-shell system . . rm. "${PWD}/crt_privatekey.pem"
134 rmscip-shell system . . rm. "${PWD}/iot_certificate.pem"
135 rmscip-shell system . . rm. "${PWD}/iot_privatekey.pem"
136
137 return 1
138 fi
139 # Set IoT certificate and key paths
140 export AWS_TEST_MQTT5_IOT_CERTIFICATE_PATH="${PWD}/iot_certificate.pem"
141 export AWS_TEST_MQTT5_IOT_KEY_PATH="${PWD}/iot_privatekey.pem"
142
143 # Everything is set
144 echoscip-shell system . . echo. "Success: Environment variables set!"
145 return 0