forked from bradygaster/COVIDScreeningApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-api-to-apim.ps1
33 lines (26 loc) · 1.33 KB
/
import-api-to-apim.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Azure-specific variables
Set-Variable -Name ResourceGroupName "COVIDScreeningAPI"
Set-Variable -Name ApimInstance "screening-app-apis"
Set-Variable -Name ServiceUrl "https://covid-screening-api.azurewebsites.net"
# Variables
Set-Variable -Name SwaggerFilePath "./src/COVIDScreeningApi/bin/Debug/netcoreapp3.1/swagger.json"
Set-Variable -Name ApiId "COVIDScreeningApi"
Set-Variable -Name ApiVersion "v1"
Set-Variable -Name AzureSubscriptionId ""
# select the subscription
Set-AzContext -SubscriptionId $AzureSubscriptionId
# import the api
Write-Output "Setting API Management Context"
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ApimInstance
# remove the old api
Write-Output "Removing the old API"
Remove-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId
# import the new api
Write-Output "Importing Swagger into a new API"
Import-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId -ServiceUrl $ServiceUrl -SpecificationFormat "Swagger" -SpecificationPath $SwaggerFilePath -Path $ApiVersion
# get the api
$api = Get-AzApiManagementApi -Context $ApiMgmtContext -ApiId $ApiId
# disable the subscription requirement
Write-Output "Disabling the subscription header requirement"
$api.SubscriptionRequired = $false
Set-AzApiManagementApi -InputObject $api