@gradientedge/cdk-utils 9.89.0 → 10.1.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.
- package/dist/src/lib/cloudflare/common/construct.d.ts +7 -19
- package/dist/src/lib/cloudflare/common/construct.js +12 -66
- package/dist/src/lib/cloudflare/common/index.d.ts +0 -1
- package/dist/src/lib/cloudflare/common/index.js +0 -1
- package/dist/src/lib/cloudflare/common/stack.d.ts +11 -21
- package/dist/src/lib/cloudflare/common/stack.js +55 -62
- package/dist/src/lib/cloudflare/common/types.d.ts +2 -14
- package/dist/src/lib/cloudflare/construct/pages-static-site/main.d.ts +8 -10
- package/dist/src/lib/cloudflare/construct/pages-static-site/main.js +18 -25
- package/dist/src/lib/cloudflare/construct/worker-site/main.d.ts +13 -10
- package/dist/src/lib/cloudflare/construct/worker-site/main.js +29 -41
- package/dist/src/lib/cloudflare/index.d.ts +0 -1
- package/dist/src/lib/cloudflare/index.js +0 -1
- package/dist/src/lib/cloudflare/services/access/main.d.ts +31 -43
- package/dist/src/lib/cloudflare/services/access/main.js +56 -83
- package/dist/src/lib/cloudflare/services/access/types.d.ts +12 -22
- package/dist/src/lib/cloudflare/services/api-shield/main.d.ts +10 -15
- package/dist/src/lib/cloudflare/services/api-shield/main.js +16 -36
- package/dist/src/lib/cloudflare/services/api-shield/types.d.ts +6 -10
- package/dist/src/lib/cloudflare/services/argo/main.d.ts +6 -8
- package/dist/src/lib/cloudflare/services/argo/main.js +9 -17
- package/dist/src/lib/cloudflare/services/argo/types.d.ts +3 -4
- package/dist/src/lib/cloudflare/services/filter/main.d.ts +3 -4
- package/dist/src/lib/cloudflare/services/filter/main.js +6 -10
- package/dist/src/lib/cloudflare/services/filter/types.d.ts +2 -2
- package/dist/src/lib/cloudflare/services/firewall/main.d.ts +2 -3
- package/dist/src/lib/cloudflare/services/firewall/main.js +4 -8
- package/dist/src/lib/cloudflare/services/firewall/types.d.ts +2 -2
- package/dist/src/lib/cloudflare/services/page/main.d.ts +7 -11
- package/dist/src/lib/cloudflare/services/page/main.js +13 -26
- package/dist/src/lib/cloudflare/services/page/types.d.ts +4 -6
- package/dist/src/lib/cloudflare/services/record/main.d.ts +2 -3
- package/dist/src/lib/cloudflare/services/record/main.js +4 -8
- package/dist/src/lib/cloudflare/services/record/types.d.ts +2 -2
- package/dist/src/lib/cloudflare/services/rule-set/main.d.ts +5 -6
- package/dist/src/lib/cloudflare/services/rule-set/main.js +7 -10
- package/dist/src/lib/cloudflare/services/rule-set/types.d.ts +2 -2
- package/dist/src/lib/cloudflare/services/worker/main.d.ts +12 -18
- package/dist/src/lib/cloudflare/services/worker/main.js +15 -39
- package/dist/src/lib/cloudflare/services/worker/types.d.ts +7 -12
- package/dist/src/lib/cloudflare/services/zone/main.d.ts +13 -30
- package/dist/src/lib/cloudflare/services/zone/main.js +31 -84
- package/dist/src/lib/cloudflare/services/zone/types.d.ts +10 -20
- package/dist/src/lib/common/types.d.ts +4 -0
- package/package.json +29 -23
- package/src/lib/cloudflare/common/construct.ts +13 -70
- package/src/lib/cloudflare/common/index.ts +0 -1
- package/src/lib/cloudflare/common/stack.ts +58 -69
- package/src/lib/cloudflare/common/types.ts +2 -15
- package/src/lib/cloudflare/construct/pages-static-site/main.ts +22 -42
- package/src/lib/cloudflare/construct/worker-site/main.ts +38 -62
- package/src/lib/cloudflare/index.ts +0 -1
- package/src/lib/cloudflare/services/access/main.ts +57 -118
- package/src/lib/cloudflare/services/access/types.ts +24 -22
- package/src/lib/cloudflare/services/api-shield/main.ts +16 -63
- package/src/lib/cloudflare/services/api-shield/types.ts +12 -10
- package/src/lib/cloudflare/services/argo/main.ts +9 -23
- package/src/lib/cloudflare/services/argo/types.ts +3 -4
- package/src/lib/cloudflare/services/filter/main.ts +6 -13
- package/src/lib/cloudflare/services/filter/types.ts +2 -2
- package/src/lib/cloudflare/services/firewall/main.ts +4 -11
- package/src/lib/cloudflare/services/firewall/types.ts +2 -2
- package/src/lib/cloudflare/services/page/main.ts +19 -36
- package/src/lib/cloudflare/services/page/types.ts +4 -6
- package/src/lib/cloudflare/services/record/main.ts +4 -11
- package/src/lib/cloudflare/services/record/types.ts +2 -2
- package/src/lib/cloudflare/services/rule-set/main.ts +7 -12
- package/src/lib/cloudflare/services/rule-set/types.ts +2 -2
- package/src/lib/cloudflare/services/worker/main.ts +15 -52
- package/src/lib/cloudflare/services/worker/types.ts +14 -12
- package/src/lib/cloudflare/services/zone/main.ts +40 -103
- package/src/lib/cloudflare/services/zone/types.ts +20 -21
- package/src/lib/common/types.ts +5 -0
- package/dist/src/lib/cloudflare/common/constants.d.ts +0 -5
- package/dist/src/lib/cloudflare/common/constants.js +0 -6
- package/dist/src/lib/cloudflare/utils/index.d.ts +0 -3
- package/dist/src/lib/cloudflare/utils/index.js +0 -13
- package/src/lib/cloudflare/common/constants.ts +0 -5
- package/src/lib/cloudflare/utils/index.ts +0 -23
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CommonCloudflareConstruct } from './construct.js'
|
|
3
|
-
import { CommonCloudflareStackProps } from './types.js'
|
|
4
|
-
|
|
1
|
+
import { ComponentResource, ComponentResourceOptions, Config } from '@pulumi/pulumi'
|
|
5
2
|
import appRoot from 'app-root-path'
|
|
6
|
-
import
|
|
7
|
-
import { Construct } from 'constructs'
|
|
3
|
+
import fs from 'fs'
|
|
8
4
|
import _ from 'lodash'
|
|
9
5
|
import path from 'path'
|
|
10
6
|
import { isDevStage } from '../../common/index.js'
|
|
7
|
+
import { CommonCloudflareConstruct } from './construct.js'
|
|
8
|
+
import { CommonCloudflareStackProps } from './types.js'
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* @classdesc Common stack to use as a base for all higher level constructs.
|
|
@@ -21,57 +19,62 @@ import { isDevStage } from '../../common/index.js'
|
|
|
21
19
|
* }
|
|
22
20
|
* }
|
|
23
21
|
*/
|
|
24
|
-
export class CommonCloudflareStack extends
|
|
22
|
+
export class CommonCloudflareStack extends ComponentResource {
|
|
25
23
|
construct: CommonCloudflareConstruct
|
|
26
24
|
props: CommonCloudflareStackProps
|
|
25
|
+
config: Config
|
|
27
26
|
|
|
28
|
-
constructor(
|
|
29
|
-
super(
|
|
30
|
-
|
|
31
|
-
/* determine extra cdk contexts */
|
|
32
|
-
this.determineExtraContexts()
|
|
33
|
-
|
|
34
|
-
/* determine extra cdk stage contexts */
|
|
35
|
-
this.determineStageContexts()
|
|
27
|
+
constructor(name: string, props: CommonCloudflareStackProps, options?: ComponentResourceOptions) {
|
|
28
|
+
super(`custom:cloudflare:Stack:${name}`, name, props, options)
|
|
36
29
|
|
|
30
|
+
/* initialise config */
|
|
31
|
+
this.config = new Config()
|
|
37
32
|
this.props = this.determineConstructProps(props)
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
/**
|
|
41
|
-
* @summary Method to determine the core CDK construct properties injected via context
|
|
36
|
+
* @summary Method to determine the core CDK construct properties injected via context
|
|
42
37
|
* @param props The stack properties
|
|
43
38
|
* @returns The stack properties
|
|
44
39
|
*/
|
|
45
40
|
protected determineConstructProps(props: CommonCloudflareStackProps) {
|
|
46
|
-
|
|
41
|
+
let projectProps: CommonCloudflareStackProps = props
|
|
42
|
+
if (!projectProps) {
|
|
43
|
+
const projectPropsPath = path.join(appRoot.path, 'pulumi.json')
|
|
44
|
+
if (!fs.existsSync(projectPropsPath)) throw `Context properties unavailable in path:${projectPropsPath}`
|
|
45
|
+
|
|
46
|
+
const projectPropsBuffer = fs.readFileSync(projectPropsPath)
|
|
47
|
+
projectProps = JSON.parse(projectPropsBuffer.toString('utf-8'))
|
|
48
|
+
}
|
|
49
|
+
|
|
47
50
|
return {
|
|
48
|
-
accountId:
|
|
49
|
-
apiToken:
|
|
50
|
-
domainName:
|
|
51
|
-
extraContexts:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
subDomain:
|
|
51
|
+
accountId: projectProps.accountId,
|
|
52
|
+
apiToken: projectProps.apiToken,
|
|
53
|
+
domainName: projectProps.domainName,
|
|
54
|
+
extraContexts: projectProps.extraContexts,
|
|
55
|
+
name: projectProps.resourceGroupName ?? projectProps.name,
|
|
56
|
+
skipStageForARecords: projectProps.skipStageForARecords,
|
|
57
|
+
stage: projectProps.stage,
|
|
58
|
+
stageContextPath: projectProps.stageContextPath,
|
|
59
|
+
subDomain: projectProps.subDomain,
|
|
60
|
+
...this.determineExtraContexts(props),
|
|
61
|
+
...this.determineStageContexts(props),
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
/**
|
|
61
|
-
* @summary Method to determine extra cdk contexts apart from the main
|
|
66
|
+
* @summary Method to determine extra cdk contexts apart from the main context
|
|
62
67
|
* - Sets the properties from the extra contexts into cdk node context
|
|
63
68
|
* - Primary use is to have layered config in separate files to enable easier maintenance and readability
|
|
64
69
|
*/
|
|
65
|
-
protected determineExtraContexts() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (!extraContexts) {
|
|
70
|
-
if (debug) console.debug(`No additional contexts provided. Using default context properties from cdktf.json`)
|
|
71
|
-
return
|
|
70
|
+
protected determineExtraContexts(props: CommonCloudflareStackProps) {
|
|
71
|
+
if (!props.extraContexts) {
|
|
72
|
+
if (props.debug) console.debug(`No additional contexts provided. Using default context properties`)
|
|
73
|
+
return {}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
let extraContextProps: Record<string, any> = {}
|
|
77
|
+
_.forEach(props.extraContexts, (context: string) => {
|
|
75
78
|
const extraContextPath = path.join(appRoot.path, context)
|
|
76
79
|
|
|
77
80
|
/* scenario where extra context is configured in cdk.json but absent in file system */
|
|
@@ -79,65 +82,51 @@ export class CommonCloudflareStack extends TerraformStack {
|
|
|
79
82
|
|
|
80
83
|
/* read the extra properties */
|
|
81
84
|
const extraContextPropsBuffer = fs.readFileSync(extraContextPath)
|
|
82
|
-
if (debug) console.debug(`Adding additional contexts provided in ${extraContextPath}`)
|
|
85
|
+
if (props.debug) console.debug(`Adding additional contexts provided in ${extraContextPath}`)
|
|
83
86
|
|
|
84
87
|
/* parse as JSON properties */
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.node.setContext(propKey, extraContextProps[propKey])
|
|
90
|
-
})
|
|
88
|
+
extraContextProps = {
|
|
89
|
+
...extraContextProps,
|
|
90
|
+
...JSON.parse(extraContextPropsBuffer.toString('utf-8')),
|
|
91
|
+
}
|
|
91
92
|
})
|
|
93
|
+
return extraContextProps
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
/**
|
|
95
|
-
* @summary Method to determine extra cdk stage contexts apart from the main
|
|
97
|
+
* @summary Method to determine extra cdk stage contexts apart from the main context
|
|
96
98
|
* - Sets the properties from the extra stage contexts into cdk node context
|
|
97
99
|
* - Primary use is to have layered config for each environment which is injected into the context
|
|
98
100
|
*/
|
|
99
|
-
protected determineStageContexts() {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (isDevStage(stage)) {
|
|
106
|
-
if (debug) console.debug(`Development stage. Using default stage context properties`)
|
|
101
|
+
protected determineStageContexts(props: CommonCloudflareStackProps) {
|
|
102
|
+
const stageContextFilePath = path.join(appRoot.path, props.stageContextPath ?? 'cdkEnv', `${props.stage}.json`)
|
|
103
|
+
|
|
104
|
+
if (isDevStage(props.stage)) {
|
|
105
|
+
if (props.debug) console.debug(`Development stage. Using default stage context properties`)
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
/* alert default context usage when extra stage config is missing */
|
|
110
109
|
if (!fs.existsSync(stageContextFilePath)) {
|
|
111
|
-
if (debug) console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`)
|
|
112
|
-
if (debug) console.debug(`Using default stage context properties for ${stage} stage`)
|
|
113
|
-
return
|
|
110
|
+
if (props.debug) console.debug(`Stage specific context properties unavailable in path:${stageContextFilePath}`)
|
|
111
|
+
if (props.debug) console.debug(`Using default stage context properties for ${props.stage} stage`)
|
|
112
|
+
return {}
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
/* read the extra properties */
|
|
117
116
|
const stageContextPropsBuffer = fs.readFileSync(stageContextFilePath)
|
|
118
|
-
if (debug) console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`)
|
|
117
|
+
if (props.debug) console.debug(`Adding additional stage contexts provided in ${stageContextFilePath}`)
|
|
119
118
|
|
|
120
119
|
/* parse as JSON properties */
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
/* set each of the property into the cdk node context */
|
|
124
|
-
_.keys(stageContextProps).forEach((propKey: any) => {
|
|
125
|
-
/* handle object, array properties */
|
|
126
|
-
if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
|
|
127
|
-
this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]))
|
|
128
|
-
} else {
|
|
129
|
-
/* handle all other primitive properties */
|
|
130
|
-
this.node.setContext(propKey, stageContextProps[propKey])
|
|
131
|
-
}
|
|
132
|
-
})
|
|
120
|
+
return JSON.parse(stageContextPropsBuffer.toString('utf-8'))
|
|
133
121
|
}
|
|
134
122
|
|
|
135
123
|
/**
|
|
136
124
|
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
137
125
|
*/
|
|
138
126
|
protected fullyQualifiedDomain() {
|
|
139
|
-
const domainName = this.
|
|
140
|
-
const subDomain = this.
|
|
127
|
+
const domainName = this.props.domainName
|
|
128
|
+
const subDomain = this.props.subDomain
|
|
129
|
+
|
|
141
130
|
return subDomain ? `${subDomain}.${domainName}` : domainName
|
|
142
131
|
}
|
|
143
132
|
}
|
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
import { CloudflareProviderConfig } from '@cdktf/provider-cloudflare/lib/provider/index.js'
|
|
2
1
|
import { BaseProps } from '../../common/index.js'
|
|
3
|
-
import { RemoteBackend } from './constants.js'
|
|
4
|
-
|
|
5
|
-
export interface RemoteBackendProps {
|
|
6
|
-
bucketName: string
|
|
7
|
-
region: string
|
|
8
|
-
tableName: string
|
|
9
|
-
type: RemoteBackend
|
|
10
|
-
storageAccountName: string
|
|
11
|
-
containerName: string
|
|
12
|
-
subscriptionId: string
|
|
13
|
-
resourceGroupName: string
|
|
14
|
-
}
|
|
15
2
|
|
|
16
3
|
/**
|
|
17
4
|
*/
|
|
18
|
-
export interface CommonCloudflareStackProps extends BaseProps
|
|
5
|
+
export interface CommonCloudflareStackProps extends BaseProps {
|
|
19
6
|
accountId: string
|
|
20
7
|
apiToken: string
|
|
21
|
-
|
|
8
|
+
resourceGroupName?: string
|
|
22
9
|
useExistingZone?: boolean
|
|
23
10
|
}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { DataAzurermKeyVault } from '@cdktf/provider-azurerm/lib/data-azurerm-key-vault/index.js'
|
|
5
|
-
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone/index.js'
|
|
6
|
-
import { DnsRecord } from '@cdktf/provider-cloudflare/lib/dns-record/index.js'
|
|
7
|
-
import { PagesDomain } from '@cdktf/provider-cloudflare/lib/pages-domain/index.js'
|
|
1
|
+
import * as aws from '@pulumi/aws'
|
|
2
|
+
import * as azure from '@pulumi/azure-native'
|
|
3
|
+
import { DnsRecord, PagesDomain, PagesProject, Zone } from '@pulumi/cloudflare'
|
|
8
4
|
import {
|
|
9
|
-
PagesProject,
|
|
10
5
|
PagesProjectDeploymentConfigsPreviewEnvVars,
|
|
11
6
|
PagesProjectDeploymentConfigsProductionEnvVars,
|
|
12
|
-
} from '@
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import { Construct } from 'constructs'
|
|
7
|
+
} from '@pulumi/cloudflare/types/input.js'
|
|
8
|
+
import { ComponentResourceOptions } from '@pulumi/pulumi'
|
|
9
|
+
import * as std from '@pulumi/std'
|
|
16
10
|
import { CommonCloudflareConstruct } from '../../common/index.js'
|
|
17
11
|
import { CloudflarePagesStaticSiteProps } from './types.js'
|
|
18
12
|
|
|
@@ -38,16 +32,17 @@ export class CloudflarePagesStaticSite extends CommonCloudflareConstruct {
|
|
|
38
32
|
sitePagesCnameRecord: DnsRecord
|
|
39
33
|
sitePagesDomain: PagesDomain
|
|
40
34
|
sitePagesProject: PagesProject
|
|
41
|
-
siteZone:
|
|
35
|
+
siteZone: Zone
|
|
42
36
|
sitePagesEnvironmentVariables: { [key: string]: PagesProjectDeploymentConfigsProductionEnvVars }
|
|
43
37
|
sitePagesPreviewEnvironmentVariables: { [key: string]: PagesProjectDeploymentConfigsPreviewEnvVars }
|
|
44
38
|
sitePagesSecrets: { [key: string]: PagesProjectDeploymentConfigsProductionEnvVars }
|
|
45
39
|
sitePagesPreviewSecrets: { [key: string]: PagesProjectDeploymentConfigsPreviewEnvVars }
|
|
46
40
|
siteDeploymentDependsOn: any
|
|
47
41
|
|
|
48
|
-
constructor(
|
|
49
|
-
super(
|
|
42
|
+
constructor(id: string, props: CloudflarePagesStaticSiteProps, options?: ComponentResourceOptions) {
|
|
43
|
+
super(id, props)
|
|
50
44
|
this.props = props
|
|
45
|
+
this.options = options
|
|
51
46
|
this.id = id
|
|
52
47
|
}
|
|
53
48
|
|
|
@@ -116,14 +111,11 @@ export class CloudflarePagesStaticSite extends CommonCloudflareConstruct {
|
|
|
116
111
|
* @returns the secret value
|
|
117
112
|
*/
|
|
118
113
|
protected resolveSecretFromAWS(secretName: string, secretKey: string) {
|
|
119
|
-
if (
|
|
120
|
-
const secret =
|
|
121
|
-
const secretVersion =
|
|
122
|
-
provider: this.awsProvider,
|
|
123
|
-
secretId: secret.id,
|
|
124
|
-
})
|
|
114
|
+
if (this.config.require('secretsProvider') !== 'aws') return
|
|
115
|
+
const secret = aws.secretsmanager.getSecretOutput({ name: secretName })
|
|
116
|
+
const secretVersion = aws.secretsmanager.getSecretVersionOutput({ secretId: secret.id })
|
|
125
117
|
if (!secretVersion) throw new Error(`Unable to resolve secret:${secretName}`)
|
|
126
|
-
return
|
|
118
|
+
return std.jsondecodeOutput({ input: secretVersion.secretString })
|
|
127
119
|
}
|
|
128
120
|
|
|
129
121
|
/**
|
|
@@ -135,26 +127,14 @@ export class CloudflarePagesStaticSite extends CommonCloudflareConstruct {
|
|
|
135
127
|
* @returns the secret value
|
|
136
128
|
*/
|
|
137
129
|
protected resolveSecretFromAzure(resourceGroupName: string, keyVaultName: string, secretKey: string) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
provider: this.azurermProvider,
|
|
145
|
-
}
|
|
146
|
-
)
|
|
147
|
-
const secretValueData = new DataAzurermKeyVaultSecret(
|
|
148
|
-
this,
|
|
149
|
-
`${this.id}-${resourceGroupName}-${keyVaultName}-${secretKey}-secret`,
|
|
150
|
-
{
|
|
151
|
-
name: secretKey,
|
|
152
|
-
keyVaultId: keyVaultData.id,
|
|
153
|
-
provider: this.azurermProvider,
|
|
154
|
-
}
|
|
155
|
-
)
|
|
130
|
+
if (this.config.require('secretsProvider') !== 'azure') return
|
|
131
|
+
const secretValueData = azure.keyvault.getSecretOutput({
|
|
132
|
+
resourceGroupName,
|
|
133
|
+
secretName: secretKey,
|
|
134
|
+
vaultName: keyVaultName,
|
|
135
|
+
})
|
|
156
136
|
if (!secretValueData) throw new Error(`Unable to resolve secret:${secretKey}`)
|
|
157
|
-
return secretValueData.value
|
|
137
|
+
return secretValueData.properties?.value
|
|
158
138
|
}
|
|
159
139
|
|
|
160
140
|
/**
|
|
@@ -201,7 +181,7 @@ export class CloudflarePagesStaticSite extends CommonCloudflareConstruct {
|
|
|
201
181
|
branch: this.props.siteBranch ?? 'main',
|
|
202
182
|
directory: this.props.siteAssetDir,
|
|
203
183
|
message: this.props.siteDeployMessage,
|
|
204
|
-
projectName: this.sitePagesProject.name,
|
|
184
|
+
projectName: String(this.sitePagesProject.name),
|
|
205
185
|
dependsOn: this.siteDeploymentDependsOn,
|
|
206
186
|
})
|
|
207
187
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { AssetType, Fn, TerraformAsset } from 'cdktf'
|
|
9
|
-
import { Construct } from 'constructs'
|
|
1
|
+
import * as aws from '@pulumi/aws'
|
|
2
|
+
import * as azure from '@pulumi/azure-native'
|
|
3
|
+
import { Ruleset, WorkersCustomDomain, WorkersScript, Zone, ZoneSetting } from '@pulumi/cloudflare'
|
|
4
|
+
import { WorkersScriptBinding } from '@pulumi/cloudflare/types/input.js'
|
|
5
|
+
import { ComponentResourceOptions } from '@pulumi/pulumi'
|
|
6
|
+
import * as std from '@pulumi/std'
|
|
7
|
+
import fs from 'fs'
|
|
10
8
|
import { CommonCloudflareConstruct } from '../../common/index.js'
|
|
11
9
|
import { CloudflareWorkerSiteProps } from './types.js'
|
|
12
10
|
|
|
@@ -29,14 +27,18 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
|
29
27
|
declare props: CloudflareWorkerSiteProps
|
|
30
28
|
|
|
31
29
|
/* worker site resources */
|
|
32
|
-
siteZone:
|
|
30
|
+
siteZone: Zone
|
|
33
31
|
siteWorkerScript: WorkersScript
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
siteWorkerDomain: WorkersCustomDomain
|
|
33
|
+
siteRuleSet: Ruleset
|
|
34
|
+
siteZoneSetting: ZoneSetting
|
|
35
|
+
workerPlainTextBindingEnvironmentVariables: WorkersScriptBinding[] = []
|
|
36
|
+
workerSecretTextBindingEnvironmentVariables: WorkersScriptBinding[] = []
|
|
36
37
|
|
|
37
|
-
constructor(
|
|
38
|
-
super(
|
|
38
|
+
constructor(id: string, props: CloudflareWorkerSiteProps, options?: ComponentResourceOptions) {
|
|
39
|
+
super(id, props)
|
|
39
40
|
this.props = props
|
|
41
|
+
this.options = options
|
|
40
42
|
this.id = id
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -79,14 +81,10 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
|
79
81
|
* @summary Create the worker
|
|
80
82
|
*/
|
|
81
83
|
protected createWorker() {
|
|
82
|
-
const workerContent =
|
|
83
|
-
path: this.props.siteWorkerAsset,
|
|
84
|
-
type: AssetType.FILE,
|
|
85
|
-
})
|
|
86
|
-
|
|
84
|
+
const workerContent = fs.readFileSync(this.props.siteWorkerAsset, 'utf-8')
|
|
87
85
|
this.siteWorkerScript = this.workerManager.createWorkerScript(`${this.id}-worker-script`, this, {
|
|
88
86
|
...this.props.siteWorkerScript,
|
|
89
|
-
content:
|
|
87
|
+
content: workerContent,
|
|
90
88
|
})
|
|
91
89
|
}
|
|
92
90
|
|
|
@@ -94,7 +92,7 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
|
94
92
|
* @summary Create the worker domain
|
|
95
93
|
*/
|
|
96
94
|
protected createWorkerDomain() {
|
|
97
|
-
this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
95
|
+
this.siteWorkerDomain = this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
98
96
|
...this.props.siteWorkerDomain,
|
|
99
97
|
environment: this.props.siteWorkerDomain.environment ?? 'production',
|
|
100
98
|
hostname: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
@@ -108,23 +106,12 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
|
108
106
|
* @param secretKey the secret key
|
|
109
107
|
* @returns the secret value
|
|
110
108
|
*/
|
|
111
|
-
protected resolveSecretFromAWS(secretName: string, secretKey: string
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
const secret = new DataAwsSecretsmanagerSecret(this, id ?? `${this.id}-${secretName}-${secretKey}`, {
|
|
116
|
-
name: secretName,
|
|
117
|
-
})
|
|
118
|
-
const secretVersion = new DataAwsSecretsmanagerSecretVersion(
|
|
119
|
-
this,
|
|
120
|
-
id ? `${id}-ver` : `${this.id}-${secretName}-${secretKey}-ver`,
|
|
121
|
-
{
|
|
122
|
-
provider: this.awsProvider,
|
|
123
|
-
secretId: secret.id,
|
|
124
|
-
}
|
|
125
|
-
)
|
|
109
|
+
protected resolveSecretFromAWS(secretName: string, secretKey: string) {
|
|
110
|
+
if (this.config.require('secretsProvider') !== 'aws') return
|
|
111
|
+
const secret = aws.secretsmanager.getSecretOutput({ name: secretName })
|
|
112
|
+
const secretVersion = aws.secretsmanager.getSecretVersionOutput({ secretId: secret.id })
|
|
126
113
|
if (!secretVersion) throw new Error(`Unable to resolve secret:${secretName}`)
|
|
127
|
-
return
|
|
114
|
+
return std.jsondecodeOutput({ input: secretVersion.secretString })
|
|
128
115
|
}
|
|
129
116
|
|
|
130
117
|
/**
|
|
@@ -135,30 +122,15 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
|
135
122
|
* @param secretKey the secret key
|
|
136
123
|
* @returns the secret value
|
|
137
124
|
*/
|
|
138
|
-
protected resolveSecretFromAzure(resourceGroupName: string, keyVaultName: string, secretKey: string
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
{
|
|
146
|
-
resourceGroupName: resourceGroupName,
|
|
147
|
-
name: keyVaultName,
|
|
148
|
-
provider: this.azurermProvider,
|
|
149
|
-
}
|
|
150
|
-
)
|
|
151
|
-
const secretValueData = new DataAzurermKeyVaultSecret(
|
|
152
|
-
this,
|
|
153
|
-
id ? `${id}-secret` : `${this.id}-${resourceGroupName}-${keyVaultName}-${secretKey}-secret`,
|
|
154
|
-
{
|
|
155
|
-
name: secretKey,
|
|
156
|
-
keyVaultId: keyVaultData.id,
|
|
157
|
-
provider: this.azurermProvider,
|
|
158
|
-
}
|
|
159
|
-
)
|
|
125
|
+
protected resolveSecretFromAzure(resourceGroupName: string, keyVaultName: string, secretKey: string) {
|
|
126
|
+
if (this.config.require('secretsProvider') !== 'azure') return
|
|
127
|
+
const secretValueData = azure.keyvault.getSecretOutput({
|
|
128
|
+
resourceGroupName,
|
|
129
|
+
secretName: secretKey,
|
|
130
|
+
vaultName: keyVaultName,
|
|
131
|
+
})
|
|
160
132
|
if (!secretValueData) throw new Error(`Unable to resolve secret:${secretKey}`)
|
|
161
|
-
return secretValueData.value
|
|
133
|
+
return secretValueData.properties?.value
|
|
162
134
|
}
|
|
163
135
|
|
|
164
136
|
/**
|
|
@@ -166,7 +138,7 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
|
166
138
|
*/
|
|
167
139
|
protected createRuleset() {
|
|
168
140
|
if (!this.props.siteRuleSet) return
|
|
169
|
-
this.ruleSetManager.createRuleSet(`${this.id}-rule`, this, this.props.siteRuleSet)
|
|
141
|
+
this.siteRuleSet = this.ruleSetManager.createRuleSet(`${this.id}-rule`, this, this.props.siteRuleSet)
|
|
170
142
|
}
|
|
171
143
|
|
|
172
144
|
/**
|
|
@@ -174,6 +146,10 @@ export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
|
174
146
|
*/
|
|
175
147
|
protected createZoneSetting() {
|
|
176
148
|
if (!this.props.siteZoneSetting) return
|
|
177
|
-
this.
|
|
149
|
+
this.siteZoneSetting = this.zoneManager.createZoneSetting(
|
|
150
|
+
`${this.id}-zone-setting`,
|
|
151
|
+
this,
|
|
152
|
+
this.props.siteZoneSetting
|
|
153
|
+
)
|
|
178
154
|
}
|
|
179
155
|
}
|