Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules/
/lib/
*.dll
/coverage/
.env
.env*
38 changes: 38 additions & 0 deletions scripts/generate-service-principal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

###
# This script generate a service principal using your currently set subscription
# then write out the credentials of your new sp in a file
# that you can export as environment variables
###
set -e

if ! [[ -x "$(command -v jq)" ]]; then
echo "Please install [jq] before continuing -> https://stedolan.github.io/jq/download/. Aborting."
exit 1
fi

SP_NAME=$1

if [[ -z $SP_NAME ]]; then
SP_NAME="FunctionsTestingPrincipal"
echo "You didn't pass in a name for the service principal. We'll use the default: ${SP_NAME}"
echo
fi

SUBSCRIPTION=$(az account show | jq .name)
echo "You're using subscription: ${SUBSCRIPTION}"
echo "--> Creating service principal with name: ${SP_NAME}"
SP_RESPONSE=$(az ad sp create-for-rbac --name "http://${SP_NAME}")

FILE=".env.servicePrincipal"

echo "--> Writing creds to '${FILE}'"
cat <<EOF >${FILE}
export azureSubId=$(az account show | jq .id)
export azureServicePrincipalTenantId=$(echo "${SP_RESPONSE}" | jq .tenant)
export azureServicePrincipalClientId=$(echo "${SP_RESPONSE}" | jq .name)
export azureServicePrincipalPassword=$(echo "${SP_RESPONSE}" | jq .password)
EOF

echo "Run \"source ${FILE}\" to set your Azure account credentials "