Skip to content

Commit 70ff58e

Browse files
add login prompt for azure authentication
1 parent de0f11a commit 70ff58e

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

content-gen/azure.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@ hooks:
7474
7575
# Assign Cosmos DB role to current user
7676
Write-Host "Assigning Cosmos DB Data Contributor role..."
77-
$signedUserId = az ad signed-in-user show --query id -o tsv
77+
78+
# Check if user is logged in, if not prompt for login
79+
$signedUserId = az ad signed-in-user show --query id -o tsv 2>$null
80+
if (-not $signedUserId) {
81+
Write-Host "Not logged in to Azure. Please authenticate..." -ForegroundColor Yellow
82+
az login --use-device-code
83+
$signedUserId = az ad signed-in-user show --query id -o tsv
84+
}
85+
7886
az cosmosdb sql role assignment create --resource-group $env:RESOURCE_GROUP_NAME --account-name $env:COSMOSDB_ACCOUNT_NAME --role-definition-id "00000000-0000-0000-0000-000000000002" --principal-id $signedUserId --scope "/" 2>$null
7987
if ($LASTEXITCODE -eq 0) {
8088
Write-Host " Cosmos DB role assigned successfully" -ForegroundColor Green
@@ -143,7 +151,15 @@ hooks:
143151
144152
# Assign Cosmos DB role to current user
145153
echo "Assigning Cosmos DB Data Contributor role..."
146-
signed_user_id=$(az ad signed-in-user show --query id -o tsv)
154+
155+
# Check if user is logged in, if not prompt for login
156+
signed_user_id=$(az ad signed-in-user show --query id -o tsv 2>/dev/null)
157+
if [ -z "$signed_user_id" ]; then
158+
echo "Not logged in to Azure. Please authenticate..."
159+
az login --use-device-code
160+
signed_user_id=$(az ad signed-in-user show --query id -o tsv)
161+
fi
162+
147163
az cosmosdb sql role assignment create \
148164
--resource-group "$RESOURCE_GROUP_NAME" \
149165
--account-name "$COSMOSDB_ACCOUNT_NAME" \

0 commit comments

Comments
 (0)