@gradientedge/cdk-utils 10.6.0 → 10.8.0

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.
Files changed (200) hide show
  1. package/dist/app/api-destined-function/src/lib/lambda.d.ts +1 -0
  2. package/dist/app/api-destined-function/src/lib/lambda.d.ts.map +1 -0
  3. package/dist/app/api-destined-function/src/lib/lambda.js +1 -0
  4. package/dist/app/api-destined-function/src/lib/lambda.js.map +1 -0
  5. package/dist/app/api-destined-function/tsconfig.tsbuildinfo +1 -0
  6. package/dist/src/lib/aws/services/cloudwatch/main.d.ts +11 -11
  7. package/dist/src/lib/azure/common/constants.d.ts +74 -0
  8. package/dist/src/lib/azure/common/constants.js +77 -0
  9. package/dist/src/lib/azure/common/construct.d.ts +15 -3
  10. package/dist/src/lib/azure/common/construct.js +40 -4
  11. package/dist/src/lib/azure/common/stack.d.ts +3 -2
  12. package/dist/src/lib/azure/common/stack.js +25 -42
  13. package/dist/src/lib/azure/common/types.d.ts +13 -2
  14. package/dist/src/lib/azure/construct/event-handler/index.d.ts +2 -0
  15. package/dist/src/lib/azure/construct/event-handler/index.js +2 -0
  16. package/dist/src/lib/azure/construct/event-handler/main.d.ts +20 -0
  17. package/dist/src/lib/azure/construct/event-handler/main.js +139 -0
  18. package/dist/src/lib/azure/construct/event-handler/types.d.ts +35 -0
  19. package/dist/src/lib/azure/construct/event-handler/types.js +1 -0
  20. package/dist/src/lib/azure/construct/function-app/index.d.ts +2 -0
  21. package/dist/src/lib/azure/construct/function-app/index.js +2 -0
  22. package/dist/src/lib/azure/construct/function-app/main.d.ts +51 -0
  23. package/dist/src/lib/azure/construct/function-app/main.js +297 -0
  24. package/dist/src/lib/azure/construct/function-app/types.d.ts +33 -0
  25. package/dist/src/lib/azure/construct/function-app/types.js +1 -0
  26. package/dist/src/lib/azure/construct/index.d.ts +6 -0
  27. package/dist/src/lib/azure/construct/index.js +6 -0
  28. package/dist/src/lib/azure/construct/rest-api/index.d.ts +2 -0
  29. package/dist/src/lib/azure/construct/rest-api/index.js +2 -0
  30. package/dist/src/lib/azure/construct/rest-api/main.d.ts +20 -0
  31. package/dist/src/lib/azure/construct/rest-api/main.js +172 -0
  32. package/dist/src/lib/azure/construct/rest-api/types.d.ts +25 -0
  33. package/dist/src/lib/azure/construct/rest-api/types.js +1 -0
  34. package/dist/src/lib/azure/construct/rest-api-function/index.d.ts +2 -0
  35. package/dist/src/lib/azure/construct/rest-api-function/index.js +2 -0
  36. package/dist/src/lib/azure/construct/rest-api-function/main.d.ts +19 -0
  37. package/dist/src/lib/azure/construct/rest-api-function/main.js +255 -0
  38. package/dist/src/lib/azure/construct/rest-api-function/types.d.ts +29 -0
  39. package/dist/src/lib/azure/construct/rest-api-function/types.js +1 -0
  40. package/dist/src/lib/azure/construct/rest-api-with-cache/index.d.ts +2 -0
  41. package/dist/src/lib/azure/construct/rest-api-with-cache/index.js +2 -0
  42. package/dist/src/lib/azure/construct/rest-api-with-cache/main.d.ts +12 -0
  43. package/dist/src/lib/azure/construct/rest-api-with-cache/main.js +56 -0
  44. package/dist/src/lib/azure/construct/rest-api-with-cache/types.d.ts +13 -0
  45. package/dist/src/lib/azure/construct/rest-api-with-cache/types.js +1 -0
  46. package/dist/src/lib/azure/construct/site-with-webapp/index.d.ts +2 -0
  47. package/dist/src/lib/azure/construct/site-with-webapp/index.js +2 -0
  48. package/dist/src/lib/azure/construct/site-with-webapp/main.d.ts +19 -0
  49. package/dist/src/lib/azure/construct/site-with-webapp/main.js +135 -0
  50. package/dist/src/lib/azure/construct/site-with-webapp/types.d.ts +30 -0
  51. package/dist/src/lib/azure/construct/site-with-webapp/types.js +1 -0
  52. package/dist/src/lib/azure/index.d.ts +1 -0
  53. package/dist/src/lib/azure/index.js +1 -0
  54. package/dist/src/lib/azure/services/api-management/main.d.ts +83 -5
  55. package/dist/src/lib/azure/services/api-management/main.js +114 -148
  56. package/dist/src/lib/azure/services/api-management/types.d.ts +22 -1
  57. package/dist/src/lib/azure/services/app-configuration/main.d.ts +13 -1
  58. package/dist/src/lib/azure/services/app-configuration/main.js +21 -2
  59. package/dist/src/lib/azure/services/app-service/main.d.ts +5 -2
  60. package/dist/src/lib/azure/services/app-service/main.js +12 -4
  61. package/dist/src/lib/azure/services/application-insights/main.d.ts +15 -4
  62. package/dist/src/lib/azure/services/application-insights/main.js +27 -6
  63. package/dist/src/lib/azure/services/application-insights/types.d.ts +4 -1
  64. package/dist/src/lib/azure/services/authorisation/constants.d.ts +13 -0
  65. package/dist/src/lib/azure/services/authorisation/constants.js +14 -0
  66. package/dist/src/lib/azure/services/authorisation/index.d.ts +3 -0
  67. package/dist/src/lib/azure/services/authorisation/index.js +3 -0
  68. package/dist/src/lib/azure/services/authorisation/main.d.ts +84 -0
  69. package/dist/src/lib/azure/services/authorisation/main.js +120 -0
  70. package/dist/src/lib/azure/services/authorisation/types.d.ts +3 -0
  71. package/dist/src/lib/azure/services/authorisation/types.js +1 -0
  72. package/dist/src/lib/azure/services/cosmosdb/constants.d.ts +8 -0
  73. package/dist/src/lib/azure/services/cosmosdb/constants.js +10 -0
  74. package/dist/src/lib/azure/services/cosmosdb/index.d.ts +1 -0
  75. package/dist/src/lib/azure/services/cosmosdb/index.js +1 -0
  76. package/dist/src/lib/azure/services/cosmosdb/main.d.ts +47 -5
  77. package/dist/src/lib/azure/services/cosmosdb/main.js +77 -8
  78. package/dist/src/lib/azure/services/cosmosdb/types.d.ts +3 -1
  79. package/dist/src/lib/azure/services/dns/main.d.ts +9 -4
  80. package/dist/src/lib/azure/services/dns/main.js +12 -8
  81. package/dist/src/lib/azure/services/eventgrid/main.d.ts +12 -7
  82. package/dist/src/lib/azure/services/eventgrid/main.js +18 -19
  83. package/dist/src/lib/azure/services/function/main.d.ts +16 -3
  84. package/dist/src/lib/azure/services/function/main.js +122 -8
  85. package/dist/src/lib/azure/services/function/types.d.ts +3 -4
  86. package/dist/src/lib/azure/services/index.d.ts +3 -0
  87. package/dist/src/lib/azure/services/index.js +3 -0
  88. package/dist/src/lib/azure/services/key-vault/main.d.ts +22 -2
  89. package/dist/src/lib/azure/services/key-vault/main.js +28 -3
  90. package/dist/src/lib/azure/services/key-vault/types.d.ts +3 -2
  91. package/dist/src/lib/azure/services/monitor/main.d.ts +3 -1
  92. package/dist/src/lib/azure/services/monitor/main.js +3 -2
  93. package/dist/src/lib/azure/services/operational-insights/main.d.ts +13 -2
  94. package/dist/src/lib/azure/services/operational-insights/main.js +17 -3
  95. package/dist/src/lib/azure/services/operational-insights/types.d.ts +3 -1
  96. package/dist/src/lib/azure/services/portal/error.d.ts +5 -0
  97. package/dist/src/lib/azure/services/portal/error.js +10 -0
  98. package/dist/src/lib/azure/services/portal/index.d.ts +4 -0
  99. package/dist/src/lib/azure/services/portal/index.js +4 -0
  100. package/dist/src/lib/azure/services/portal/main.d.ts +33 -0
  101. package/dist/src/lib/azure/services/portal/main.js +51 -0
  102. package/dist/src/lib/azure/services/portal/renderer.d.ts +11 -0
  103. package/dist/src/lib/azure/services/portal/renderer.js +156 -0
  104. package/dist/src/lib/azure/services/portal/types.d.ts +40 -0
  105. package/dist/src/lib/azure/services/portal/types.js +1 -0
  106. package/dist/src/lib/azure/services/redis/main.d.ts +4 -2
  107. package/dist/src/lib/azure/services/redis/main.js +3 -2
  108. package/dist/src/lib/azure/services/redis/types.d.ts +1 -1
  109. package/dist/src/lib/azure/services/resource-group/main.d.ts +10 -1
  110. package/dist/src/lib/azure/services/resource-group/main.js +17 -3
  111. package/dist/src/lib/azure/services/security-center/index.d.ts +2 -0
  112. package/dist/src/lib/azure/services/security-center/index.js +2 -0
  113. package/dist/src/lib/azure/services/security-center/main.d.ts +31 -0
  114. package/dist/src/lib/azure/services/security-center/main.js +33 -0
  115. package/dist/src/lib/azure/services/security-center/types.d.ts +3 -0
  116. package/dist/src/lib/azure/services/security-center/types.js +1 -0
  117. package/dist/src/lib/azure/services/servicebus/main.d.ts +28 -22
  118. package/dist/src/lib/azure/services/servicebus/main.js +31 -26
  119. package/dist/src/lib/azure/services/servicebus/types.d.ts +4 -4
  120. package/dist/src/lib/azure/services/storage/main.d.ts +26 -5
  121. package/dist/src/lib/azure/services/storage/main.js +51 -9
  122. package/dist/src/lib/azure/services/storage/types.d.ts +7 -2
  123. package/dist/src/lib/cloudflare/common/construct.js +1 -1
  124. package/dist/src/lib/cloudflare/common/stack.d.ts +2 -2
  125. package/dist/src/lib/cloudflare/common/stack.js +25 -25
  126. package/dist/src/lib/cloudflare/services/worker/main.js +8 -1
  127. package/dist/src/lib/cloudflare/services/worker/types.d.ts +1 -0
  128. package/package.json +26 -23
  129. package/src/lib/azure/common/constants.ts +83 -0
  130. package/src/lib/azure/common/construct.ts +50 -7
  131. package/src/lib/azure/common/stack.ts +26 -43
  132. package/src/lib/azure/common/types.ts +14 -2
  133. package/src/lib/azure/construct/event-handler/index.ts +2 -0
  134. package/src/lib/azure/construct/event-handler/main.ts +183 -0
  135. package/src/lib/azure/construct/event-handler/types.ts +49 -0
  136. package/src/lib/azure/construct/function-app/index.ts +2 -0
  137. package/src/lib/azure/construct/function-app/main.ts +410 -0
  138. package/src/lib/azure/construct/function-app/types.ts +45 -0
  139. package/src/lib/azure/construct/index.ts +6 -0
  140. package/src/lib/azure/construct/rest-api/index.ts +2 -0
  141. package/src/lib/azure/construct/rest-api/main.ts +205 -0
  142. package/src/lib/azure/construct/rest-api/types.ts +33 -0
  143. package/src/lib/azure/construct/rest-api-function/index.ts +2 -0
  144. package/src/lib/azure/construct/rest-api-function/main.ts +297 -0
  145. package/src/lib/azure/construct/rest-api-function/types.ts +39 -0
  146. package/src/lib/azure/construct/rest-api-with-cache/index.ts +2 -0
  147. package/src/lib/azure/construct/rest-api-with-cache/main.ts +75 -0
  148. package/src/lib/azure/construct/rest-api-with-cache/types.ts +15 -0
  149. package/src/lib/azure/construct/site-with-webapp/index.ts +2 -0
  150. package/src/lib/azure/construct/site-with-webapp/main.ts +160 -0
  151. package/src/lib/azure/construct/site-with-webapp/types.ts +33 -0
  152. package/src/lib/azure/index.ts +1 -0
  153. package/src/lib/azure/services/api-management/main.ts +168 -152
  154. package/src/lib/azure/services/api-management/types.ts +30 -1
  155. package/src/lib/azure/services/app-configuration/main.ts +29 -2
  156. package/src/lib/azure/services/app-service/main.ts +23 -4
  157. package/src/lib/azure/services/application-insights/main.ts +46 -7
  158. package/src/lib/azure/services/application-insights/types.ts +6 -2
  159. package/src/lib/azure/services/authorisation/constants.ts +13 -0
  160. package/src/lib/azure/services/authorisation/index.ts +3 -0
  161. package/src/lib/azure/services/authorisation/main.ts +202 -0
  162. package/src/lib/azure/services/authorisation/types.ts +3 -0
  163. package/src/lib/azure/services/cosmosdb/constants.ts +9 -0
  164. package/src/lib/azure/services/cosmosdb/index.ts +1 -0
  165. package/src/lib/azure/services/cosmosdb/main.ts +158 -8
  166. package/src/lib/azure/services/cosmosdb/types.ts +3 -0
  167. package/src/lib/azure/services/dns/main.ts +33 -8
  168. package/src/lib/azure/services/eventgrid/main.ts +41 -23
  169. package/src/lib/azure/services/function/main.ts +155 -9
  170. package/src/lib/azure/services/function/types.ts +3 -4
  171. package/src/lib/azure/services/index.ts +3 -0
  172. package/src/lib/azure/services/key-vault/main.ts +47 -4
  173. package/src/lib/azure/services/key-vault/types.ts +4 -4
  174. package/src/lib/azure/services/monitor/main.ts +5 -2
  175. package/src/lib/azure/services/operational-insights/main.ts +30 -4
  176. package/src/lib/azure/services/operational-insights/types.ts +3 -1
  177. package/src/lib/azure/services/portal/error.ts +12 -0
  178. package/src/lib/azure/services/portal/index.ts +4 -0
  179. package/src/lib/azure/services/portal/main.ts +81 -0
  180. package/src/lib/azure/services/portal/renderer.ts +182 -0
  181. package/src/lib/azure/services/portal/types.ts +45 -0
  182. package/src/lib/azure/services/redis/main.ts +10 -3
  183. package/src/lib/azure/services/redis/types.ts +1 -1
  184. package/src/lib/azure/services/resource-group/main.ts +34 -3
  185. package/src/lib/azure/services/security-center/index.ts +2 -0
  186. package/src/lib/azure/services/security-center/main.ts +42 -0
  187. package/src/lib/azure/services/security-center/types.ts +3 -0
  188. package/src/lib/azure/services/servicebus/main.ts +61 -30
  189. package/src/lib/azure/services/servicebus/types.ts +4 -4
  190. package/src/lib/azure/services/storage/main.ts +91 -9
  191. package/src/lib/azure/services/storage/types.ts +11 -2
  192. package/src/lib/cloudflare/common/construct.ts +1 -1
  193. package/src/lib/cloudflare/common/stack.ts +25 -25
  194. package/src/lib/cloudflare/services/worker/main.ts +10 -1
  195. package/src/lib/cloudflare/services/worker/types.ts +8 -1
  196. package/dist/lib/lambda.d.ts +0 -17
  197. package/dist/lib/lambda.d.ts.map +0 -1
  198. package/dist/lib/lambda.js +0 -28
  199. package/dist/lib/lambda.js.map +0 -1
  200. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,172 @@
1
+ import { HostnameType, LoggerType } from '@pulumi/azure-native/apimanagement/index.js';
2
+ import { getComponentOutput } from '@pulumi/azure-native/applicationinsights/index.js';
3
+ import { getVaultOutput } from '@pulumi/azure-native/keyvault/index.js';
4
+ import * as pulumi from '@pulumi/pulumi';
5
+ import { CommonAzureConstruct } from '../../common/index.js';
6
+ import { RoleDefinitionId } from '../../services/index.js';
7
+ export class AzureRestApi extends CommonAzureConstruct {
8
+ props;
9
+ api;
10
+ applicationInsights;
11
+ constructor(id, props) {
12
+ super(id, props);
13
+ this.props = props;
14
+ this.id = id;
15
+ }
16
+ initResources() {
17
+ this.createResourceGroup();
18
+ this.resolveApiKeyVault();
19
+ this.resolveCommonLogAnalyticsWorkspace();
20
+ this.resolveApplicationInsights();
21
+ this.createApiManagement();
22
+ this.createNamespaceSecretRole();
23
+ this.createNamespaceSecret();
24
+ this.createSubscriptionKeySecret();
25
+ this.createApiManagementLogger();
26
+ this.createApiDiagnostic();
27
+ this.createDiagnosticLog();
28
+ }
29
+ resolveApiKeyVault() {
30
+ this.api.authKeyVault = getVaultOutput({
31
+ vaultName: this.props.apiAuthKeyVault.name,
32
+ resourceGroupName: this.props.apiAuthKeyVault.resourceGroupName,
33
+ });
34
+ }
35
+ resolveApplicationInsights() {
36
+ if (!this.props.commonApplicationInsights || !this.props.commonApplicationInsights.resourceName)
37
+ return;
38
+ this.applicationInsights = getComponentOutput({
39
+ resourceName: this.props.commonApplicationInsights.resourceName,
40
+ resourceGroupName: this.props.commonApplicationInsights.resourceGroupName,
41
+ });
42
+ }
43
+ createApiManagement() {
44
+ if (this.props.apiManagement.useExistingApiManagement) {
45
+ if (this.props.apiManagement.apiStackName) {
46
+ const apiStack = new pulumi.StackReference(this.props.apiManagement.apiStackName);
47
+ this.api.id = apiStack.getOutput('apiId');
48
+ this.api.name = apiStack.getOutput('apiName');
49
+ this.api.resourceGroupName = apiStack.getOutput('apiResourceGroupName');
50
+ }
51
+ }
52
+ else {
53
+ let hostnameConfigurations;
54
+ if (this.props.apiManagement.certificateKeyVaultId) {
55
+ hostnameConfigurations = [
56
+ {
57
+ hostName: `api-${this.props.locationConfig?.[this.props.location].name}.${this.props.domainName}`,
58
+ keyVaultId: this.props.apiManagement.certificateKeyVaultId,
59
+ type: HostnameType.Management,
60
+ },
61
+ ];
62
+ }
63
+ this.api.apim = this.apiManagementManager.createApiManagementService(this.id, this, {
64
+ ...this.props.apiManagement,
65
+ serviceName: this.props.stackName,
66
+ location: this.resourceGroup.location,
67
+ resourceGroupName: this.resourceGroup.name,
68
+ hostnameConfigurations,
69
+ }, undefined, undefined, { protect: true });
70
+ this.api.id = this.api.apim.id;
71
+ this.api.name = this.api.apim.name;
72
+ this.api.resourceGroupName = this.resourceGroup.name;
73
+ if (this.props.apiManagement.certificateKeyVaultId) {
74
+ this.authorisationManager.createRoleAssignment(`${this.id}-kv-role`, this, {
75
+ principalId: this.api.apim.identity.apply(identity => identity?.principalId ?? ''),
76
+ roleDefinitionId: RoleDefinitionId.KEY_VAULT_CERTIFICATE_USER,
77
+ scope: this.props.apiManagement.certificateKeyVaultId,
78
+ });
79
+ }
80
+ }
81
+ this.registerOutputs({
82
+ apiId: this.api.id,
83
+ apiName: this.api.name,
84
+ apiResourceGroupName: this.api.resourceGroupName,
85
+ });
86
+ }
87
+ createNamespaceSecretRole() {
88
+ if (this.props.apiManagement.useExistingApiManagement)
89
+ return;
90
+ this.api.namedValueRoleAssignment = this.authorisationManager.createRoleAssignment(`${this.id}-key-vault-role-api-namespace`, this, {
91
+ principalId: this.api.apim.identity.apply(identity => identity?.principalId ?? ''),
92
+ roleDefinitionId: `/subscriptions/${this.props.subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/4633458b-17de-408a-b874-0445c86b69e6`,
93
+ scope: this.api.authKeyVault.id,
94
+ });
95
+ }
96
+ createNamespaceSecret() {
97
+ if (this.props.apiManagement.useExistingApiManagement)
98
+ return;
99
+ this.api.namedValueSecret = this.keyVaultManager.createKeyVaultSecret(`${this.id}-key-vault-api-namespace-secret`, this, {
100
+ vaultName: this.api.authKeyVault.name,
101
+ secretName: `${this.applicationInsights.name}-${this.props.stackName}-key`,
102
+ resourceGroupName: this.resourceGroup.name,
103
+ properties: {
104
+ value: this.applicationInsights.instrumentationKey,
105
+ },
106
+ });
107
+ }
108
+ createSubscriptionKeySecret() {
109
+ if (this.props.apiManagement.useExistingApiManagement)
110
+ return;
111
+ const apiManagementSubscription = this.apiManagementManager.createSubscription(this.id, this, {
112
+ serviceName: this.api.apim.name,
113
+ resourceGroupName: this.resourceGroup.name,
114
+ displayName: 'all-apis',
115
+ state: 'active',
116
+ allowTracing: false,
117
+ scope: '', // todo
118
+ });
119
+ this.keyVaultManager.createKeyVaultSecret(`${this.id}-key-vault-api-subscription-key-secret`, this, {
120
+ vaultName: this.api.authKeyVault.name,
121
+ secretName: `${this.props.stackName}-subscription-key`,
122
+ resourceGroupName: this.resourceGroup.name,
123
+ properties: {
124
+ value: apiManagementSubscription.primaryKey.apply(key => key ?? ''),
125
+ },
126
+ });
127
+ }
128
+ createApiManagementLogger() {
129
+ if (this.props.apiManagement.useExistingApiManagement)
130
+ return;
131
+ const apiAppNamedValue = this.apiManagementManager.createNamedValue(`${this.id}-am-nv`, this, {
132
+ displayName: this.applicationInsights.name,
133
+ resourceGroupName: this.resourceGroup.name,
134
+ serviceName: this.api.apim.name,
135
+ namedValueId: `${this.applicationInsights.name}-key`,
136
+ secret: true,
137
+ keyVault: {
138
+ secretIdentifier: this.api.namedValueSecret.id,
139
+ },
140
+ });
141
+ this.api.logger = this.apiManagementManager.createLogger(`${this.id}-am-logger`, this, {
142
+ resourceGroupName: this.resourceGroup.name,
143
+ serviceName: this.api.apim.name,
144
+ resourceId: this.applicationInsights.id,
145
+ loggerType: LoggerType.ApplicationInsights,
146
+ credentials: {
147
+ instrumentationKey: `{{${apiAppNamedValue.displayName}}}`,
148
+ },
149
+ });
150
+ }
151
+ createApiDiagnostic() {
152
+ if (this.props.apiManagement.useExistingApiManagement)
153
+ return;
154
+ this.apiManagementManager.createApiDiagnostic(`${this.id}-all-apis`, this, {
155
+ ...this.props.apiManagementDiagnostic,
156
+ apiId: this.api.apim.id,
157
+ resourceGroupName: this.resourceGroup.name,
158
+ serviceName: this.api.apim.name,
159
+ loggerId: this.api.logger.id,
160
+ });
161
+ }
162
+ createDiagnosticLog() {
163
+ if (this.props.apiManagement.useExistingApiManagement)
164
+ return;
165
+ this.monitorManager.createMonitorDiagnosticSettings(`${this.id}-apim-diagnostic`, this, {
166
+ ...this.props.apiManagementDiagnosticSettings,
167
+ name: `${this.props.stackName}-api-management`,
168
+ resourceUri: this.api.apim.id,
169
+ workspaceId: this.commonLogAnalyticsWorkspace.id,
170
+ });
171
+ }
172
+ }
@@ -0,0 +1,25 @@
1
+ import { ApiManagementService, Logger } from '@pulumi/azure-native/apimanagement/index.js';
2
+ import { RoleAssignment } from '@pulumi/azure-native/authorization/index.js';
3
+ import { GetVaultResult, Secret } from '@pulumi/azure-native/keyvault/index.js';
4
+ import { Input, Output } from '@pulumi/pulumi';
5
+ import { ApiDiagnosticProps, ApiManagementProps, CommonAzureStackProps, MonitorDiagnosticSettingProps } from '../../index.js';
6
+ export interface ApiAuthKeyVault {
7
+ name: string;
8
+ resourceGroupName: string;
9
+ }
10
+ export interface AzureRestApiProps extends CommonAzureStackProps {
11
+ apiAuthKeyVault: ApiAuthKeyVault;
12
+ apiManagement: ApiManagementProps;
13
+ apiManagementDiagnostic: ApiDiagnosticProps;
14
+ apiManagementDiagnosticSettings: MonitorDiagnosticSettingProps;
15
+ }
16
+ export interface AzureApi {
17
+ id: Input<string>;
18
+ name: Input<string>;
19
+ resourceGroupName: Input<string>;
20
+ authKeyVault: Output<GetVaultResult>;
21
+ apim: ApiManagementService;
22
+ namedValueSecret: Secret;
23
+ namedValueRoleAssignment: RoleAssignment;
24
+ logger: Logger;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,19 @@
1
+ import { ApiManagementApiOperationProps } from '../../services/index.js';
2
+ import { AzureFunctionApp } from '../function-app/index.js';
3
+ import { AzureApiFunction, AzureRestApiFunctionProps } from './types.js';
4
+ export declare class AzureRestApiFunction extends AzureFunctionApp {
5
+ props: AzureRestApiFunctionProps;
6
+ api: AzureApiFunction;
7
+ constructor(id: string, props: AzureRestApiFunctionProps);
8
+ initResources(): void;
9
+ protected resolveApiKeyVault(): void;
10
+ protected createNamespaceSecret(): void;
11
+ protected createApiManagement(): void;
12
+ protected createApiManagementNamespace(): void;
13
+ protected createApiManagementRoutes(): void;
14
+ protected createApiOperation(operation: ApiManagementApiOperationProps): void;
15
+ protected createApiOperationCachePolicy(operation: ApiManagementApiOperationProps): void;
16
+ protected createCorsPolicy(): void;
17
+ protected createApiPolicy(): void;
18
+ protected dashboardVariables(): Record<string, any>;
19
+ }
@@ -0,0 +1,255 @@
1
+ import { HostnameType, NamedValue } from '@pulumi/azure-native/apimanagement/index.js';
2
+ import { getVaultOutput } from '@pulumi/azure-native/keyvault/index.js';
3
+ import { listWebAppHostKeysOutput } from '@pulumi/azure-native/web/index.js';
4
+ import * as pulumi from '@pulumi/pulumi';
5
+ import _ from 'lodash';
6
+ import { RoleDefinitionId } from '../../services/index.js';
7
+ import { AzureFunctionApp } from '../function-app/index.js';
8
+ export class AzureRestApiFunction extends AzureFunctionApp {
9
+ props;
10
+ api;
11
+ constructor(id, props) {
12
+ super(id, props);
13
+ this.props = props;
14
+ this.id = id;
15
+ }
16
+ initResources() {
17
+ this.createResourceGroup();
18
+ this.resolveCommonLogAnalyticsWorkspace();
19
+ this.resolveApplicationInsights();
20
+ this.createAppServicePlan();
21
+ this.createdParsedAppConfigurations();
22
+ this.createAppConfiguration();
23
+ this.createAppConfigurations();
24
+ this.createStorageAccount();
25
+ this.createStorageDeploymentContainer();
26
+ this.createStorageContainer();
27
+ this.createDataStorageAccount();
28
+ this.createDataStorageContainer();
29
+ this.generateStorageContainerSas();
30
+ this.createFunctionHosts();
31
+ this.createCodePackage();
32
+ this.createFunctionAppSiteConfig();
33
+ this.createFunctionApp();
34
+ this.createRoleAssignments();
35
+ this.resolveApiKeyVault();
36
+ this.createNamespaceSecret();
37
+ this.createApiManagement();
38
+ this.createApiManagementNamespace();
39
+ this.createApiManagementRoutes();
40
+ this.createCorsPolicy();
41
+ this.createFunctionDashboard();
42
+ }
43
+ resolveApiKeyVault() {
44
+ this.api.authKeyVault = getVaultOutput({
45
+ vaultName: this.props.apiAuthKeyVault.name,
46
+ resourceGroupName: this.props.apiAuthKeyVault.resourceGroupName,
47
+ });
48
+ }
49
+ createNamespaceSecret() {
50
+ if (!this.props.apiManagement.useExistingApiManagement)
51
+ return;
52
+ const functionDefaultKey = listWebAppHostKeysOutput({
53
+ name: this.app.name,
54
+ resourceGroupName: this.resourceGroup.name,
55
+ });
56
+ this.api.namedValueSecret = this.keyVaultManager.createKeyVaultSecret(`${this.id}-key-vault-api-namespace-secret`, this, {
57
+ vaultName: this.api.authKeyVault.name,
58
+ secretName: pulumi.interpolate `${this.app.name}key`,
59
+ resourceGroupName: this.resourceGroup.name,
60
+ properties: {
61
+ value: functionDefaultKey.functionKeys?.apply(keys => keys?.['default'] ?? ''),
62
+ },
63
+ });
64
+ }
65
+ createApiManagement() {
66
+ if (this.props.apiManagement.useExistingApiManagement) {
67
+ if (this.props.apiManagement.apiStackName) {
68
+ const apiStack = new pulumi.StackReference(this.props.apiManagement.apiStackName);
69
+ this.api.id = apiStack.getOutput('apiId');
70
+ this.api.name = apiStack.getOutput('apiName');
71
+ this.api.resourceGroupName = apiStack.getOutput('apiResourceGroupName');
72
+ }
73
+ }
74
+ else {
75
+ let hostnameConfigurations;
76
+ if (this.props.apiManagement.certificateKeyVaultId) {
77
+ hostnameConfigurations = [
78
+ {
79
+ hostName: `api-${this.props.locationConfig?.[this.props.location].name}.${this.props.domainName}`,
80
+ keyVaultId: this.props.apiManagement.certificateKeyVaultId,
81
+ type: HostnameType.Management,
82
+ },
83
+ ];
84
+ }
85
+ this.api.apim = this.apiManagementManager.createApiManagementService(this.id, this, {
86
+ ...this.props.apiManagement,
87
+ serviceName: this.props.stackName,
88
+ location: this.resourceGroup.location,
89
+ resourceGroupName: this.resourceGroup.name,
90
+ hostnameConfigurations,
91
+ }, undefined, undefined, { protect: true });
92
+ this.api.id = this.api.apim.id;
93
+ this.api.name = this.api.apim.name;
94
+ this.api.resourceGroupName = this.resourceGroup.name;
95
+ if (this.props.apiManagement.certificateKeyVaultId) {
96
+ this.authorisationManager.createRoleAssignment(`${this.id}-kv-role`, this, {
97
+ principalId: this.api.apim.identity.apply(identity => identity?.principalId ?? ''),
98
+ roleDefinitionId: RoleDefinitionId.KEY_VAULT_CERTIFICATE_USER,
99
+ scope: this.props.apiManagement.certificateKeyVaultId,
100
+ });
101
+ }
102
+ }
103
+ }
104
+ createApiManagementNamespace() {
105
+ this.api.namedValue = new NamedValue(`${this.id}-am-nv`, {
106
+ displayName: this.app.name,
107
+ keyVault: {
108
+ secretIdentifier: this.api.namedValueSecret.id,
109
+ },
110
+ resourceGroupName: this.api.resourceGroupName,
111
+ secret: true,
112
+ serviceName: this.api.name,
113
+ });
114
+ this.api.backend = this.apiManagementManager.createBackend(this.id, this, {
115
+ ...this.props.apiManagementBackend,
116
+ title: this.props.stackName,
117
+ resourceGroupName: this.api.resourceGroupName,
118
+ serviceName: this.api.name,
119
+ url: pulumi.interpolate `https://${this.app.name}.azurewebsites.net/${this.props.apiManagementBackend.backendUrlPath}`,
120
+ resourceId: pulumi.interpolate `https://management.azure.com/subscriptions/${this.props.subscriptionId}/resourceGroups/${this.resourceGroup.name}/providers/Microsoft.Web/sites/${this.app.name}`,
121
+ credentials: {
122
+ header: {
123
+ 'x-functions-key': [`{{${this.api.namedValue.name}}}`],
124
+ },
125
+ },
126
+ });
127
+ }
128
+ createApiManagementRoutes() {
129
+ this.api.managementApi = this.apiManagementManager.createApi(`${this.id}-apim-api`, this, {
130
+ ...this.props.apiManagementApi,
131
+ displayName: this.props.apiManagementApi.displayName ?? this.props.stackName,
132
+ serviceName: this.api.name,
133
+ resourceGroupName: this.api.resourceGroupName,
134
+ isCurrent: this.props.apiManagementApi.isCurrent ?? true,
135
+ protocols: this.props.apiManagementApi.protocols ?? ['https'],
136
+ });
137
+ _.forEach(this.props.apiManagementApi.operations, operation => {
138
+ this.createApiOperation(operation);
139
+ this.createApiOperationCachePolicy(operation);
140
+ });
141
+ }
142
+ createApiOperation(operation) {
143
+ this.api.apiOperations[operation.displayName.toString()] = this.apiManagementManager.createOperation(`${this.id}-apim-api-apim-api-operation-${operation.displayName}-${operation.method}`, this, {
144
+ operationId: `${operation.displayName}-${operation.method}`,
145
+ method: operation.method.toString().toUpperCase(),
146
+ serviceName: this.api.name,
147
+ resourceGroupName: this.api.resourceGroupName,
148
+ apiId: this.api.id,
149
+ displayName: operation.displayName,
150
+ urlTemplate: operation.urlTemplate,
151
+ templateParameters: operation.templateParameters,
152
+ });
153
+ }
154
+ createApiOperationCachePolicy(operation) {
155
+ if (!operation.caching || !operation.caching.enableCacheSet)
156
+ return;
157
+ this.apiManagementManager.createOperationPolicy(`${this.id}-apim-api-operation-policy-${operation.displayName}-${operation.method}`, this, {
158
+ apiId: this.api.id,
159
+ resourceGroupName: this.api.resourceGroupName,
160
+ serviceName: this.api.name,
161
+ operationId: `${operation.displayName}-${operation.method}`,
162
+ value: `
163
+ <policies>
164
+ <policies>
165
+ <inbound>
166
+ <base />
167
+ ${this.props.apiManagementApi.cacheSetInboundPolicy}
168
+ </inbound>
169
+ <backend>
170
+ <base />
171
+ </backend>
172
+ <outbound>
173
+ <base />
174
+ ${this.props.apiManagementApi.cacheSetOutboundPolicy}
175
+ </outbound>
176
+ <on-error>
177
+ <base />
178
+ </on-error>
179
+ </policies>`.replace(/\n[ \t]*\n/g, '\n'), // move to utils
180
+ });
181
+ }
182
+ createCorsPolicy() {
183
+ if (!this.props.apiManagementCors?.enableCors)
184
+ return;
185
+ const allowedOrigins = [];
186
+ if (this.props.apiManagementCors.allowedOrigins) {
187
+ _.forEach(this.props.apiManagementCors.allowedOrigins, (origin) => {
188
+ allowedOrigins.push(`<origin>${origin}</origin>`);
189
+ });
190
+ }
191
+ else if (this.props.apiManagementCors.originSubdomain) {
192
+ _.forEach(this.props.locales, (locale) => {
193
+ allowedOrigins.push(`<origin>https://${this.props.apiManagementCors?.originSubdomain}-${locale}.${this.props.domainName}</origin>`);
194
+ });
195
+ }
196
+ const allowedHeaders = [];
197
+ _.forEach(this.props.apiManagementCors.allowedHeaders, (header) => {
198
+ allowedHeaders.push(`<header>${header}</header>`);
199
+ });
200
+ const allowedMethods = [];
201
+ _.forEach(this.props.apiManagementCors.allowedMethods, (method) => {
202
+ allowedMethods.push(`<method>${method}</method>`);
203
+ });
204
+ this.api.corsPolicyXmlContent = `
205
+ <cors allow-credentials="${this.props.apiManagementCors.allowCredentials}">
206
+ <allowed-origins>
207
+ ${allowedOrigins.toString().replaceAll(',', '')}
208
+ </allowed-origins>
209
+ <allowed-methods>
210
+ ${allowedMethods.toString().replaceAll(',', '')}
211
+ </allowed-methods>
212
+ <allowed-headers>
213
+ ${allowedHeaders.toString().replaceAll(',', '')}
214
+ </allowed-headers>
215
+ </cors>`.replace(/\n[ \t]*\n/g, '\n'); // move to utils
216
+ }
217
+ createApiPolicy() {
218
+ const policyXmlContent = pulumi.interpolate `
219
+ <policies>
220
+ <inbound>
221
+ <base />
222
+ ${this.api.corsPolicyXmlContent ?? ''}
223
+ <set-backend-service backend-id="${this.api.backend.name}" />
224
+ <set-header name="traceparent" exists-action="override">
225
+ <value>@(context.Request.Headers.GetValueOrDefault("traceparent", ""))</value>
226
+ </set-header>
227
+ </inbound>
228
+ <backend>
229
+ <base />
230
+ </backend>
231
+ <outbound>
232
+ <base />
233
+ <set-header name="traceparent" exists-action="override">
234
+ <value>@(context.Request.Headers.GetValueOrDefault("traceparent", ""))</value>
235
+ </set-header>
236
+ </outbound>
237
+ <on-error>
238
+ <base />
239
+ </on-error>
240
+ </policies>`;
241
+ this.apiManagementManager.createPolicy(`${this.id}-apim-api-policy`, this, {
242
+ serviceName: this.api.name,
243
+ apiId: this.api.id,
244
+ resourceGroupName: this.api.resourceGroupName,
245
+ value: policyXmlContent.apply(xml => xml.replace(/\n[ \t]*\n/g, '\n')),
246
+ });
247
+ }
248
+ dashboardVariables() {
249
+ const variables = super.dashboardVariables();
250
+ return {
251
+ ...variables,
252
+ apimName: this.api.name,
253
+ };
254
+ }
255
+ }
@@ -0,0 +1,29 @@
1
+ import { Api, ApiOperation, Backend, NamedValue } from '@pulumi/azure-native/apimanagement/index.js';
2
+ import { ApiManagementApiProps, ApiManagementBackendProps, ApiManagementProps, ApplicationInsightsProps, AzureApi, AzureFunctionAppProps, AzureRestApiProps } from '../../index.js';
3
+ export interface ApiManagementRestApiProps extends ApiManagementProps {
4
+ useExistingApiManagement: boolean;
5
+ }
6
+ export interface ApiManagementCors {
7
+ enableCors: boolean;
8
+ allowCredentials: boolean;
9
+ allowedMethods: string[];
10
+ allowedHeaders: string[];
11
+ allowedOrigins?: string[];
12
+ originSubdomain?: string;
13
+ }
14
+ export interface AzureRestApiFunctionProps extends AzureRestApiProps, AzureFunctionAppProps {
15
+ apiManagementBackend: ApiManagementBackendProps;
16
+ apiManagementApi: ApiManagementApiProps;
17
+ apiManagementApplicationInsights?: ApplicationInsightsProps;
18
+ apiManagement: ApiManagementRestApiProps;
19
+ apiManagementCors?: ApiManagementCors;
20
+ }
21
+ export interface AzureApiFunction extends AzureApi {
22
+ corsPolicyXmlContent?: string;
23
+ apiOperations: {
24
+ [operation: string]: ApiOperation;
25
+ };
26
+ managementApi: Api;
27
+ backend: Backend;
28
+ namedValue: NamedValue;
29
+ }
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,12 @@
1
+ import { AzureRestApi } from '../rest-api/main.js';
2
+ import { AzureApiWithCache, AzureRestApiWithCacheProps } from './types.js';
3
+ export declare class AzureRestApiWithCache extends AzureRestApi {
4
+ props: AzureRestApiWithCacheProps;
5
+ api: AzureApiWithCache;
6
+ constructor(id: string, props: AzureRestApiWithCacheProps);
7
+ initResources(): void;
8
+ protected createRedisCache(): void;
9
+ protected createRedisCacheSecret(): void;
10
+ protected createRedisCacheNamespace(): void;
11
+ protected createRedisCacheApiManagement(): void;
12
+ }
@@ -0,0 +1,56 @@
1
+ import { AzureRestApi } from '../rest-api/main.js';
2
+ export class AzureRestApiWithCache extends AzureRestApi {
3
+ props;
4
+ constructor(id, props) {
5
+ super(id, props);
6
+ this.props = props;
7
+ this.id = id;
8
+ }
9
+ initResources() {
10
+ super.initResources();
11
+ this.createRedisCache();
12
+ this.createRedisCacheSecret();
13
+ this.createRedisCacheNamespace();
14
+ this.createRedisCacheApiManagement();
15
+ }
16
+ createRedisCache() {
17
+ this.api.redis = this.redisManager.createManagedRedis(this.id, this, {
18
+ ...this.props.apiManagementManagedRedis,
19
+ name: this.props.stackName,
20
+ location: this.resourceGroup.location,
21
+ resourceGroupName: this.resourceGroup.name,
22
+ }, { ignoreChanges: ['location'] });
23
+ }
24
+ createRedisCacheSecret() {
25
+ this.api.redisNamedValueSecret = this.keyVaultManager.createKeyVaultSecret(`${this.id}-key-vault-redis-namespace-secret`, this, {
26
+ vaultName: this.api.authKeyVault.name,
27
+ secretName: `${this.api.redis.name}key`,
28
+ resourceGroupName: this.resourceGroup.name,
29
+ properties: {
30
+ value: `${this.api.redis.name}:10000,password=${this.api.redis.accessKeys.primaryKey},ssl=True,abortConnect=False`,
31
+ },
32
+ }, { dependsOn: [this.api.redis, this.api.namedValueRoleAssignment] });
33
+ }
34
+ createRedisCacheNamespace() {
35
+ this.api.redisNamedValue = this.apiManagementManager.createNamedValue(`${this.id}-redis-nv`, this, {
36
+ displayName: `${this.api.redis.name}key`,
37
+ resourceGroupName: this.resourceGroup.name,
38
+ serviceName: this.api.apim.name,
39
+ namedValueId: `${this.api.redis.name}key`,
40
+ secret: true,
41
+ keyVault: {
42
+ secretIdentifier: this.api.redisNamedValueSecret.id,
43
+ },
44
+ });
45
+ }
46
+ createRedisCacheApiManagement() {
47
+ this.apiManagementManager.createCache(`${this.id}-am-redis-cache`, this, {
48
+ serviceName: this.api.apim.name,
49
+ connectionString: `{{${this.api.redisNamedValue.name}}}`,
50
+ cacheId: this.api.redis.id,
51
+ resourceGroupName: this.resourceGroup.name,
52
+ useFromLocation: this.api.redis.location,
53
+ description: `Redis cache for ${this.api.apim.name}`,
54
+ });
55
+ }
56
+ }
@@ -0,0 +1,13 @@
1
+ import { NamedValue } from '@pulumi/azure-native/apimanagement/index.js';
2
+ import { Secret } from '@pulumi/azure-native/keyvault/index.js';
3
+ import { Redis } from '@pulumi/azure-native/redis/index.js';
4
+ import { RedisProps } from '../../index.js';
5
+ import { AzureApi, AzureRestApiProps } from '../index.js';
6
+ export interface AzureRestApiWithCacheProps extends AzureRestApiProps {
7
+ apiManagementManagedRedis: RedisProps;
8
+ }
9
+ export interface AzureApiWithCache extends AzureApi {
10
+ redis: Redis;
11
+ redisNamedValueSecret: Secret;
12
+ redisNamedValue: NamedValue;
13
+ }
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,19 @@
1
+ import { GetComponentResult } from '@pulumi/azure-native/applicationinsights/index.js';
2
+ import { Output, ResourceOptions } from '@pulumi/pulumi';
3
+ import { CommonAzureConstruct } from '../../common/index.js';
4
+ import { Site, SiteWithWebAppProps } from './types.js';
5
+ export declare class SiteWithWebApp extends CommonAzureConstruct {
6
+ props: SiteWithWebAppProps;
7
+ applicationInsights: Output<GetComponentResult>;
8
+ site: Site;
9
+ constructor(id: string, props: SiteWithWebAppProps);
10
+ initResources(): void;
11
+ protected resolveApplicationInsights(): void;
12
+ protected createSiteAppServicePlan(): void;
13
+ protected createSiteStorageAccount(): void;
14
+ protected createSiteStorageContainer(): void;
15
+ protected createCodePackage(): void;
16
+ protected createWebAppSiteConfig(): void;
17
+ protected createWebApp(resourceOptions?: ResourceOptions): void;
18
+ protected createDiagnosticLog(): void;
19
+ }