Skip to content

Commit 5f9b07c

Browse files
committed
role
1 parent ea3e8e7 commit 5f9b07c

2 files changed

Lines changed: 19 additions & 27 deletions

File tree

infra/main.bicep

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,12 @@ resource appService 'Microsoft.Web/sites@2023-12-01' = {
179179
}
180180
}
181181

182-
// Grant App Service access to Azure AI Foundry
183-
resource appServiceAIFoundryRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
184-
name: guid(subscription().id, appService.id, aiFoundryResource.id, 'CognitiveServicesOpenAIUser')
182+
// Grant App Service Azure AI Project Manager role on AI Foundry resource (includes dataActions for Microsoft.CognitiveServices/*)
183+
resource appServiceAIProjectManagerRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
184+
name: guid(subscription().id, appService.id, aiFoundryResource.id, 'Azure AI Project Manager')
185185
scope: aiFoundryResource
186186
properties: {
187-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd') // Cognitive Services OpenAI User
188-
principalId: appService.identity.principalId
189-
principalType: 'ServicePrincipal'
190-
}
191-
}
192-
193-
// Grant App Service Azure AI Developer role (required for Agents)
194-
resource appServiceAIDeveloperRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
195-
name: guid(subscription().id, appService.id, 'AzureAIDeveloper')
196-
properties: {
197-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '64702f94-c441-49e6-a78b-ef80e0188fee') // Azure AI Developer
187+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'eadc314b-1a2d-4efa-be10-5d325db5065e') // Azure AI Project Manager
198188
principalId: appService.identity.principalId
199189
principalType: 'ServicePrincipal'
200190
}

main.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,25 @@
4141
def get_azure_ai_project_endpoint():
4242
"""Get Azure AI Project endpoint from environment variables"""
4343
azure_ai_endpoint = os.getenv('AZURE_AI_PROJECT_ENDPOINT')
44+
azure_ai_project_name = os.getenv('AZURE_AI_PROJECT_NAME')
45+
4446
if not azure_ai_endpoint:
4547
raise ValueError("AZURE_AI_PROJECT_ENDPOINT environment variable is required")
48+
if not azure_ai_project_name:
49+
raise ValueError("AZURE_AI_PROJECT_NAME environment variable is required")
4650

47-
# Azure AI Foundry endpoint should be a direct URL
48-
if azure_ai_endpoint.startswith('https://'):
49-
return azure_ai_endpoint
51+
# Extract the AI Foundry resource name from the endpoint
52+
# Format: https://az-tda-foundry-wgznky2irncfe.cognitiveservices.azure.com/
53+
if azure_ai_endpoint.startswith('https://') and 'cognitiveservices.azure.com' in azure_ai_endpoint:
54+
# Extract resource name from URL
55+
resource_name = azure_ai_endpoint.replace('https://', '').replace('.cognitiveservices.azure.com/', '').replace('.cognitiveservices.azure.com', '')
56+
# Format for Azure AI Agents: https://<resource-name>.services.ai.azure.com/api/projects/<project-name>
57+
agents_endpoint = f"https://{resource_name}.services.ai.azure.com/api/projects/{azure_ai_project_name}"
58+
return agents_endpoint
5059

51-
# Handle legacy Azure ML format if still present
52-
if ';' in azure_ai_endpoint:
53-
# Format: "westus.api.azureml.ms;subscription;resourcegroup;projectname"
54-
parts = azure_ai_endpoint.split(';')
55-
if len(parts) >= 4:
56-
# Extract region from "westus.api.azureml.ms"
57-
region = parts[0].split('.')[0]
58-
project_name = parts[3]
59-
return (f"https://{region}.api.azureml.ms/api/projects/"
60-
f"{project_name}")
60+
# If already in correct format, return as-is
61+
if '/api/projects/' in azure_ai_endpoint:
62+
return azure_ai_endpoint
6163

6264
raise ValueError(f"Invalid AZURE_AI_PROJECT_ENDPOINT format: {azure_ai_endpoint}")
6365

0 commit comments

Comments
 (0)