You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -174,7 +174,7 @@ function Ensure-CosmosDBRole {
174
174
$roleDefId="00000000-0000-0000-0000-000000000002"
175
175
176
176
# Check if role already assigned
177
-
$existing= az cosmosdb sql role assignment list --resource-group $resourceGroup--account-name $cosmosAccount--query "[?principalId=='$signedUserId'].id"-o tsv 2>$null
177
+
$existing= az cosmosdb sql role assignment list --resource-group $resourceGroup--account-name $cosmosAccount--query "[?principalId=='$signedUserId' && contains(roleDefinitionId, '$roleDefId')].id | [0]"-o tsv 2>$null
178
178
179
179
if ($existing) {
180
180
Write-Success"Cosmos DB role already assigned."
@@ -189,6 +189,53 @@ function Ensure-CosmosDBRole {
189
189
}
190
190
}
191
191
192
+
functionEnsure-StorageRole {
193
+
Write-Info"Checking Storage Blob Data Contributor role..."
194
+
195
+
# Get env vars
196
+
$storageAccount=$null
197
+
$resourceGroup=$null
198
+
if (Test-Path".env") {
199
+
Get-Content".env"|ForEach-Object {
200
+
if ($_-match"^AZURE_BLOB_ACCOUNT_NAME=(.*)$") { $storageAccount=$matches[1].Trim('"').Trim("'") }
201
+
if ($_-match"^RESOURCE_GROUP_NAME=(.*)$") { $resourceGroup=$matches[1].Trim('"').Trim("'") }
202
+
}
203
+
}
204
+
205
+
if (-not$storageAccount-or-not$resourceGroup) {
206
+
Write-Error"AZURE_BLOB_ACCOUNT_NAME or RESOURCE_GROUP_NAME not found in .env"
207
+
exit1
208
+
}
209
+
210
+
$signedUserId= az ad signed-in-user show --query id -o tsv 2>$null
211
+
if (-not$signedUserId) {
212
+
Write-Error"Could not get signed-in user ID."
213
+
exit1
214
+
}
215
+
216
+
# Get storage account resource ID
217
+
$storageResourceId= az storage account show --name $storageAccount--resource-group $resourceGroup--query id -o tsv 2>$null
218
+
if (-not$storageResourceId) {
219
+
Write-Error"Could not get storage account resource ID."
220
+
exit1
221
+
}
222
+
223
+
$roleId="Storage Blob Data Contributor"
224
+
$existing= az role assignment list --assignee $signedUserId--role $roleId--scope $storageResourceId--query "[0].id"-o tsv 2>$null
225
+
226
+
if ($existing) {
227
+
Write-Success"Storage Blob Data Contributor role already assigned."
228
+
} else {
229
+
Write-Info"Assigning Storage Blob Data Contributor role..."
230
+
az role assignment create --assignee $signedUserId--role $roleId--scope $storageResourceId--output none 2>$null
231
+
if ($LASTEXITCODE-ne0) {
232
+
Write-Error"Failed to assign Storage Blob Data Contributor role."
233
+
exit1
234
+
}
235
+
Write-Success"Storage Blob Data Contributor role assigned."
0 commit comments