Merge pull request #4133 from echuvyrov/master
Modified Azure service principal creation script to work with newer version of Azure CLI
This commit is contained in:
commit
85eedf47ca
|
@ -11,6 +11,7 @@ azure_subscription_id= # Derived from the account after login
|
|||
azure_tenant_id= # Derived from the account after login
|
||||
location=
|
||||
azure_object_id=
|
||||
azureversion=
|
||||
|
||||
showhelp() {
|
||||
echo "azure-setup"
|
||||
|
@ -65,27 +66,6 @@ requirements() {
|
|||
echo "https://stedolan.github.io/jq/"
|
||||
fi
|
||||
|
||||
# azure-cli 0.10.5 includes a breaking change
|
||||
# warn if using an incompatible azure-cli version
|
||||
# This is just a work around until a more appropriate fix is available
|
||||
supported_version=true
|
||||
IFS='.' read -ra azureversionsemver <<< "$azureversion"
|
||||
if [ ${azureversionsemver[0]} -gt 0 ]; then
|
||||
supported_version=false
|
||||
fi
|
||||
if [ ${azureversionsemver[1]} -gt 10 ]; then
|
||||
supported_version=false
|
||||
fi
|
||||
if [ ${azureversionsemver[2]} -gt 4 ]; then
|
||||
supported_version=false
|
||||
fi
|
||||
|
||||
echo "supported_version is $supported_version"
|
||||
if [ "${supported_version}" = false ]; then
|
||||
echo "Error: azure-cli must be 0.10.4 or older, see http://bit.ly/2etirbM"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $found -lt 2 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
@ -166,10 +146,31 @@ createStorageAccount() {
|
|||
fi
|
||||
}
|
||||
|
||||
createApplication() {
|
||||
echo "==> Creating application"
|
||||
azure_client_id=$(azure ad app create -n $meta_name -i http://$meta_name --home-page http://$meta_name -p $azure_client_secret --json | jq -r .appId)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error creating application: $meta_name @ http://$meta_name"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
createServicePrincipal() {
|
||||
echo "==> Creating service principal"
|
||||
azure_object_id=$(azure ad sp create -n $meta_name --home-page http://$meta_name --identifier-uris http://$meta_name/example -p $azure_client_secret --json | jq -r .objectId)
|
||||
azure_client_id=$(azure ad app show -c $meta_name --json | jq -r .[0].appId)
|
||||
# Azure CLI 0.10.2 introduced a breaking change, where appId must be supplied with the -a switch
|
||||
# prior version accepted appId as the only parameter without a switch
|
||||
newer_syntax=false
|
||||
IFS='.' read -ra azureversionsemver <<< "$azureversion"
|
||||
if [ ${azureversionsemver[0]} -ge 0 ] && [ ${azureversionsemver[1]} -ge 10 ] && [ ${azureversionsemver[2]} -ge 2 ]; then
|
||||
newer_syntax=true
|
||||
fi
|
||||
|
||||
if [ "${newer_syntax}" = true ]; then
|
||||
azure_object_id=$(azure ad sp create -a $azure_client_id --json | jq -r .objectId)
|
||||
else
|
||||
azure_object_id=$(azure ad sp create $azure_client_id --json | jq -r .objectId)
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error creating service principal: $azure_client_id"
|
||||
exit 1
|
||||
|
@ -222,6 +223,8 @@ setup() {
|
|||
sleep 5
|
||||
createStorageAccount
|
||||
sleep 5
|
||||
createApplication
|
||||
sleep 5
|
||||
createServicePrincipal
|
||||
sleep 5
|
||||
createPermissions
|
||||
|
|
Loading…
Reference in New Issue