Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RECUR-186] Deploy versioned API specs #137

Merged
merged 9 commits into from
Jul 25, 2024
1 change: 1 addition & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ self-hosted-runner:
- boley
- Windows
- self-hosted
- azure
10 changes: 3 additions & 7 deletions .github/workflows/aks-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ on:
required: false
type: string
description: "IPs to include in the application whitelist"
default: "0.0.0.0/0"
default: ${{ vars.KUBERNETES_INGRESS_WHITELIST }}
adminIngressWhitelist:
required: false
type: string
Expand Down Expand Up @@ -153,13 +153,9 @@ jobs:
$domainName = ($ingress.Split('.') | Select-Object -Last 2) -join '.'
$environmentIngress = "${{ inputs.environmentIngress }}" -replace '"', '' -replace "'", ""
$hostName = $ingress -replace $domainName, '' -replace "\.$", ""
$ingressWhitelist = $appConfig.ingress.annotations."nginx.ingress.kubernetes.io/whitelist-source-range" ?? "${{ inputs.ingressWhitelist }}"
$ingressWhitelist = "${{ inputs.ingressWhitelist }}" ?? $appConfig.ingress.annotations."nginx.ingress.kubernetes.io/whitelist-source-range" ?? '0.0.0.0/0'
if ($appConfig.adminingress) {
$adminIngressWhitelist = $appConfig.adminingress.annotations."nginx.ingress.kubernetes.io/whitelist-source-range" ?? "${{ inputs.adminIngressWhitelist }}"
if (![bool]($adminIngressWhitelist -match "^\d{1,3}(\.\d{1,3}){3}(\/\d{1,2})?(,\d{1,3}(\.\d{1,3}){3}(\/\d{1,2})?)*$")) {
Write-Output "Invalid value set for 'adminingress.annotations.nginx.ingress.kubernetes.io/whitelist-source-range'. Defaulting to ${{ inputs.adminIngressWhitelist }} Value: $adminIngressWhitelist"
$adminIngressWhitelist = "${{ inputs.adminIngressWhitelist }}"
}
$adminIngressWhitelist = "${{ inputs.adminIngressWhitelist }}" ?? $appConfig.adminingress.annotations."nginx.ingress.kubernetes.io/whitelist-source-range"
}
else {
Write-Output "adminingress values not defined. Skipping setting adminIngressWhitelist"
Expand Down
57 changes: 43 additions & 14 deletions .github/workflows/update-azureapimanagement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ on:
jobs:
update-api-management:
name: Update API Management Service
runs-on: ubuntu-latest
runs-on: azure
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -111,20 +111,49 @@ jobs:
# Create a context object for API management operations
$Context = New-AzApiManagementContext -ResourceGroupName $ResourceGroup -ServiceName $ServiceName
# Construct the Swagger URL for the default API specification
$SwaggerURL = "https://$serviceFqdn${{ inputs.apiSpecificationPath }}"
Write-Output "Default API Swagger URL: $SwaggerURL"
# Retrieve the API Version Set
$apiVersionSet = Get-AzApiManagementApiVersionSet -Context $Context | Where-Object { $_.DisplayName -eq $ApiId }
if (-not $apiVersionSet) { # Corrected variable name here
$apiVersionSet = New-AzApiManagementApiVersionSet -Context $Context -Name $ApiId -Scheme Segment -Description "$ApiId API"
}
# Import the API using the Swagger URL
Import-AzApiManagementApi -Context $Context -SpecificationUrl $SwaggerURL -SpecificationFormat OpenApi -Path $ApiId -ApiId "$ApiId"
# Update API versions
1..3 | ForEach-Object {
$version = $_
# Retrieve the imported API object
$Api = Get-AzApiManagementApi -Context $Context -ApiId $ApiId
# Check if the versioned API exists
$apiDirectory = Get-ChildItem -Directory -Recurse -Filter "V${version}" -ErrorAction SilentlyContinue | Select-Object -First 1
if ($apiDirectory -and (Test-Path -Path $apiDirectory.FullName)) {
# Construct the Swagger URL for each version
$SwaggerURL = "https://$serviceFqdn/swagger/v$version/swagger.json"
Write-Output $SwaggerURL
# Update the API object with the service URL and subscription requirement
$Api.ServiceURL = $ServiceURL
$Api.SubscriptionRequired = $ApiSubscriptionRequired
# Generate a unique API ID for each version
$versionedApiId = "$ApiId-v$version"
# Update default API version
Set-AzApiManagementApi -InputObject $Api
Add-AzApiManagementApiToProduct -Context $Context -ApiId $ApiId -ProductId $ApiProductId
# Pull down Swagger JSON
$SwaggerJSON = (Invoke-WebRequest -Uri $SwaggerURL).Content
# Remove path prefix from Swagger JSON
$SwaggerJSON = $SwaggerJSON -replace "/v${version}", ""
# Save Swagger JSON to file
$SwaggerJSONFile = "swagger.json"
$SwaggerJSON | Out-File -FilePath $SwaggerJSONFile
# # Import the versioned API
Import-AzApiManagementApi -Context $Context -SpecificationPath $SwaggerJSONFile -SpecificationFormat OpenApi -Path $ApiId -ApiId "$versionedApiId" -ApiVersion "v$version" -ApiVersionSetId $ApiVersionSet.Id
# Retrieve and update the API object
$Api = Get-AzApiManagementApi -Context $Context -ApiId "$versionedApiId"
$Api.ServiceURL = "$ServiceURL/v${version}"
$Api.SubscriptionRequired = $ApiSubscriptionRequired
# Associate the versioned API with a product
Set-AzApiManagementApi -InputObject $Api
Add-AzApiManagementApiToProduct -Context $Context -ApiId "$versionedApiId" -ProductId $ApiProductId
}
else {
Write-Output "Version V$version does not exist in this repository."
}
}
Loading