Skip to content

Commit f4f0f60

Browse files
Add reveal backend flag (#61)
1 parent 804649e commit f4f0f60

File tree

7 files changed

+83
-32
lines changed

7 files changed

+83
-32
lines changed

infrastructure/afd-apim-pe/create.ipynb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
"from apimtypes import *\n",
2222
"\n",
2323
"# 1) User-defined parameters (change these as needed)\n",
24-
"rg_location = 'eastus2'\n",
25-
"index = 1\n",
26-
"apim_sku = APIM_SKU.STANDARDV2\n",
27-
"deployment = INFRASTRUCTURE.AFD_APIM_PE\n",
28-
"use_ACA = True\n",
24+
"rg_location = 'eastus2'\n",
25+
"index = 1\n",
26+
"apim_sku = APIM_SKU.STANDARDV2\n",
27+
"deployment = INFRASTRUCTURE.AFD_APIM_PE\n",
28+
"use_ACA = True\n",
29+
"reveal_backend = True # Set to True to reveal the backend details in the API operations\n",
2930
"\n",
3031
"# 2) Service-defined parameters (please do not change these unless you know what you're doing)\n",
3132
"rg_name = utils.get_infra_rg_name(deployment, index)\n",
@@ -55,10 +56,10 @@
5556
"if use_ACA:\n",
5657
" utils.print_info('ACA APIs will be created.')\n",
5758
"\n",
58-
" backend_polixy_xml = utils.read_policy_xml(BACKEND_XML_POLICY_PATH)\n",
59-
" aca_backend_1_policy_xml = backend_polixy_xml.format(backend_id = 'aca-backend-1')\n",
60-
" aca_backend_2_policy_xml = backend_polixy_xml.format(backend_id = 'aca-backend-2')\n",
61-
" aca_backend_pool_policy_xml = backend_polixy_xml.format(backend_id = 'aca-backend-pool')\n",
59+
" backend_policy_xml = utils.read_policy_xml(BACKEND_XML_POLICY_PATH)\n",
60+
" aca_backend_1_policy_xml = backend_policy_xml.format(backend_id = 'aca-backend-1')\n",
61+
" aca_backend_2_policy_xml = backend_policy_xml.format(backend_id = 'aca-backend-2')\n",
62+
" aca_backend_pool_policy_xml = backend_policy_xml.format(backend_id = 'aca-backend-pool')\n",
6263
"\n",
6364
" # Hello World (ACA Backend 1)\n",
6465
" api_hwaca_1_get = GET_APIOperation('This is a GET for Hello World on ACA Backend 1')\n",
@@ -98,11 +99,11 @@
9899
"\n",
99100
"# 1) Define the Bicep parameters with serialized APIs and networking mode\n",
100101
"bicep_parameters = {\n",
101-
" 'apimSku' : {'value': apim_sku.value},\n",
102-
" 'apis' : {'value': [api.to_dict() for api in apis]},\n",
103-
" 'policyFragments' : {'value': [pf.to_dict() for pf in pfs]},\n",
104-
" 'apimPublicAccess' : {'value': apim_network_mode in [APIMNetworkMode.PUBLIC, APIMNetworkMode.EXTERNAL_VNET]},\n",
105-
" 'useACA' : {'value': use_ACA}\n",
102+
" 'apimSku' : {'value': apim_sku.value},\n",
103+
" 'apis' : {'value': [api.to_dict() for api in apis]},\n",
104+
" 'policyFragments' : {'value': [pf.to_dict() for pf in pfs]},\n",
105+
" 'apimPublicAccess' : {'value': apim_network_mode in [APIMNetworkMode.PUBLIC, APIMNetworkMode.EXTERNAL_VNET]},\n",
106+
" 'useACA' : {'value': use_ACA}\n",
106107
"}\n",
107108
"\n",
108109
"# 2) Run the deployment\n",

infrastructure/afd-apim-pe/main.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ param policyFragments array = []
3232
@description('Set to true to make APIM publicly accessible. If false, APIM will be deployed into a VNet subnet for egress only.')
3333
param apimPublicAccess bool = true
3434

35+
@description('Reveals the backend API information. Defaults to true. *** WARNING: This will expose backend API information to the caller - For learning & testing only! ***')
36+
param revealBackendApiInfo bool = true
37+
3538
// Front Door
3639
param afdEndpointName string = 'afd-${resourceSuffix}'
3740

@@ -170,6 +173,7 @@ module apimModule '../../shared/bicep/modules/apim/v1/apim.bicep' = {
170173
appInsightsId: appInsightsId
171174
apimSubnetResourceId: apimSubnetResourceId
172175
publicAccess: apimPublicAccess
176+
globalPolicyXml: revealBackendApiInfo ? loadTextContent('../../shared/apim-policies/all-apis-reveal-backend.xml') : loadTextContent('../../shared/apim-policies/all-apis.xml')
173177
}
174178
dependsOn: [
175179
vnetModule

infrastructure/apim-aca/create.ipynb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
"from apimtypes import *\n",
2222
"\n",
2323
"# 1) User-defined parameters (change these as needed)\n",
24-
"rg_location = 'eastus2'\n",
25-
"index = 1\n",
26-
"apim_sku = APIM_SKU.BASICV2\n",
27-
"deployment = INFRASTRUCTURE.APIM_ACA\n",
24+
"rg_location = 'eastus2'\n",
25+
"index = 1\n",
26+
"apim_sku = APIM_SKU.BASICV2\n",
27+
"deployment = INFRASTRUCTURE.APIM_ACA\n",
28+
"reveal_backend = True # Set to True to reveal the backend details in the API operations\n",
2829
"\n",
2930
"# 2) Service-defined parameters (please do not change these)\n",
3031
"rg_name = utils.get_infra_rg_name(deployment, index)\n",
@@ -42,10 +43,10 @@
4243
"\n",
4344
"# Policies\n",
4445
"hello_world_policy_xml = utils.read_policy_xml(HELLO_WORLD_XML_POLICY_PATH)\n",
45-
"backend_polixy_xml = utils.read_policy_xml(BACKEND_XML_POLICY_PATH)\n",
46-
"aca_backend_1_policy_xml = backend_polixy_xml.format(backend_id = 'aca-backend-1')\n",
47-
"aca_backend_2_policy_xml = backend_polixy_xml.format(backend_id = 'aca-backend-2')\n",
48-
"aca_backend_pool_policy_xml = backend_polixy_xml.format(backend_id = 'aca-backend-pool')\n",
46+
"backend_policy_xml = utils.read_policy_xml(BACKEND_XML_POLICY_PATH)\n",
47+
"aca_backend_1_policy_xml = backend_policy_xml.format(backend_id = 'aca-backend-1')\n",
48+
"aca_backend_2_policy_xml = backend_policy_xml.format(backend_id = 'aca-backend-2')\n",
49+
"aca_backend_pool_policy_xml = backend_policy_xml.format(backend_id = 'aca-backend-pool')\n",
4950
"\n",
5051
"# Hello World (Root)\n",
5152
"api_hwroot_get = GET_APIOperation('This is a GET for Hello World in the root', hello_world_policy_xml)\n",
@@ -88,9 +89,10 @@
8889
"\n",
8990
"# 1) Define the Bicep parameters with serialized APIs\n",
9091
"bicep_parameters = {\n",
91-
" 'apimSku' : {'value': apim_sku.value},\n",
92-
" 'apis' : {'value': [api.to_dict() for api in apis]},\n",
93-
" 'policyFragments': {'value': [pf.to_dict() for pf in pfs]}\n",
92+
" 'apimSku' : {'value': apim_sku.value},\n",
93+
" 'apis' : {'value': [api.to_dict() for api in apis]},\n",
94+
" 'policyFragments' : {'value': [pf.to_dict() for pf in pfs]},\n",
95+
" 'revealBackendApiInfo' : {'value:': reveal_backend} \n",
9496
"}\n",
9597
"\n",
9698
"# 2) Run the deployment\n",

infrastructure/apim-aca/main.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ param apimSku string
1313
param apis array = []
1414
param policyFragments array = []
1515

16+
@description('Reveals the backend API information. Defaults to true. *** WARNING: This will expose backend API information to the caller - For learning & testing only! ***')
17+
param revealBackendApiInfo bool = true
18+
1619

1720
// ------------------
1821
// "CONSTANTS"
@@ -80,6 +83,7 @@ module apimModule '../../shared/bicep/modules/apim/v1/apim.bicep' = {
8083
apimSku: apimSku
8184
appInsightsInstrumentationKey: appInsightsInstrumentationKey
8285
appInsightsId: appInsightsId
86+
globalPolicyXml: revealBackendApiInfo ? loadTextContent('../../shared/apim-policies/all-apis-reveal-backend.xml') : loadTextContent('../../shared/apim-policies/all-apis.xml')
8387
}
8488
}
8589

infrastructure/simple-apim/create.ipynb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
"from apimtypes import *\n",
2222
"\n",
2323
"# 1) User-defined parameters (change these as needed)\n",
24-
"rg_location = 'eastus2'\n",
25-
"index = 1\n",
26-
"apim_sku = APIM_SKU.BASICV2\n",
27-
"deployment = INFRASTRUCTURE.SIMPLE_APIM\n",
24+
"rg_location = 'eastus2'\n",
25+
"index = 1\n",
26+
"apim_sku = APIM_SKU.BASICV2\n",
27+
"deployment = INFRASTRUCTURE.SIMPLE_APIM\n",
28+
"reveal_backend = True # Set to True to reveal the backend details in the API operations\n",
2829
"\n",
2930
"# 2) Service-defined parameters (please do not change these)\n",
3031
"rg_name = utils.get_infra_rg_name(deployment, index)\n",
@@ -72,9 +73,10 @@
7273
"\n",
7374
"# 1) Define the Bicep parameters with serialized APIs\n",
7475
"bicep_parameters = {\n",
75-
" 'apimSku' : {'value': apim_sku.value},\n",
76-
" 'apis' : {'value': [api.to_dict() for api in apis]},\n",
77-
" 'policyFragments': {'value': [pf.to_dict() for pf in pfs]}\n",
76+
" 'apimSku' : {'value': apim_sku.value},\n",
77+
" 'apis' : {'value': [api.to_dict() for api in apis]},\n",
78+
" 'policyFragments' : {'value': [pf.to_dict() for pf in pfs]},\n",
79+
" 'revealBackendApiInfo' : {'value:': reveal_backend}\n",
7880
"}\n",
7981
"\n",
8082
"# 2) Run the deployment\n",

infrastructure/simple-apim/main.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ param apimSku string
1414
param apis array = []
1515
param policyFragments array = []
1616

17+
@description('Reveals the backend API information. Defaults to true. *** WARNING: This will expose backend API information to the caller - For learning & testing only! ***')
18+
param revealBackendApiInfo bool = true
19+
1720
// ------------------
1821
// RESOURCES
1922
// ------------------
@@ -44,6 +47,7 @@ module apimModule '../../shared/bicep/modules/apim/v1/apim.bicep' = {
4447
apimSku: apimSku
4548
appInsightsInstrumentationKey: appInsightsInstrumentationKey
4649
appInsightsId: appInsightsId
50+
globalPolicyXml: revealBackendApiInfo ? loadTextContent('../../shared/apim-policies/all-apis-reveal-backend.xml') : loadTextContent('../../shared/apim-policies/all-apis.xml')
4751
}
4852
}
4953

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!--
2+
This is the global All APIs policy.
3+
If you want to apply CORS policies to all APIs, uncomment the CORS policy block below and make the necessary adjustments to the allowed origins.
4+
-->
5+
<policies>
6+
<inbound>
7+
<!--
8+
<cors allow-credentials="true" terminate-unmatched-request="false">
9+
<allowed-origins>
10+
<origin>[ADD YOUR ORIGINS]</origin>
11+
</allowed-origins>
12+
<allowed-methods preflight-result-max-age="300">
13+
<method>*</method>
14+
</allowed-methods>
15+
<allowed-headers>
16+
<header>*</header>
17+
</allowed-headers>
18+
<expose-headers>
19+
<header>*</header>
20+
</expose-headers>
21+
</cors>
22+
-->
23+
</inbound>
24+
<backend>
25+
<forward-request />
26+
</backend>
27+
<outbound>
28+
<!-- Please be aware that this reveals internal information to the caller. Use for learning and testing only. -->
29+
<set-header name="X-Backend-URL" exists-action="override">
30+
<value>@(context.Request.Url.ToString())</value>
31+
</set-header>
32+
</outbound>
33+
<on-error />
34+
</policies>

0 commit comments

Comments
 (0)