@gradientedge/cdk-utils 9.4.0 → 9.5.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/cloudflare/construct/index.d.ts +1 -0
- package/dist/src/lib/cloudflare/construct/index.js +1 -0
- package/dist/src/lib/cloudflare/construct/worker-site/index.d.ts +2 -0
- package/dist/src/lib/cloudflare/construct/worker-site/index.js +18 -0
- package/dist/src/lib/cloudflare/construct/worker-site/main.d.ts +50 -0
- package/dist/src/lib/cloudflare/construct/worker-site/main.js +100 -0
- package/dist/src/lib/cloudflare/construct/worker-site/types.d.ts +9 -0
- package/dist/src/lib/cloudflare/construct/worker-site/types.js +2 -0
- package/package.json +1 -1
- package/src/lib/cloudflare/construct/index.ts +1 -0
- package/src/lib/cloudflare/construct/worker-site/index.ts +2 -0
- package/src/lib/cloudflare/construct/worker-site/main.ts +113 -0
- package/src/lib/cloudflare/construct/worker-site/types.ts +10 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./main"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone';
|
|
2
|
+
import { WorkerScript, WorkerScriptPlainTextBinding, WorkerScriptSecretTextBinding } from '@cdktf/provider-cloudflare/lib/worker-script';
|
|
3
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone';
|
|
4
|
+
import { Construct } from 'constructs';
|
|
5
|
+
import { CommonCloudflareConstruct } from '../../common';
|
|
6
|
+
import { CloudflareWorkerSiteProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
9
|
+
* @example
|
|
10
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
11
|
+
* import { Construct } from 'constructs'
|
|
12
|
+
*
|
|
13
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
14
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
15
|
+
* super(parent, id, props)
|
|
16
|
+
* this.props = props
|
|
17
|
+
* this.id = id
|
|
18
|
+
* this.initResources()
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export declare class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
23
|
+
props: CloudflareWorkerSiteProps;
|
|
24
|
+
siteZone: DataCloudflareZone | Zone;
|
|
25
|
+
siteWorkerScript: WorkerScript;
|
|
26
|
+
workerPlainTextBindingEnvironmentVariables: WorkerScriptPlainTextBinding[];
|
|
27
|
+
workerSecretTextBindingEnvironmentVariables: WorkerScriptSecretTextBinding[];
|
|
28
|
+
constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps);
|
|
29
|
+
/**
|
|
30
|
+
* @summary Initialise and provision resources
|
|
31
|
+
*/
|
|
32
|
+
protected initResources(): void;
|
|
33
|
+
/**
|
|
34
|
+
* @summary Resolve the zone to use for the worker site
|
|
35
|
+
*/
|
|
36
|
+
protected resolveZone(): void;
|
|
37
|
+
/**
|
|
38
|
+
* @summary Resolve the environment variables to use for the static site
|
|
39
|
+
*/
|
|
40
|
+
protected resolveEnvironmentVariables(): void;
|
|
41
|
+
protected createWorker(): void;
|
|
42
|
+
protected createWorkerDomain(): void;
|
|
43
|
+
/**
|
|
44
|
+
* @summary Resolve secrets from AWS Secrets Manager
|
|
45
|
+
* @param secretName the secret name
|
|
46
|
+
* @param secretKey the secret key
|
|
47
|
+
* @returns the secret value
|
|
48
|
+
*/
|
|
49
|
+
protected resolveSecretFromAWS(secretName: string, secretKey: string): any;
|
|
50
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudflareWorkerSite = void 0;
|
|
4
|
+
const data_aws_secretsmanager_secret_1 = require("@cdktf/provider-aws/lib/data-aws-secretsmanager-secret");
|
|
5
|
+
const data_aws_secretsmanager_secret_version_1 = require("@cdktf/provider-aws/lib/data-aws-secretsmanager-secret-version");
|
|
6
|
+
const cdktf_1 = require("cdktf");
|
|
7
|
+
const common_1 = require("../../common");
|
|
8
|
+
/**
|
|
9
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
10
|
+
* @example
|
|
11
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
12
|
+
* import { Construct } from 'constructs'
|
|
13
|
+
*
|
|
14
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
15
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
16
|
+
* super(parent, id, props)
|
|
17
|
+
* this.props = props
|
|
18
|
+
* this.id = id
|
|
19
|
+
* this.initResources()
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
class CloudflareWorkerSite extends common_1.CommonCloudflareConstruct {
|
|
24
|
+
/* worker site resources */
|
|
25
|
+
siteZone;
|
|
26
|
+
siteWorkerScript;
|
|
27
|
+
workerPlainTextBindingEnvironmentVariables;
|
|
28
|
+
workerSecretTextBindingEnvironmentVariables;
|
|
29
|
+
constructor(parent, id, props) {
|
|
30
|
+
super(parent, id, props);
|
|
31
|
+
this.props = props;
|
|
32
|
+
this.id = id;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @summary Initialise and provision resources
|
|
36
|
+
*/
|
|
37
|
+
initResources() {
|
|
38
|
+
this.resolveZone();
|
|
39
|
+
this.resolveEnvironmentVariables();
|
|
40
|
+
this.createWorker();
|
|
41
|
+
this.createWorkerDomain();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @summary Resolve the zone to use for the worker site
|
|
45
|
+
*/
|
|
46
|
+
resolveZone() {
|
|
47
|
+
if (this.props.useExistingZone) {
|
|
48
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @summary Resolve the environment variables to use for the static site
|
|
56
|
+
*/
|
|
57
|
+
resolveEnvironmentVariables() {
|
|
58
|
+
this.props.siteWorkerScript = {
|
|
59
|
+
...this.props.siteWorkerScript,
|
|
60
|
+
plainTextBinding: this.workerPlainTextBindingEnvironmentVariables,
|
|
61
|
+
secretTextBinding: this.workerSecretTextBindingEnvironmentVariables,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
createWorker() {
|
|
65
|
+
const workerContent = new cdktf_1.TerraformAsset(this, `${this.id}-worker-content`, {
|
|
66
|
+
path: this.props.siteWorkerAsset,
|
|
67
|
+
type: cdktf_1.AssetType.FILE,
|
|
68
|
+
});
|
|
69
|
+
this.siteWorkerScript = this.workerManager.createWorkerScript(`${this.id}-worker-script`, this, {
|
|
70
|
+
...this.props.siteWorkerScript,
|
|
71
|
+
content: cdktf_1.Fn.file(workerContent.path),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
createWorkerDomain() {
|
|
75
|
+
this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
76
|
+
...this.props.siteWorkerDomain,
|
|
77
|
+
hostname: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
78
|
+
service: this.siteWorkerScript.name,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @summary Resolve secrets from AWS Secrets Manager
|
|
83
|
+
* @param secretName the secret name
|
|
84
|
+
* @param secretKey the secret key
|
|
85
|
+
* @returns the secret value
|
|
86
|
+
*/
|
|
87
|
+
resolveSecretFromAWS(secretName, secretKey) {
|
|
88
|
+
if (!this.awsProvider)
|
|
89
|
+
return;
|
|
90
|
+
const secret = new data_aws_secretsmanager_secret_1.DataAwsSecretsmanagerSecret(this, `${this.id}-${secretName}-${secretKey}`, { name: secretName });
|
|
91
|
+
const secretVersion = new data_aws_secretsmanager_secret_version_1.DataAwsSecretsmanagerSecretVersion(this, `${this.id}-${secretName}-${secretKey}-ver`, {
|
|
92
|
+
provider: this.awsProvider,
|
|
93
|
+
secretId: secret.id,
|
|
94
|
+
});
|
|
95
|
+
if (!secretVersion)
|
|
96
|
+
throw new Error(`Unable to resolve secret:${secretName}`);
|
|
97
|
+
return cdktf_1.Fn.lookup(cdktf_1.Fn.jsondecode(secretVersion.secretString), secretKey);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CloudflareWorkerSite = CloudflareWorkerSite;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common';
|
|
2
|
+
import { WorkerDomainProps, WorkerScriptProps, ZoneProps } from '../../services';
|
|
3
|
+
export interface CloudflareWorkerSiteProps extends CommonCloudflareStackProps {
|
|
4
|
+
siteSubDomain: string;
|
|
5
|
+
siteZone: ZoneProps;
|
|
6
|
+
siteWorkerScript: WorkerScriptProps;
|
|
7
|
+
siteWorkerDomain: WorkerDomainProps;
|
|
8
|
+
siteWorkerAsset: string;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { DataAwsSecretsmanagerSecret } from '@cdktf/provider-aws/lib/data-aws-secretsmanager-secret'
|
|
2
|
+
import { DataAwsSecretsmanagerSecretVersion } from '@cdktf/provider-aws/lib/data-aws-secretsmanager-secret-version'
|
|
3
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone'
|
|
4
|
+
import {
|
|
5
|
+
WorkerScript,
|
|
6
|
+
WorkerScriptPlainTextBinding,
|
|
7
|
+
WorkerScriptSecretTextBinding,
|
|
8
|
+
} from '@cdktf/provider-cloudflare/lib/worker-script'
|
|
9
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone'
|
|
10
|
+
import { Fn, TerraformAsset, AssetType } from 'cdktf'
|
|
11
|
+
import { Construct } from 'constructs'
|
|
12
|
+
import { CommonCloudflareConstruct } from '../../common'
|
|
13
|
+
import { CloudflareWorkerSiteProps } from './types'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @classdesc Provides a construct to create and deploy a cloudflare worker site
|
|
17
|
+
* @example
|
|
18
|
+
* import { CloudflareWorkerSite, CloudflareWorkerSiteProps } '@gradientedge/cdk-utils'
|
|
19
|
+
* import { Construct } from 'constructs'
|
|
20
|
+
*
|
|
21
|
+
* class CustomConstruct extends CloudflareWorkerSite {
|
|
22
|
+
* constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
23
|
+
* super(parent, id, props)
|
|
24
|
+
* this.props = props
|
|
25
|
+
* this.id = id
|
|
26
|
+
* this.initResources()
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
export class CloudflareWorkerSite extends CommonCloudflareConstruct {
|
|
31
|
+
declare props: CloudflareWorkerSiteProps
|
|
32
|
+
|
|
33
|
+
/* worker site resources */
|
|
34
|
+
siteZone: DataCloudflareZone | Zone
|
|
35
|
+
siteWorkerScript: WorkerScript
|
|
36
|
+
workerPlainTextBindingEnvironmentVariables: WorkerScriptPlainTextBinding[]
|
|
37
|
+
workerSecretTextBindingEnvironmentVariables: WorkerScriptSecretTextBinding[]
|
|
38
|
+
|
|
39
|
+
constructor(parent: Construct, id: string, props: CloudflareWorkerSiteProps) {
|
|
40
|
+
super(parent, id, props)
|
|
41
|
+
this.props = props
|
|
42
|
+
this.id = id
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @summary Initialise and provision resources
|
|
47
|
+
*/
|
|
48
|
+
protected initResources() {
|
|
49
|
+
this.resolveZone()
|
|
50
|
+
this.resolveEnvironmentVariables()
|
|
51
|
+
this.createWorker()
|
|
52
|
+
this.createWorkerDomain()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @summary Resolve the zone to use for the worker site
|
|
57
|
+
*/
|
|
58
|
+
protected resolveZone() {
|
|
59
|
+
if (this.props.useExistingZone) {
|
|
60
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this)
|
|
61
|
+
} else {
|
|
62
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @summary Resolve the environment variables to use for the static site
|
|
68
|
+
*/
|
|
69
|
+
protected resolveEnvironmentVariables() {
|
|
70
|
+
this.props.siteWorkerScript = {
|
|
71
|
+
...this.props.siteWorkerScript,
|
|
72
|
+
plainTextBinding: this.workerPlainTextBindingEnvironmentVariables,
|
|
73
|
+
secretTextBinding: this.workerSecretTextBindingEnvironmentVariables,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected createWorker() {
|
|
78
|
+
const workerContent = new TerraformAsset(this, `${this.id}-worker-content`, {
|
|
79
|
+
path: this.props.siteWorkerAsset,
|
|
80
|
+
type: AssetType.FILE,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
this.siteWorkerScript = this.workerManager.createWorkerScript(`${this.id}-worker-script`, this, {
|
|
84
|
+
...this.props.siteWorkerScript,
|
|
85
|
+
content: Fn.file(workerContent.path),
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
protected createWorkerDomain() {
|
|
90
|
+
this.workerManager.createWorkerDomain(`${this.id}-worker-domain`, this, {
|
|
91
|
+
...this.props.siteWorkerDomain,
|
|
92
|
+
hostname: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
93
|
+
service: this.siteWorkerScript.name,
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @summary Resolve secrets from AWS Secrets Manager
|
|
99
|
+
* @param secretName the secret name
|
|
100
|
+
* @param secretKey the secret key
|
|
101
|
+
* @returns the secret value
|
|
102
|
+
*/
|
|
103
|
+
protected resolveSecretFromAWS(secretName: string, secretKey: string) {
|
|
104
|
+
if (!this.awsProvider) return
|
|
105
|
+
const secret = new DataAwsSecretsmanagerSecret(this, `${this.id}-${secretName}-${secretKey}`, { name: secretName })
|
|
106
|
+
const secretVersion = new DataAwsSecretsmanagerSecretVersion(this, `${this.id}-${secretName}-${secretKey}-ver`, {
|
|
107
|
+
provider: this.awsProvider,
|
|
108
|
+
secretId: secret.id,
|
|
109
|
+
})
|
|
110
|
+
if (!secretVersion) throw new Error(`Unable to resolve secret:${secretName}`)
|
|
111
|
+
return Fn.lookup(Fn.jsondecode(secretVersion.secretString), secretKey)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common'
|
|
2
|
+
import { WorkerDomainProps, WorkerScriptProps, RecordProps, ZoneProps } from '../../services'
|
|
3
|
+
|
|
4
|
+
export interface CloudflareWorkerSiteProps extends CommonCloudflareStackProps {
|
|
5
|
+
siteSubDomain: string
|
|
6
|
+
siteZone: ZoneProps
|
|
7
|
+
siteWorkerScript: WorkerScriptProps
|
|
8
|
+
siteWorkerDomain: WorkerDomainProps
|
|
9
|
+
siteWorkerAsset: string
|
|
10
|
+
}
|