Skip to content

Commit

Permalink
Update API import scripts (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo authored Jul 11, 2024
1 parent ceb4028 commit ae307be
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion infra/core/gateway/apicenter-api.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion infra/core/gateway/apicenter-environment.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions infra/core/gateway/apicenter-metadata.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion infra/core/integration/eventgrid-topic.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
16 changes: 10 additions & 6 deletions infra/hooks/import_api_definitions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ $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
$VALUE = $DEFINITION.value

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 `
Expand All @@ -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
}
16 changes: 10 additions & 6 deletions infra/hooks/import_api_definitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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

0 comments on commit ae307be

Please sign in to comment.