Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli/azd/pkg/azapi/azure_resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
//nolint:lll
AzureResourceTypeMachineLearningEndpoint AzureResourceType = "Microsoft.MachineLearningServices/workspaces/onlineEndpoints"
AzureResourceTypeCognitiveServiceAccountDeployment AzureResourceType = "Microsoft.CognitiveServices/accounts/deployments"
AzureResourceTypeCognitiveServiceAccountProject AzureResourceType = "Microsoft.CognitiveServices/accounts/projects"
)

// GetResourceTypeDisplayName retrieves the display name for the given resource type.
Expand Down Expand Up @@ -123,6 +124,8 @@ func GetResourceTypeDisplayName(resourceType AzureResourceType) string {
return "Azure AI Services"
case AzureResourceTypeCognitiveServiceAccountDeployment:
return "Azure AI Services Model Deployment"
case AzureResourceTypeCognitiveServiceAccountProject:
return "Foundry project"
case AzureResourceTypeSearchService:
return "Search service"
case AzureResourceTypeVideoIndexer:
Expand Down
12 changes: 11 additions & 1 deletion cli/azd/pkg/infra/azure_resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func (rm *AzureResourceManager) GetResourceTypeDisplayName(
} else {
return resourceTypeDisplayName, nil
}
} else if resourceType == azapi.AzureResourceTypeCognitiveServiceAccount {
} else if resourceType == azapi.AzureResourceTypeCognitiveServiceAccount ||
resourceType == azapi.AzureResourceTypeCognitiveServiceAccountProject {
resourceTypeDisplayName, err := rm.getCognitiveServiceResourceTypeDisplayName(ctx, subscriptionId, resourceId)

if err != nil {
Expand Down Expand Up @@ -277,6 +278,11 @@ func (rm *AzureResourceManager) getCognitiveServiceResourceTypeDisplayName(
subscriptionId string,
resourceId string,
) (string, error) {
// Check if this is a Foundry project resource (child resource)
if strings.Contains(resourceId, "/projects/") {
return "Foundry project", nil
}

resource, err := rm.resourceService.GetResource(ctx, subscriptionId, resourceId, cognitiveServiceApiVersion)

if err != nil {
Expand All @@ -287,6 +293,10 @@ func (rm *AzureResourceManager) getCognitiveServiceResourceTypeDisplayName(
return "Azure OpenAI", nil
} else if strings.Contains(resource.Kind, "FormRecognizer") {
return "Document Intelligence", nil
} else if strings.Contains(resource.Kind, "AIHub") {
return "Foundry", nil
} else if resource.Kind == "AIServices" {
return "Foundry", nil
} else {
return "Azure AI Services", nil
}
Expand Down
108 changes: 108 additions & 0 deletions cli/azd/pkg/infra/azure_resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,114 @@ func TestFindResourceGroupForEnvironment(t *testing.T) {
}
}

func TestGetResourceTypeDisplayNameForCognitiveServices(t *testing.T) {
const SUBSCRIPTION_ID = "273f1e6b-6c19-4c9e-8b67-5fbe78b14063"

tests := []struct {
name string
resourceId string
kind string
expectedName string
}{
{
name: "Azure OpenAI",
resourceId: fmt.Sprintf(
"/subscriptions/%s/resourceGroups/test-rg/providers/Microsoft.CognitiveServices/accounts/test-openai",
SUBSCRIPTION_ID,
),
kind: "OpenAI",
expectedName: "Azure OpenAI",
},
{
name: "Document Intelligence (FormRecognizer)",
resourceId: fmt.Sprintf(
"/subscriptions/%s/resourceGroups/test-rg/providers/"+
"Microsoft.CognitiveServices/accounts/test-formrecognizer",
SUBSCRIPTION_ID,
),
kind: "FormRecognizer",
expectedName: "Document Intelligence",
},
{
name: "Foundry (AIServices)",
resourceId: fmt.Sprintf(
"/subscriptions/%s/resourceGroups/test-rg/providers/Microsoft.CognitiveServices/accounts/test-foundry",
SUBSCRIPTION_ID,
),
kind: "AIServices",
expectedName: "Foundry",
},
{
name: "Foundry project",
resourceId: fmt.Sprintf(
"/subscriptions/%s/resourceGroups/test-rg/providers/"+
"Microsoft.CognitiveServices/accounts/test-foundry/projects/test-project",
SUBSCRIPTION_ID,
),
kind: "AIServices",
expectedName: "Foundry project",
},
{
name: "Azure AI Services (CognitiveServices)",
resourceId: fmt.Sprintf(
"/subscriptions/%s/resourceGroups/test-rg/providers/Microsoft.CognitiveServices/accounts/test-cogservices",
SUBSCRIPTION_ID,
),
kind: "CognitiveServices",
expectedName: "Azure AI Services",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockContext := mocks.NewMockContext(context.Background())
resourceService := azapi.NewResourceService(
mockContext.SubscriptionCredentialProvider,
mockContext.ArmClientOptions,
)
deploymentService := mockazapi.NewStandardDeploymentsFromMockContext(mockContext)

mockContext.HttpClient.When(func(request *http.Request) bool {
return request.Method == http.MethodGet &&
strings.Contains(request.URL.Path, "/Microsoft.CognitiveServices/accounts/")
}).RespondFn(func(request *http.Request) (*http.Response, error) {
response := map[string]interface{}{
"id": tt.resourceId,
"name": "test-resource",
"type": "Microsoft.CognitiveServices/accounts",
"location": "eastus2",
"kind": tt.kind,
}

body, err := json.Marshal(response)
if err != nil {
return nil, err
}

return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(body)),
Request: &http.Request{
Method: http.MethodGet,
URL: request.URL,
},
}, nil
})

arm := NewAzureResourceManager(resourceService, deploymentService)
displayName, err := arm.GetResourceTypeDisplayName(
*mockContext.Context,
SUBSCRIPTION_ID,
tt.resourceId,
azapi.AzureResourceTypeCognitiveServiceAccount,
)

require.NoError(t, err)
require.Equal(t, tt.expectedName, displayName)
})
}
}

func TestGetResourceTypeDisplayNameForRedisEnterprise(t *testing.T) {
const SUBSCRIPTION_ID = "273f1e6b-6c19-4c9e-8b67-5fbe78b14063"

Expand Down
Loading