@gradientedge/cdk-utils 9.73.0 → 9.74.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/lib/azure/services/api-management/main.d.ts +1 -9
- package/dist/src/lib/azure/services/api-management/main.js +22 -95
- package/dist/src/lib/azure/services/api-management/types.d.ts +3 -5
- package/package.json +1 -1
- package/src/lib/azure/services/api-management/main.ts +23 -111
- package/src/lib/azure/services/api-management/types.ts +4 -6
|
@@ -5,7 +5,7 @@ import { ApiManagementApi } from '@cdktf/provider-azurerm/lib/api-management-api
|
|
|
5
5
|
import { ApiManagementLoggerApplicationInsights } from '@cdktf/provider-azurerm/lib/api-management-logger';
|
|
6
6
|
import { Resource } from '../../.gen/providers/azapi/resource';
|
|
7
7
|
import { CommonAzureConstruct } from '../../common';
|
|
8
|
-
import { ApiManagementProps, ApiManagementBackendProps, ApiManagementApiProps,
|
|
8
|
+
import { ApiManagementProps, ApiManagementBackendProps, ApiManagementApiProps, ApiManagementCustomDomainProps } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* @classdesc Provides operations on Azure Api Management
|
|
11
11
|
* - A new instance of this class is injected into {@link CommonAzureConstruct} constructor.
|
|
@@ -40,14 +40,6 @@ export declare class AzureApiManagementManager {
|
|
|
40
40
|
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
41
41
|
*/
|
|
42
42
|
resolveApiManagement(id: string, scope: CommonAzureConstruct, props: DataAzurermApiManagementConfig): DataAzurermApiManagement;
|
|
43
|
-
/**
|
|
44
|
-
* @summary Method to create a new api management
|
|
45
|
-
* @param id scoped id of the resource
|
|
46
|
-
* @param scope scope in which this resource is defined
|
|
47
|
-
* @param props api management properties
|
|
48
|
-
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
49
|
-
*/
|
|
50
|
-
createApiManagementv2(id: string, scope: CommonAzureConstruct, props: ApiManagementV2Props, applicationInsightsKey?: ApiManagementLoggerApplicationInsights['instrumentationKey']): Resource;
|
|
51
43
|
/**
|
|
52
44
|
* @summary Method to create a new api management backend
|
|
53
45
|
* @param id scoped id of the resource
|
|
@@ -99,67 +99,6 @@ class AzureApiManagementManager {
|
|
|
99
99
|
});
|
|
100
100
|
return apiManagement;
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
103
|
-
* @summary Method to create a new api management
|
|
104
|
-
* @param id scoped id of the resource
|
|
105
|
-
* @param scope scope in which this resource is defined
|
|
106
|
-
* @param props api management properties
|
|
107
|
-
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
108
|
-
*/
|
|
109
|
-
createApiManagementv2(id, scope, props, applicationInsightsKey) {
|
|
110
|
-
if (!props)
|
|
111
|
-
throw `Props undefined for ${id}`;
|
|
112
|
-
const resourceGroup = new data_azurerm_resource_group_1.DataAzurermResourceGroup(scope, `${id}-am-rg`, {
|
|
113
|
-
name: scope.props.resourceGroupName
|
|
114
|
-
? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
|
|
115
|
-
: `${props.resourceGroupName}`,
|
|
116
|
-
});
|
|
117
|
-
if (!resourceGroup)
|
|
118
|
-
throw `Resource group undefined for ${id}`;
|
|
119
|
-
const apiManagement = new resource_1.Resource(scope, `${id}-am`, {
|
|
120
|
-
type: 'Microsoft.ApiManagement/service@2024-05-01',
|
|
121
|
-
name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagement),
|
|
122
|
-
location: resourceGroup.location,
|
|
123
|
-
parentId: resourceGroup.id,
|
|
124
|
-
body: {
|
|
125
|
-
properties: {
|
|
126
|
-
apiVersionConstraint: {
|
|
127
|
-
minApiVersion: '2019-12-01',
|
|
128
|
-
},
|
|
129
|
-
publisherName: props.publisherName,
|
|
130
|
-
publisherEmail: props.publisherEmail,
|
|
131
|
-
},
|
|
132
|
-
sku: {
|
|
133
|
-
capacity: 1,
|
|
134
|
-
name: props.skuName,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
responseExportValues: ['*'],
|
|
138
|
-
identity: [
|
|
139
|
-
{
|
|
140
|
-
type: 'SystemAssigned',
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
ignoreMissingProperty: true,
|
|
144
|
-
ignoreCasing: true,
|
|
145
|
-
schemaValidationEnabled: false,
|
|
146
|
-
lifecycle: props.lifecycle,
|
|
147
|
-
});
|
|
148
|
-
if (applicationInsightsKey) {
|
|
149
|
-
new api_management_logger_1.ApiManagementLogger(scope, `${id}-am-logger`, {
|
|
150
|
-
name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementLogger),
|
|
151
|
-
resourceGroupName: resourceGroup.name,
|
|
152
|
-
apiManagementName: apiManagement.name,
|
|
153
|
-
applicationInsights: {
|
|
154
|
-
instrumentationKey: applicationInsightsKey,
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementName`, scope, apiManagement.name);
|
|
159
|
-
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId);
|
|
160
|
-
(0, utils_1.createAzureTfOutput)(`${id}-apiManagementId`, scope, apiManagement.id);
|
|
161
|
-
return apiManagement;
|
|
162
|
-
}
|
|
163
102
|
/**
|
|
164
103
|
* @summary Method to create a new api management backend
|
|
165
104
|
* @param id scoped id of the resource
|
|
@@ -239,11 +178,12 @@ class AzureApiManagementManager {
|
|
|
239
178
|
(0, utils_1.createAzureTfOutput)(`${id}-${operation.displayName}-${operation.method}-apimOperationFriendlyUniqueId`, scope, apimOperation.friendlyUniqueId);
|
|
240
179
|
(0, utils_1.createAzureTfOutput)(`${id}-${operation.displayName}-${operation.method}-apimOperationId`, scope, apimOperation.id);
|
|
241
180
|
// Define Caching Policy if enabled
|
|
242
|
-
let
|
|
243
|
-
let
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
181
|
+
let cacheSetVariablePolicy = '';
|
|
182
|
+
let cacheInvalidateInboundPolicy = '';
|
|
183
|
+
let cacheSetInboundPolicy = '';
|
|
184
|
+
let cacheSetOutboundPolicy = '';
|
|
185
|
+
if (operation.caching) {
|
|
186
|
+
cacheSetVariablePolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
|
|
247
187
|
<set-variable name="customCacheKey" value="@{
|
|
248
188
|
// Instance identification
|
|
249
189
|
|
|
@@ -253,13 +193,16 @@ class AzureApiManagementManager {
|
|
|
253
193
|
|
|
254
194
|
// Full path construction (without query parameters)
|
|
255
195
|
string fullPath = context.Request.Url.Path.ToLower();
|
|
256
|
-
|
|
196
|
+
|
|
197
|
+
// Query parameters
|
|
198
|
+
string query = context.Request.Url.QueryString.ToLower();
|
|
199
|
+
|
|
257
200
|
// Construct final cache key (no Accept header needed for JSON-only APIs)
|
|
258
|
-
return $"{apiName}:{apiVersion}:{fullPath}";
|
|
201
|
+
return $"{apiName}:{apiVersion}:{fullPath}:{query}";
|
|
259
202
|
}" />
|
|
260
|
-
<set-variable name="bypassCache" value="@(context.Request.Headers.GetValueOrDefault("X-Bypass-Cache", "false").ToLower())"
|
|
261
|
-
|
|
262
|
-
|
|
203
|
+
<set-variable name="bypassCache" value="@(context.Request.Headers.GetValueOrDefault("X-Bypass-Cache", "false").ToLower())" />`;
|
|
204
|
+
if (operation.caching.enableCacheSet) {
|
|
205
|
+
cacheSetInboundPolicy = `<choose>
|
|
263
206
|
<when condition="@((string)context.Variables["bypassCache"] != "true")">
|
|
264
207
|
<!-- Attempt to retrieve cached response -->
|
|
265
208
|
<cache-lookup-value key="@((string)context.Variables["customCacheKey"])" variable-name="cachedResponse" />
|
|
@@ -284,12 +227,12 @@ class AzureApiManagementManager {
|
|
|
284
227
|
</choose>
|
|
285
228
|
</when>
|
|
286
229
|
</choose>`;
|
|
287
|
-
|
|
230
|
+
cacheSetOutboundPolicy = `<choose>
|
|
288
231
|
<when condition="@((string)context.Variables["bypassCache"] != "true")">
|
|
289
232
|
<!-- Store the response body in cache -->
|
|
290
233
|
<choose>
|
|
291
234
|
<when condition="@(context.Response.StatusCode == 200)">
|
|
292
|
-
<cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${
|
|
235
|
+
<cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${operation.caching.ttlInSecs ?? 900}" />
|
|
293
236
|
<!-- Add cache status header -->
|
|
294
237
|
<set-header name="X-Apim-Cache-Status" exists-action="override">
|
|
295
238
|
<value>MISS</value>
|
|
@@ -306,26 +249,8 @@ class AzureApiManagementManager {
|
|
|
306
249
|
</when>
|
|
307
250
|
</choose>`;
|
|
308
251
|
}
|
|
309
|
-
if (operation.
|
|
310
|
-
|
|
311
|
-
<set-variable name="customCacheKey" value="@{
|
|
312
|
-
// Instance identification
|
|
313
|
-
|
|
314
|
-
// API identification
|
|
315
|
-
string apiName = context.Api.Name.Replace(" ", "").ToLower();
|
|
316
|
-
string apiVersion = context.Api.Version ?? "v1";
|
|
317
|
-
|
|
318
|
-
// Full path construction (without query parameters)
|
|
319
|
-
string fullPath = context.Request.Url.Path.ToLower();
|
|
320
|
-
|
|
321
|
-
// Query arameters
|
|
322
|
-
string query = context.Request.Url.Query.ToLower();
|
|
323
|
-
|
|
324
|
-
// Construct final cache key (no Accept header needed for JSON-only APIs)
|
|
325
|
-
return $"{apiName}:{apiVersion}:{fullPath}:{query}";
|
|
326
|
-
}" />
|
|
327
|
-
<set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
|
|
328
|
-
|
|
252
|
+
if (operation.caching.enableCacheInvalidation) {
|
|
253
|
+
cacheInvalidateInboundPolicy = `<set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
|
|
329
254
|
<!-- Allow admin to clear specific cache entries -->
|
|
330
255
|
<choose>
|
|
331
256
|
<when condition="@((string)context.Variables["clearCache"] == "true")">
|
|
@@ -347,7 +272,9 @@ class AzureApiManagementManager {
|
|
|
347
272
|
<inbound>
|
|
348
273
|
<base />
|
|
349
274
|
${rateLimitPolicy}
|
|
350
|
-
${
|
|
275
|
+
${cacheSetVariablePolicy}
|
|
276
|
+
${cacheInvalidateInboundPolicy}
|
|
277
|
+
${cacheSetInboundPolicy}
|
|
351
278
|
${props.commonInboundPolicyXml ?? ''}
|
|
352
279
|
</inbound>
|
|
353
280
|
<backend>
|
|
@@ -355,7 +282,7 @@ class AzureApiManagementManager {
|
|
|
355
282
|
</backend>
|
|
356
283
|
<outbound>
|
|
357
284
|
<base />
|
|
358
|
-
${
|
|
285
|
+
${cacheSetOutboundPolicy}
|
|
359
286
|
${props.commonOutboundPolicyXml ?? ''}
|
|
360
287
|
</outbound>
|
|
361
288
|
<on-error>
|
|
@@ -16,16 +16,14 @@ export interface ApiManagementApiProps extends ApiManagementApiConfig {
|
|
|
16
16
|
operations: ApiManagementApiOperationProps[];
|
|
17
17
|
commonInboundPolicyXml: string;
|
|
18
18
|
commonOutboundPolicyXml: string;
|
|
19
|
-
caching?: ApiManagementApiCaching;
|
|
20
19
|
rateLimit?: ApiManagementApiRateLimit;
|
|
21
20
|
}
|
|
22
|
-
export interface ApiManagementV2Props extends ApiManagementConfig {
|
|
23
|
-
body: any;
|
|
24
|
-
}
|
|
25
21
|
export interface ApiManagementApiOperationProps extends ApiManagementApiOperationConfig {
|
|
22
|
+
caching?: ApiManagementApiCaching;
|
|
26
23
|
}
|
|
27
24
|
export interface ApiManagementApiCaching {
|
|
28
|
-
|
|
25
|
+
enableCacheSet?: boolean;
|
|
26
|
+
enableCacheInvalidation?: boolean;
|
|
29
27
|
ttlInSecs?: number;
|
|
30
28
|
}
|
|
31
29
|
export interface ApiManagementApiRateLimit {
|
package/package.json
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
DataAzurermApiManagementConfig,
|
|
5
5
|
} from '@cdktf/provider-azurerm/lib/data-azurerm-api-management'
|
|
6
6
|
import { ApiManagementCustomDomain } from '@cdktf/provider-azurerm/lib/api-management-custom-domain'
|
|
7
|
-
import { ApiManagementBackend } from '@cdktf/provider-azurerm/lib/api-management-backend'
|
|
8
7
|
import { ApiManagement } from '@cdktf/provider-azurerm/lib/api-management'
|
|
9
8
|
import { ApiManagementApi } from '@cdktf/provider-azurerm/lib/api-management-api'
|
|
10
9
|
import { ApiManagementApiOperation } from '@cdktf/provider-azurerm/lib/api-management-api-operation'
|
|
@@ -20,7 +19,6 @@ import {
|
|
|
20
19
|
ApiManagementProps,
|
|
21
20
|
ApiManagementBackendProps,
|
|
22
21
|
ApiManagementApiProps,
|
|
23
|
-
ApiManagementV2Props,
|
|
24
22
|
ApiManagementCustomDomainProps,
|
|
25
23
|
} from './types'
|
|
26
24
|
import _ from 'lodash'
|
|
@@ -122,82 +120,6 @@ export class AzureApiManagementManager {
|
|
|
122
120
|
return apiManagement
|
|
123
121
|
}
|
|
124
122
|
|
|
125
|
-
/**
|
|
126
|
-
* @summary Method to create a new api management
|
|
127
|
-
* @param id scoped id of the resource
|
|
128
|
-
* @param scope scope in which this resource is defined
|
|
129
|
-
* @param props api management properties
|
|
130
|
-
* @see [CDKTF Api management Module]{@link https://github.com/cdktf/cdktf-provider-azurerm/blob/main/docs/apiManagement.typescript.md}
|
|
131
|
-
*/
|
|
132
|
-
public createApiManagementv2(
|
|
133
|
-
id: string,
|
|
134
|
-
scope: CommonAzureConstruct,
|
|
135
|
-
props: ApiManagementV2Props,
|
|
136
|
-
applicationInsightsKey?: ApiManagementLoggerApplicationInsights['instrumentationKey']
|
|
137
|
-
) {
|
|
138
|
-
if (!props) throw `Props undefined for ${id}`
|
|
139
|
-
|
|
140
|
-
const resourceGroup = new DataAzurermResourceGroup(scope, `${id}-am-rg`, {
|
|
141
|
-
name: scope.props.resourceGroupName
|
|
142
|
-
? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
|
|
143
|
-
: `${props.resourceGroupName}`,
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
if (!resourceGroup) throw `Resource group undefined for ${id}`
|
|
147
|
-
|
|
148
|
-
const apiManagement = new Resource(scope, `${id}-am`, {
|
|
149
|
-
type: 'Microsoft.ApiManagement/service@2024-05-01',
|
|
150
|
-
name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagement),
|
|
151
|
-
location: resourceGroup.location,
|
|
152
|
-
parentId: resourceGroup.id,
|
|
153
|
-
|
|
154
|
-
body: {
|
|
155
|
-
properties: {
|
|
156
|
-
apiVersionConstraint: {
|
|
157
|
-
minApiVersion: '2019-12-01',
|
|
158
|
-
},
|
|
159
|
-
publisherName: props.publisherName,
|
|
160
|
-
publisherEmail: props.publisherEmail,
|
|
161
|
-
},
|
|
162
|
-
sku: {
|
|
163
|
-
capacity: 1,
|
|
164
|
-
name: props.skuName,
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
responseExportValues: ['*'],
|
|
169
|
-
|
|
170
|
-
identity: [
|
|
171
|
-
{
|
|
172
|
-
type: 'SystemAssigned',
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
|
|
176
|
-
ignoreMissingProperty: true,
|
|
177
|
-
ignoreCasing: true,
|
|
178
|
-
schemaValidationEnabled: false,
|
|
179
|
-
|
|
180
|
-
lifecycle: props.lifecycle,
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
if (applicationInsightsKey) {
|
|
184
|
-
new ApiManagementLogger(scope, `${id}-am-logger`, {
|
|
185
|
-
name: scope.resourceNameFormatter.format(props.name, scope.props.resourceNameOptions?.apiManagementLogger),
|
|
186
|
-
resourceGroupName: resourceGroup.name,
|
|
187
|
-
apiManagementName: apiManagement.name,
|
|
188
|
-
applicationInsights: {
|
|
189
|
-
instrumentationKey: applicationInsightsKey,
|
|
190
|
-
},
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
createAzureTfOutput(`${id}-apiManagementName`, scope, apiManagement.name)
|
|
195
|
-
createAzureTfOutput(`${id}-apiManagementFriendlyUniqueId`, scope, apiManagement.friendlyUniqueId)
|
|
196
|
-
createAzureTfOutput(`${id}-apiManagementId`, scope, apiManagement.id)
|
|
197
|
-
|
|
198
|
-
return apiManagement
|
|
199
|
-
}
|
|
200
|
-
|
|
201
123
|
/**
|
|
202
124
|
* @summary Method to create a new api management backend
|
|
203
125
|
* @param id scoped id of the resource
|
|
@@ -301,12 +223,13 @@ export class AzureApiManagementManager {
|
|
|
301
223
|
createAzureTfOutput(`${id}-${operation.displayName}-${operation.method}-apimOperationId`, scope, apimOperation.id)
|
|
302
224
|
|
|
303
225
|
// Define Caching Policy if enabled
|
|
304
|
-
let
|
|
305
|
-
let
|
|
226
|
+
let cacheSetVariablePolicy = ''
|
|
227
|
+
let cacheInvalidateInboundPolicy = ''
|
|
228
|
+
let cacheSetInboundPolicy = ''
|
|
229
|
+
let cacheSetOutboundPolicy = ''
|
|
306
230
|
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
cacheInboundPolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
|
|
231
|
+
if (operation.caching) {
|
|
232
|
+
cacheSetVariablePolicy = `<!-- Generate a comprehensive custom cache key (without query params or Accept header) -->
|
|
310
233
|
<set-variable name="customCacheKey" value="@{
|
|
311
234
|
// Instance identification
|
|
312
235
|
|
|
@@ -316,13 +239,17 @@ export class AzureApiManagementManager {
|
|
|
316
239
|
|
|
317
240
|
// Full path construction (without query parameters)
|
|
318
241
|
string fullPath = context.Request.Url.Path.ToLower();
|
|
319
|
-
|
|
242
|
+
|
|
243
|
+
// Query parameters
|
|
244
|
+
string query = context.Request.Url.QueryString.ToLower();
|
|
245
|
+
|
|
320
246
|
// Construct final cache key (no Accept header needed for JSON-only APIs)
|
|
321
|
-
return $"{apiName}:{apiVersion}:{fullPath}";
|
|
247
|
+
return $"{apiName}:{apiVersion}:{fullPath}:{query}";
|
|
322
248
|
}" />
|
|
323
|
-
<set-variable name="bypassCache" value="@(context.Request.Headers.GetValueOrDefault("X-Bypass-Cache", "false").ToLower())"
|
|
249
|
+
<set-variable name="bypassCache" value="@(context.Request.Headers.GetValueOrDefault("X-Bypass-Cache", "false").ToLower())" />`
|
|
324
250
|
|
|
325
|
-
|
|
251
|
+
if (operation.caching.enableCacheSet) {
|
|
252
|
+
cacheSetInboundPolicy = `<choose>
|
|
326
253
|
<when condition="@((string)context.Variables["bypassCache"] != "true")">
|
|
327
254
|
<!-- Attempt to retrieve cached response -->
|
|
328
255
|
<cache-lookup-value key="@((string)context.Variables["customCacheKey"])" variable-name="cachedResponse" />
|
|
@@ -347,12 +274,12 @@ export class AzureApiManagementManager {
|
|
|
347
274
|
</choose>
|
|
348
275
|
</when>
|
|
349
276
|
</choose>`
|
|
350
|
-
|
|
277
|
+
cacheSetOutboundPolicy = `<choose>
|
|
351
278
|
<when condition="@((string)context.Variables["bypassCache"] != "true")">
|
|
352
279
|
<!-- Store the response body in cache -->
|
|
353
280
|
<choose>
|
|
354
281
|
<when condition="@(context.Response.StatusCode == 200)">
|
|
355
|
-
<cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${
|
|
282
|
+
<cache-store-value key="@((string)context.Variables["customCacheKey"])" value="@(context.Response.Body.As<string>(preserveContent: true))" duration="${operation.caching.ttlInSecs ?? 900}" />
|
|
356
283
|
<!-- Add cache status header -->
|
|
357
284
|
<set-header name="X-Apim-Cache-Status" exists-action="override">
|
|
358
285
|
<value>MISS</value>
|
|
@@ -370,26 +297,8 @@ export class AzureApiManagementManager {
|
|
|
370
297
|
</choose>`
|
|
371
298
|
}
|
|
372
299
|
|
|
373
|
-
if (operation.
|
|
374
|
-
|
|
375
|
-
<set-variable name="customCacheKey" value="@{
|
|
376
|
-
// Instance identification
|
|
377
|
-
|
|
378
|
-
// API identification
|
|
379
|
-
string apiName = context.Api.Name.Replace(" ", "").ToLower();
|
|
380
|
-
string apiVersion = context.Api.Version ?? "v1";
|
|
381
|
-
|
|
382
|
-
// Full path construction (without query parameters)
|
|
383
|
-
string fullPath = context.Request.Url.Path.ToLower();
|
|
384
|
-
|
|
385
|
-
// Query arameters
|
|
386
|
-
string query = context.Request.Url.Query.ToLower();
|
|
387
|
-
|
|
388
|
-
// Construct final cache key (no Accept header needed for JSON-only APIs)
|
|
389
|
-
return $"{apiName}:{apiVersion}:{fullPath}:{query}";
|
|
390
|
-
}" />
|
|
391
|
-
<set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
|
|
392
|
-
|
|
300
|
+
if (operation.caching.enableCacheInvalidation) {
|
|
301
|
+
cacheInvalidateInboundPolicy = `<set-variable name="clearCache" value="@(context.Request.Headers.GetValueOrDefault("X-Apim-Clear-Cache", "false").ToLower())" />
|
|
393
302
|
<!-- Allow admin to clear specific cache entries -->
|
|
394
303
|
<choose>
|
|
395
304
|
<when condition="@((string)context.Variables["clearCache"] == "true")">
|
|
@@ -408,11 +317,14 @@ export class AzureApiManagementManager {
|
|
|
408
317
|
if (props.rateLimit && scope.props.subscriptionId) {
|
|
409
318
|
rateLimitPolicy = `<rate-limit-by-key calls="${props.rateLimit.calls}" renewal-period="${props.rateLimit.renewalPeriodInSecs}" counter-key="${scope.props.subscriptionId}-${apimOperation.operationId}"/>`
|
|
410
319
|
}
|
|
320
|
+
|
|
411
321
|
const policyXmlContent = `<policies>
|
|
412
322
|
<inbound>
|
|
413
323
|
<base />
|
|
414
324
|
${rateLimitPolicy}
|
|
415
|
-
${
|
|
325
|
+
${cacheSetVariablePolicy}
|
|
326
|
+
${cacheInvalidateInboundPolicy}
|
|
327
|
+
${cacheSetInboundPolicy}
|
|
416
328
|
${props.commonInboundPolicyXml ?? ''}
|
|
417
329
|
</inbound>
|
|
418
330
|
<backend>
|
|
@@ -420,7 +332,7 @@ export class AzureApiManagementManager {
|
|
|
420
332
|
</backend>
|
|
421
333
|
<outbound>
|
|
422
334
|
<base />
|
|
423
|
-
${
|
|
335
|
+
${cacheSetOutboundPolicy}
|
|
424
336
|
${props.commonOutboundPolicyXml ?? ''}
|
|
425
337
|
</outbound>
|
|
426
338
|
<on-error>
|
|
@@ -18,18 +18,16 @@ export interface ApiManagementApiProps extends ApiManagementApiConfig {
|
|
|
18
18
|
operations: ApiManagementApiOperationProps[]
|
|
19
19
|
commonInboundPolicyXml: string
|
|
20
20
|
commonOutboundPolicyXml: string
|
|
21
|
-
caching?: ApiManagementApiCaching
|
|
22
21
|
rateLimit?: ApiManagementApiRateLimit
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
export interface
|
|
26
|
-
|
|
24
|
+
export interface ApiManagementApiOperationProps extends ApiManagementApiOperationConfig {
|
|
25
|
+
caching?: ApiManagementApiCaching
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
export interface ApiManagementApiOperationProps extends ApiManagementApiOperationConfig {}
|
|
30
|
-
|
|
31
28
|
export interface ApiManagementApiCaching {
|
|
32
|
-
|
|
29
|
+
enableCacheSet?: boolean
|
|
30
|
+
enableCacheInvalidation?: boolean
|
|
33
31
|
ttlInSecs?: number
|
|
34
32
|
}
|
|
35
33
|
|