From ae307be82232963ba11a2bbf9a8593dfa220f812 Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Thu, 11 Jul 2024 22:35:53 +0900 Subject: [PATCH] Update API import scripts (#41) --- infra/core/gateway/apicenter-api.bicep | 2 +- infra/core/gateway/apicenter-environment.bicep | 2 +- infra/core/gateway/apicenter-metadata.bicep | 4 ++-- infra/core/integration/eventgrid-topic.bicep | 2 +- infra/hooks/import_api_definitions.ps1 | 16 ++++++++++------ infra/hooks/import_api_definitions.sh | 16 ++++++++++------ 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/infra/core/gateway/apicenter-api.bicep b/infra/core/gateway/apicenter-api.bicep index 5841290..45df113 100644 --- a/infra/core/gateway/apicenter-api.bicep +++ b/infra/core/gateway/apicenter-api.bicep @@ -33,7 +33,7 @@ param apiCenterApis array = [ ] // Create an API Center service -resource apic 'Microsoft.ApiCenter/services@2024-03-01' existing = { +resource apic 'Microsoft.ApiCenter/services@2024-03-15-preview' existing = { name: apiCenterName } diff --git a/infra/core/gateway/apicenter-environment.bicep b/infra/core/gateway/apicenter-environment.bicep index cfe9d63..560f280 100644 --- a/infra/core/gateway/apicenter-environment.bicep +++ b/infra/core/gateway/apicenter-environment.bicep @@ -29,7 +29,7 @@ param apiCenterEnvironmentKind string param apiCenterEnvironmentServerType string // Create an API Center service -resource apic 'Microsoft.ApiCenter/services@2024-03-01' existing = { +resource apic 'Microsoft.ApiCenter/services@2024-03-15-preview' existing = { name: apiCenterName } diff --git a/infra/core/gateway/apicenter-metadata.bicep b/infra/core/gateway/apicenter-metadata.bicep index d34a6b9..0cedaba 100644 --- a/infra/core/gateway/apicenter-metadata.bicep +++ b/infra/core/gateway/apicenter-metadata.bicep @@ -9,11 +9,11 @@ param apiCenterMetadataSchemaAssignedTo array param apiCenterMetadataSchema string // Create an API center service -resource apiCenter 'Microsoft.ApiCenter/services@2024-03-01' existing = { +resource apiCenter 'Microsoft.ApiCenter/services@2024-03-15-preview' existing = { name: apiCenterName } -resource apiCenterMetadata 'Microsoft.ApiCenter/services/metadataSchemas@2024-03-01' = { +resource apiCenterMetadata 'Microsoft.ApiCenter/services/metadataSchemas@2024-03-15-preview' = { name: apiCenterMetadataSchemaName parent: apiCenter properties: { diff --git a/infra/core/integration/eventgrid-topic.bicep b/infra/core/integration/eventgrid-topic.bicep index 6bf2676..a9b98b1 100644 --- a/infra/core/integration/eventgrid-topic.bicep +++ b/infra/core/integration/eventgrid-topic.bicep @@ -7,7 +7,7 @@ param apiCenterName string param eventGridTopicName string -resource apiCenter 'Microsoft.ApiCenter/services@2024-03-01' existing = { +resource apiCenter 'Microsoft.ApiCenter/services@2024-03-15-preview' existing = { name: apiCenterName } diff --git a/infra/hooks/import_api_definitions.ps1 b/infra/hooks/import_api_definitions.ps1 index 00bc5fd..9dcc763 100644 --- a/infra/hooks/import_api_definitions.ps1 +++ b/infra/hooks/import_api_definitions.ps1 @@ -34,13 +34,13 @@ $DEFINITIONs = @( ) # Get the list of APIs registered in the API Center -$API_IDs = az apic api list -g $RESOURCE_GROUP -s $APIC_NAME --query "[].name" | ConvertFrom-Json +$API_IDs = az apic api list -g $RESOURCE_GROUP -n $APIC_NAME --query "[].name" | ConvertFrom-Json # Iterate over the APIs and import the API definitions $API_IDs | ForEach-Object { $API_ID = $_ - $VERSION_ID = az apic api version list -g $RESOURCE_GROUP -s $APIC_NAME --api-id $API_ID --query "[].name" -o tsv - $DEFINITION_ID = az apic api definition list -g $RESOURCE_GROUP -s $APIC_NAME --api-id $API_ID --version-id $VERSION_ID --query "[].name" -o tsv + $VERSION_ID = az apic api version list -g $RESOURCE_GROUP -n $APIC_NAME --api-id $API_ID --query "[].name" -o tsv + $DEFINITION_ID = az apic api definition list -g $RESOURCE_GROUP -n $APIC_NAME --api-id $API_ID --version-id $VERSION_ID --query "[].name" -o tsv $DEFINITION = $DEFINITIONs | Where-Object { $_.id -eq $DEFINITION_ID } $SPECIFICATION = $DEFINITION.specification | ConvertTo-Json -Depth 100 -Compress | ConvertTo-Json @@ -48,7 +48,7 @@ $API_IDs | ForEach-Object { az apic api definition import-specification ` -g $RESOURCE_GROUP ` - -s $APIC_NAME ` + -n $APIC_NAME ` --api-id $API_ID ` --version-id $VERSION_ID ` --definition-id $DEFINITION_ID ` @@ -59,11 +59,15 @@ $API_IDs | ForEach-Object { # Get the list of APIs registered in the API Management $APIM_NAME = az resource list --namespace "Microsoft.ApiManagement" --resource-type "service" -g $RESOURCE_GROUP --query "[].name" -o tsv -$API_IDs = az apim api list -g $RESOURCE_GROUP -n $APIM_NAME --query "[].id" | ConvertFrom-Json + +# # Import APIs from API Management to API Center +# az apic import-from-apim -g $RESOURCE_GROUP -n $APIC_NAME --apim-name $APIM_NAME --apim-apis * + +$API_IDs = az apim api list -g $RESOURCE_GROUP -n $APIM_NAME --query "[].name" | ConvertFrom-Json # Iterate over the APIs and import the APIs from API Management to API Center $API_IDs | ForEach-Object { $API_ID = $_ - az apic service import-from-apim -g $RESOURCE_GROUP -s $APIC_NAME --source-resource-ids $API_ID + az apic import-from-apim -g $RESOURCE_GROUP -n $APIC_NAME --apim-name $APIM_NAME --apim-apis $API_ID } diff --git a/infra/hooks/import_api_definitions.sh b/infra/hooks/import_api_definitions.sh index b76e03c..b4811a0 100755 --- a/infra/hooks/import_api_definitions.sh +++ b/infra/hooks/import_api_definitions.sh @@ -26,13 +26,13 @@ DEFINITIONs=( ) # Get the list of APIs registered in the API Center -API_IDs=$(az apic api list -g $RESOURCE_GROUP -s $APIC_NAME --query "[].name" -o json | jq -r '.[]') +API_IDs=$(az apic api list -g $RESOURCE_GROUP -n $APIC_NAME --query "[].name" -o json | jq -r '.[]') # Iterate over the APIs and import the API definitions for API_ID in $API_IDs do - VERSION_ID=$(az apic api version list -g $RESOURCE_GROUP -s $APIC_NAME --api-id $API_ID --query "[].name" -o tsv) - DEFINITION_ID=$(az apic api definition list -g $RESOURCE_GROUP -s $APIC_NAME --api-id $API_ID --version-id $VERSION_ID --query "[].name" -o tsv) + VERSION_ID=$(az apic api version list -g $RESOURCE_GROUP -n $APIC_NAME --api-id $API_ID --query "[].name" -o tsv) + DEFINITION_ID=$(az apic api definition list -g $RESOURCE_GROUP -n $APIC_NAME --api-id $API_ID --version-id $VERSION_ID --query "[].name" -o tsv) for DEFINITION in "${DEFINITIONs[@]}" do @@ -47,7 +47,7 @@ do az apic api definition import-specification \ -g $RESOURCE_GROUP \ - -s $APIC_NAME \ + -n $APIC_NAME \ --api-id $API_ID \ --version-id $VERSION_ID \ --definition-id $DEFINITION_ID \ @@ -58,10 +58,14 @@ done # Get the list of APIs registered in the API Management APIM_NAME=$(az resource list --namespace "Microsoft.ApiManagement" --resource-type "service" -g $RESOURCE_GROUP --query "[].name" -o tsv) -API_IDs=$(az apim api list -g $RESOURCE_GROUP -n $APIM_NAME --query "[].id" | jq -r '.[]') + +# # Import APIs from API Management to API Center +# az apic import-from-apim -g $RESOURCE_GROUP -n $APIC_NAME --apim-name $APIM_NAME --apim-apis * + +API_IDs=$(az apim api list -g $RESOURCE_GROUP -n $APIM_NAME --query "[].name" | jq -r '.[]') # Iterate over the APIs and import the APIs from API Management to API Center for API_ID in $API_IDs do - az apic service import-from-apim -g $RESOURCE_GROUP -s $APIC_NAME --source-resource-ids $API_ID + az apic import-from-apim -g $RESOURCE_GROUP -n $APIC_NAME --apim-name $APIM_NAME --apim-apis $API_ID done