Skip to content

Commit 93ef931

Browse files
Enhance Azure Maps sample notebook and Bicep templates with improved API testing and role assignments
1 parent b88cacf commit 93ef931

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

samples/azure-maps/create.ipynb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,25 @@
118118
"outputs": [],
119119
"source": [
120120
"import utils\n",
121+
"from apimtesting import ApimTesting\n",
121122
"from apimrequests import ApimRequests\n",
123+
"import json\n",
122124
"\n",
125+
"tests = ApimTesting(\"AuthX-Pro Sample Tests\")\n",
123126
"reqs = ApimRequests(apim_gateway_url)\n",
124127
"\n",
125128
"# 1) Issue a direct request to API Management\n",
126-
"reqs.singleGet('/', msg = 'Calling Hello World (Root) API. Expect 200.')\n",
129+
"output = reqs.singleGet('/', msg = 'Calling Hello World (Root) API. Expect 200.')\n",
130+
"tests.verify(output, 'Hello World from API Management!')\n",
127131
"\n",
128132
"# 2) Issue requests to API Management with Azure Maps APIs\n",
129-
"reqs.singleGet('/map/default/geocode?query=15127%20NE%2024th%20Street%20Redmond%20WA', msg = 'Calling Default Route API with SAS Token Auth. Expect 200.')\n",
130-
"reqs.singleGet('/map/geocode?query=15127%20NE%2024th%20Street%20Redmond%20WA', msg = 'Calling Geocode v2 API with AAD Auth. Expect 200.')\n",
131-
"reqs.singlePostAsync('/map/geocode/batch/async', data={\n",
133+
"output = reqs.singleGet('/map/default/geocode?query=15127%20NE%2024th%20Street%20Redmond%20WA', msg = 'Calling Default Route API with SAS Token Auth. Expect 200.')\n",
134+
"tests.verify('address' in output, True)\n",
135+
"\n",
136+
"output = reqs.singleGet('/map/geocode?query=15127%20NE%2024th%20Street%20Redmond%20WA', msg = 'Calling Geocode v2 API with AAD Auth. Expect 200.')\n",
137+
"tests.verify('address' in output, True)\n",
138+
"\n",
139+
"output = reqs.singlePostAsync('/map/geocode/batch/async', data={\n",
132140
" \"batchItems\": [\n",
133141
" {\"query\": \"?query=400 Broad St, Seattle, WA 98109&limit=3\"},\n",
134142
" {\"query\": \"?query=One, Microsoft Way, Redmond, WA 98052&limit=3\"},\n",
@@ -137,6 +145,10 @@
137145
" {\"query\": \"?query=Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France&limit=1\"}\n",
138146
" ]\n",
139147
"}, msg = 'Calling Async Geocode Batch v1 API with Share Key Auth. Expect initial 202, then a 200 on the polling response', timeout=120, poll_interval=3)\n",
148+
"# confirm the response contains \"summary\": { \"successfulRequests\": 5, \"totalRequests\": 5}\n",
149+
"tests.verify('summary' in output and 'successfulRequests' in output and json.loads(output)['summary']['successfulRequests'] == 5, True)\n",
150+
"\n",
151+
"tests.print_summary()\n",
140152
"\n",
141153
"utils.print_ok('All done!')"
142154
]

samples/azure-maps/main.bicep

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@description('Location to be used for resources. Defaults to the resource group location')
66
param location string = resourceGroup().location
77

8-
param mapsLocation string = 'eastus' // Azure Maps is only available in certain regions, adjust as needed
8+
param mapsLocation string = 'eastus' // Azure Maps is only available in certain regions: https://learn.microsoft.com/en-us/azure/azure-maps/creator-geographic-scope#geographic-and-regional-mapping
99

1010
@description('The unique suffix to append. Defaults to a unique string based on subscription and resource group IDs.')
1111
param resourceSuffix string = uniqueString(subscription().id, resourceGroup().id)
@@ -17,6 +17,12 @@ param appInsightsName string = 'appi-${resourceSuffix}'
1717
param userAssignedIdentityName string = 'uami-maps-${resourceSuffix}'
1818
param apis array = []
1919

20+
// ------------------------------
21+
// VARIABLES
22+
// ------------------------------
23+
24+
var azureRoles = loadJsonContent('../../shared/azure-roles.json')
25+
2026
// ------------------
2127
// RESOURCES
2228
// ------------------
@@ -155,35 +161,35 @@ module apisModule '../../shared/bicep/modules/apim/v1/api.bicep' = [for api in a
155161
]
156162
}]
157163

158-
// Grant APIM managed identity access to Azure Maps, here are the RBAC roles you might need: https://learn.microsoft.com/en-us/azure/azure-maps/azure-maps-authentication#picking-a-role-definition
164+
// Grant APIM managed identity Azure Maps Seaarch and Render Data Reader role to Azure Maps
159165
resource mapsDataReaderRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
160-
name: guid(mapsAccount.id, apimService.id, '6be48352-4f82-47c9-ad5e-0acacefdb005')
166+
name: guid(mapsAccount.id, apimService.id, 'Azure Maps Search and Render Data Reader')
161167
scope: mapsAccount
162168
properties: {
163-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '6be48352-4f82-47c9-ad5e-0acacefdb005')
169+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', azureRoles.AzureMapsSearchAndRenderDataReader)
164170
principalId: apimService.identity.principalId
165171
principalType: 'ServicePrincipal'
166172
}
167173
}
168174

169175
// Grant APIM managed identity 'Azure Maps Contributor' role to Azure Maps, this allows the creation of SAS tokens
170176
resource mapsContributorRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
171-
name: guid(mapsAccount.id, apimService.id, 'dba33070-676a-4fb0-87fa-064dc56ff7fb')
177+
name: guid(mapsAccount.id, apimService.id, 'Azure Maps Contributor')
172178
scope: mapsAccount
173179
properties: {
174-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'dba33070-676a-4fb0-87fa-064dc56ff7fb')
180+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', azureRoles.AzureMapsContributor)
175181
principalId: apimService.identity.principalId
176182
principalType: 'ServicePrincipal'
177183
}
178184
}
179185

180186

181-
// Grant user-assigned managed identity Azure Maps Data Reader role
187+
// Grant user-assigned managed identity Azure Maps Search and Render Data Reader role
182188
resource userAssignedIdentityMapsDataReaderRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
183-
name: guid(mapsAccount.id, userAssignedIdentity.id, '6be48352-4f82-47c9-ad5e-0acacefdb005')
189+
name: guid(mapsAccount.id, userAssignedIdentity.id, 'Azure Maps Search and Render Data Reader')
184190
scope: mapsAccount
185191
properties: {
186-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '6be48352-4f82-47c9-ad5e-0acacefdb005')
192+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', azureRoles.AzureMapsSearchAndRenderDataReader)
187193
principalId: userAssignedIdentity.properties.principalId
188194
principalType: 'ServicePrincipal'
189195
}

shared/azure-roles.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"__source": "https://learn.microsoft.com/azure/role-based-access-control/built-in-roles",
33
"StorageBlobDataContributor": "ba92f5b4-2d11-453d-a403-e96b0029c9fe",
4-
"StorageBlobDataReader": "2a2b9908-6ea1-4ae2-8e65-a410df84e7d1"
4+
"StorageBlobDataReader": "2a2b9908-6ea1-4ae2-8e65-a410df84e7d1",
5+
"AzureMapsSearchAndRenderDataReader": "6be48352-4f82-47c9-ad5e-0acacefdb005",
6+
"AzureMapsContributor": "dba33070-676a-4fb0-87fa-064dc56ff7fb"
57
}

0 commit comments

Comments
 (0)