diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml index 5bee8471..5ec1ce0f 100644 --- a/.github/actionlint.yaml +++ b/.github/actionlint.yaml @@ -4,3 +4,4 @@ self-hosted-runner: - boley - Windows - self-hosted + - azure diff --git a/.github/workflows/aks-deploy.yaml b/.github/workflows/aks-deploy.yaml index 396d9953..15691e02 100644 --- a/.github/workflows/aks-deploy.yaml +++ b/.github/workflows/aks-deploy.yaml @@ -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 @@ -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" diff --git a/.github/workflows/update-azureapimanagement.yaml b/.github/workflows/update-azureapimanagement.yaml index be3a3a94..910959f1 100644 --- a/.github/workflows/update-azureapimanagement.yaml +++ b/.github/workflows/update-azureapimanagement.yaml @@ -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 @@ -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." + } + } \ No newline at end of file