Update setup-azure-conf-test.sh
Add removal of AKV_SPAUTH_SP to generated teardown script.
Fix extraction of `clientId` and `clientSecret` from provided
credentials without line breaks.
@@ -218,8 +218,8 @@ echo "Created Service Principal for cert auth: ${CERT_AUTH_SP_NAME}"
if [[ -n ${CREDENTIALS_PATH} ]]; then
SDK_AUTH_SP_INFO="$(cat ${CREDENTIALS_PATH})"
- SDK_AUTH_SP_APPID="$(echo "${SDK_AUTH_SP_INFO}" | grep 'clientId' | sed -E 's/(.*clientId\"\: \")|\",//g')"
- SDK_AUTH_SP_CLIENT_SECRET="$(echo "${SDK_AUTH_SP_INFO}" | grep 'clientSecret' | sed -E 's/(.*clientSecret\"\: \")|\",//g')"
+ SDK_AUTH_SP_APPID="$(echo "${SDK_AUTH_SP_INFO}" | grep 'clientId' | sed -E 's/(.*clientId\"\: \")|\".*//g')"
+ SDK_AUTH_SP_CLIENT_SECRET="$(echo "${SDK_AUTH_SP_INFO}" | grep 'clientSecret' | sed -E 's/(.*clientSecret\"\: \")|\".*//g')"
if [[ -z ${SDK_AUTH_SP_APPID} || -z ${SDK_AUTH_SP_CLIENT_SECRET} ]]; then
echo "Invalid credentials JSON file. Contents should match output of 'az ad sp create-for-rbac' command."
exit 1
@@ -230,7 +230,7 @@ if [[ -n ${CREDENTIALS_PATH} ]]; then
else
SDK_AUTH_SP_NAME="${PREFIX}-conf-test-runner-sp"
SDK_AUTH_SP_INFO="$(az ad sp create-for-rbac --name "${SDK_AUTH_SP_NAME}" --sdk-auth --skip-assignment --years 1)"
- SDK_AUTH_SP_CLIENT_SECRET="$(echo "${SDK_AUTH_SP_INFO}" | grep 'clientSecret' | sed -E 's/(.*clientSecret\"\: \")|\",//g')"
+ SDK_AUTH_SP_CLIENT_SECRET="$(echo "${SDK_AUTH_SP_INFO}" | grep 'clientSecret' | sed -E 's/(.*clientSecret\"\: \")|\".*//g')"
SDK_AUTH_SP_ID="$(az ad sp list --display-name "${SDK_AUTH_SP_NAME}" --query "[].objectId" --output tsv)"
echo "${SDK_AUTH_SP_INFO}"
echo "Created Service Principal for SDK Auth: ${SDK_AUTH_SP_NAME}"
@@ -374,6 +374,8 @@ echo "Purging key vault ${KEYVAULT_NAME} ..."
az keyvault purge --name "${KEYVAULT_NAME}"
echo "Deleting service principal ${CERT_AUTH_SP_NAME} ..."
az ad sp delete --id "${CERT_AUTH_SP_ID}"
+echo "Deleting service principal ${AKV_SPAUTH_SP_NAME} ..."
+az ad sp delete --id "${AKV_SPAUTH_SP_OBJECTID}"
EOF
# Only remove the test runner Service Principal if it was not pre-existing
