@byaga/cdk-patterns 0.2.0 → 0.4.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/ApiCertificate.ts +7 -7
- package/IDeployStack.ts +56 -0
- package/IDomainConfig.ts +8 -0
- package/IHostedZoneConfig.ts +5 -0
- package/IStackArguments.ts +8 -0
- package/package.json +1 -1
- package/IStackArguments +0 -0
- package/cdk-patterns.iml +0 -9
package/ApiCertificate.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import {DnsValidatedCertificate} from "aws-cdk-lib/aws-certificatemanager";
|
1
|
+
import {Certificate, CertificateValidation} from "aws-cdk-lib/aws-certificatemanager";
|
3
2
|
import {HostedZone, IHostedZone} from "aws-cdk-lib/aws-route53";
|
4
3
|
import {CfnOutput} from "aws-cdk-lib";
|
5
|
-
import
|
4
|
+
import IDeployStack from "./IDeployStack";
|
5
|
+
import IDomainConfig from "./IDomainConfig";
|
6
6
|
|
7
|
-
export
|
7
|
+
export class ApiCertificate extends Certificate {
|
8
8
|
hostedZone: IHostedZone
|
9
9
|
domain: string
|
10
10
|
|
@@ -13,14 +13,13 @@ export default class ApiCertificate extends DnsValidatedCertificate {
|
|
13
13
|
if (domain.subdomain) certDomain.splice(0, 0, domain.subdomain)
|
14
14
|
const domainName = certDomain.join('.')
|
15
15
|
|
16
|
-
console.log(1, domainName, domain)
|
17
16
|
const hostedZone: IHostedZone = HostedZone.fromHostedZoneAttributes(stack, stack.genId(id, 'hosted-zone'), {
|
18
17
|
hostedZoneId: domain.hostedZone.id,
|
19
18
|
zoneName: domain.hostedZone.name
|
20
19
|
})
|
21
20
|
super(stack, stack.genId(id), {
|
22
21
|
domainName,
|
23
|
-
hostedZone
|
22
|
+
validation: CertificateValidation.fromDns(hostedZone)
|
24
23
|
});
|
25
24
|
|
26
25
|
this.domain = domainName
|
@@ -29,4 +28,5 @@ export default class ApiCertificate extends DnsValidatedCertificate {
|
|
29
28
|
exportName: stack.genName(id)})
|
30
29
|
this.hostedZone = hostedZone
|
31
30
|
}
|
32
|
-
}
|
31
|
+
}
|
32
|
+
export default ApiCertificate
|
package/IDeployStack.ts
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
import {Stack} from 'aws-cdk-lib';
|
2
|
+
import IStackArguments from './IStackArguments'
|
3
|
+
import {IConstruct} from "constructs";
|
4
|
+
|
5
|
+
export class IDeployStack extends Stack {
|
6
|
+
registry: { [t: string]: { [n: string]: any } } = {}
|
7
|
+
stage: string
|
8
|
+
name: string
|
9
|
+
|
10
|
+
genName(...name: string[]): string {
|
11
|
+
return IDeployStack.genStackResourceName(this.name, this.stage, name.filter(n => !!n).join('-'))
|
12
|
+
}
|
13
|
+
|
14
|
+
genId(...name: string[]): string {
|
15
|
+
return IDeployStack.genStackResourceId(this.name, this.stage, name.filter(n => !!n).join('-'))
|
16
|
+
}
|
17
|
+
|
18
|
+
static genStackResourceName(stackName: string, resource: string, stage = 'develop') {
|
19
|
+
let name = stackName[0].toLowerCase() + stackName.substr(1)
|
20
|
+
name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase())
|
21
|
+
return `${name}-${resource}-${stage}`.toLowerCase()
|
22
|
+
}
|
23
|
+
|
24
|
+
static genStackResourceId(stackName: string, resource: string, stage = 'develop') {
|
25
|
+
const constructName = `${stackName}-${resource}-${stage}`
|
26
|
+
return constructName[0].toUpperCase() + constructName.substr(1).replace(/-./g, v => (v[1] || '').toUpperCase())
|
27
|
+
}
|
28
|
+
|
29
|
+
constructor(scope: IConstruct, props: IStackArguments) {
|
30
|
+
const options = (props || {}) as IStackArguments
|
31
|
+
const {stage = 'develop'} = options
|
32
|
+
super(scope, props.stackName + '-' + stage, {
|
33
|
+
...props,
|
34
|
+
stackName: props.stackName + '-' + stage
|
35
|
+
});
|
36
|
+
const stack = this;
|
37
|
+
stack.name = props.stackName || '';
|
38
|
+
|
39
|
+
stack.stage = stage;
|
40
|
+
|
41
|
+
stack.tags.setTag('Stage', stage);
|
42
|
+
stack.tags.setTag('Stack', this.genName('ui-stack'));
|
43
|
+
}
|
44
|
+
|
45
|
+
get(type: string, name: string) {
|
46
|
+
const items = this.registry[type]
|
47
|
+
return (items && items[name]) || null
|
48
|
+
}
|
49
|
+
|
50
|
+
set(type: string, name: string, instance: any) {
|
51
|
+
this.registry[type] = this.registry[type] || {};
|
52
|
+
this.registry[type][name] = instance;
|
53
|
+
return instance;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
export default IDeployStack
|
package/IDomainConfig.ts
ADDED
package/package.json
CHANGED
package/IStackArguments
DELETED
File without changes
|
package/cdk-patterns.iml
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="WEB_MODULE" version="4">
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
-
<exclude-output />
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
6
|
-
<orderEntry type="inheritedJdk" />
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
8
|
-
</component>
|
9
|
-
</module>
|