Skip to content

Commit

Permalink
exposing service provider openapi + mock
Browse files Browse the repository at this point in the history
  • Loading branch information
petretiandrea committed Oct 18, 2024
1 parent 8faa806 commit 269855a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/rtp/02_api_service_provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## RTP Service Provider API ##
resource "azurerm_api_management_api_version_set" "rtp_service_provider_api" {
name = "${var.env_short}-rtp-service-provider-api"
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name

display_name = "RTP Service Provider API"
versioning_scheme = "Segment"
}

resource "azurerm_api_management_api" "rtp_service_provider_api" {
name = "${var.env_short}-rtp-service-provider-api"
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name

version_set_id = azurerm_api_management_api_version_set.rtp_service_provider_api.id

revision = "1"
version = "v1"
description = "RTP Service Provider API"
display_name = "RTP Service Provider API"
path = "rtp"
protocols = ["https"]
subscription_required = false

depends_on = [azurerm_api_management_product.rtp]

import {
content_format = "openapi"
content_value = templatefile("./api/pagopa/openapi.yaml", {})
}
}


resource "azurerm_api_management_product_api" "rtp_service_provider_product_api" {
api_management_name = data.azurerm_api_management.this.name
resource_group_name = data.azurerm_api_management.this.resource_group_name

api_name = azurerm_api_management_api.rtp_service_provider_api.name
product_id = azurerm_api_management_product.rtp.product_id
depends_on = [azurerm_api_management_product.rtp, azurerm_api_management_api.rtp_service_provider_api]
}

## Override API Operations Policies ##
resource "azurerm_api_management_api_operation_policy" "rtp_service_provider_create_rtp_policy" {
api_name = azurerm_api_management_api.rtp_service_provider_api.name
api_management_name = azurerm_api_management_api.rtp_service_provider_api.api_management_name
resource_group_name = azurerm_api_management_api.rtp_service_provider_api.resource_group_name
operation_id = "createRtp"

xml_content = templatefile("./api/pagopa/create_rtp_mock_policy.xml", {
base_url : "${local.rtp_base_url}/${azurerm_api_management_api.rtp_service_provider_api.path}/${azurerm_api_management_api.rtp_service_provider_api.version}/rtps"
})
}
2 changes: 2 additions & 0 deletions src/rtp/99_locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ locals {

apim_name = "${local.product}-apim"
apim_rg = "${local.product}-api-rg"

rtp_base_url = "https://api-rtp.${var.env}.${var.prefix}.pagopa.it"
}
35 changes: 35 additions & 0 deletions src/rtp/api/pagopa/create_rtp_mock_policy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
IMPORTANT:
- Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.
- To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.
- To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.
- To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.
- To remove a policy, delete the corresponding policy statement from the policy document.
- Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.
- Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.
- Policies are applied in the order of their appearance, from the top down.
- Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope.
-->
<policies>
<inbound>
<set-variable name="uuid" value="@(Guid.NewGuid().ToString())"/>
<return-response>
<set-status code="200" reason="OK" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-header name="Location" exists-action="override">
<value>@("${base_url}" + "/" + context.Variables["uuid"])</value>
</set-header>
</return-response>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>

0 comments on commit 269855a

Please sign in to comment.