Last active
February 16, 2023 18:38
-
-
Save ChrisRomp/fa2e70b379afc76eedbc5498f91d701e to your computer and use it in GitHub Desktop.
Azure .env File Generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# requires azure cli client and jq | |
# Get account info from Azure CLI | |
ACCOUNT=$(az account show) | |
# Get tenant name (from user query) | |
TENANT_NAME=$(az ad signed-in-user show --query 'userPrincipalName' | cut -d '@' -f 2 | sed 's/\"//') | |
# Parse tenant ID | |
TENANT_ID=$(echo $ACCOUNT | jq -r .tenantId) | |
# Parse subscription ID | |
SUBSCRIPTION=$(echo $ACCOUNT | jq -r .id) | |
# Get token from Azure CLI | |
AAD_TOKEN=$(az account get-access-token --query accessToken -o tsv) | |
# Folder path | |
WD=${CODESPACE_VSCODE_FOLDER:-${PWD:-.}} | |
# Create new .env file | |
cat <<EOF > .env | |
TENANT_ID=$TENANT_ID | |
TENANT_NAME=$TENANT_NAME | |
SUBSCRIPTION=$SUBSCRIPTION | |
AAD_TOKEN=$AAD_TOKEN | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get token from Azure CLI | |
TOKEN=$(az account get-access-token --query accessToken -o tsv) | |
# Folder path | |
WD=${CODESPACE_VSCODE_FOLDER:-${PWD:-.}} | |
# Update token in .env | |
sed -i "s/^AAD_TOKEN=\S*$/AAD_TOKEN=$TOKEN/gm" $WD/.env |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment