@byaga/cdk-patterns 0.3.0 → 0.5.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/lib/ApiCertificate.d.ts +10 -0
- package/lib/ApiCertificate.js +32 -0
- package/lib/IDeployStack.d.ts +20 -0
- package/lib/IDeployStack.js +48 -0
- package/lib/IDomainConfig.d.ts +7 -0
- package/lib/IDomainConfig.js +2 -0
- package/lib/IHostedZoneConfig.d.ts +5 -0
- package/lib/IHostedZoneConfig.js +2 -0
- package/lib/IStackArguments.d.ts +7 -0
- package/lib/IStackArguments.js +2 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +7 -0
- package/package.json +7 -3
- package/{ApiCertificate.ts → src/ApiCertificate.ts} +7 -7
- package/{IDeployStack.ts → src/IDeployStack.ts} +2 -1
- package/src/IDomainConfig.ts +8 -0
- package/src/IHostedZoneConfig.ts +5 -0
- package/{IStackArguments.ts → src/IStackArguments.ts} +2 -1
- package/src/index.ts +5 -0
- package/tsconfig.json +35 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
|
2
|
+
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
3
|
+
import IDeployStack from "./IDeployStack";
|
4
|
+
import IDomainConfig from "./IDomainConfig";
|
5
|
+
export declare class ApiCertificate extends Certificate {
|
6
|
+
hostedZone: IHostedZone;
|
7
|
+
domain: string;
|
8
|
+
constructor(stack: IDeployStack, id: string, domain: IDomainConfig);
|
9
|
+
}
|
10
|
+
export default ApiCertificate;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ApiCertificate = void 0;
|
4
|
+
const aws_certificatemanager_1 = require("aws-cdk-lib/aws-certificatemanager");
|
5
|
+
const aws_route53_1 = require("aws-cdk-lib/aws-route53");
|
6
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
7
|
+
class ApiCertificate extends aws_certificatemanager_1.Certificate {
|
8
|
+
hostedZone;
|
9
|
+
domain;
|
10
|
+
constructor(stack, id, domain) {
|
11
|
+
const certDomain = [domain.domainName];
|
12
|
+
if (domain.subdomain)
|
13
|
+
certDomain.splice(0, 0, domain.subdomain);
|
14
|
+
const domainName = certDomain.join('.');
|
15
|
+
const hostedZone = aws_route53_1.HostedZone.fromHostedZoneAttributes(stack, stack.genId(id, 'hosted-zone'), {
|
16
|
+
hostedZoneId: domain.hostedZone.id,
|
17
|
+
zoneName: domain.hostedZone.name
|
18
|
+
});
|
19
|
+
super(stack, stack.genId(id), {
|
20
|
+
domainName,
|
21
|
+
validation: aws_certificatemanager_1.CertificateValidation.fromDns(hostedZone)
|
22
|
+
});
|
23
|
+
this.domain = domainName;
|
24
|
+
new aws_cdk_lib_1.CfnOutput(this, stack.genId(id, "certificate-output"), {
|
25
|
+
value: this.certificateArn,
|
26
|
+
exportName: stack.genName(id)
|
27
|
+
});
|
28
|
+
this.hostedZone = hostedZone;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
exports.ApiCertificate = ApiCertificate;
|
32
|
+
exports.default = ApiCertificate;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Stack } from 'aws-cdk-lib';
|
2
|
+
import IStackArguments from './IStackArguments';
|
3
|
+
import { IConstruct } from "constructs";
|
4
|
+
export declare class IDeployStack extends Stack {
|
5
|
+
registry: {
|
6
|
+
[t: string]: {
|
7
|
+
[n: string]: any;
|
8
|
+
};
|
9
|
+
};
|
10
|
+
stage: string;
|
11
|
+
name: string;
|
12
|
+
genName(...name: string[]): string;
|
13
|
+
genId(...name: string[]): string;
|
14
|
+
static genStackResourceName(stackName: string, resource: string, stage?: string): string;
|
15
|
+
static genStackResourceId(stackName: string, resource: string, stage?: string): string;
|
16
|
+
constructor(scope: IConstruct, props: IStackArguments);
|
17
|
+
get(type: string, name: string): any;
|
18
|
+
set(type: string, name: string, instance: any): any;
|
19
|
+
}
|
20
|
+
export default IDeployStack;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.IDeployStack = void 0;
|
4
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
5
|
+
class IDeployStack extends aws_cdk_lib_1.Stack {
|
6
|
+
registry = {};
|
7
|
+
stage;
|
8
|
+
name;
|
9
|
+
genName(...name) {
|
10
|
+
return IDeployStack.genStackResourceName(this.name, this.stage, name.filter(n => !!n).join('-'));
|
11
|
+
}
|
12
|
+
genId(...name) {
|
13
|
+
return IDeployStack.genStackResourceId(this.name, this.stage, name.filter(n => !!n).join('-'));
|
14
|
+
}
|
15
|
+
static genStackResourceName(stackName, resource, stage = 'develop') {
|
16
|
+
let name = stackName[0].toLowerCase() + stackName.substr(1);
|
17
|
+
name = name.replace(/[A-Z]/g, v => '-' + v.toLowerCase());
|
18
|
+
return `${name}-${resource}-${stage}`.toLowerCase();
|
19
|
+
}
|
20
|
+
static genStackResourceId(stackName, resource, stage = 'develop') {
|
21
|
+
const constructName = `${stackName}-${resource}-${stage}`;
|
22
|
+
return constructName[0].toUpperCase() + constructName.substr(1).replace(/-./g, v => (v[1] || '').toUpperCase());
|
23
|
+
}
|
24
|
+
constructor(scope, props) {
|
25
|
+
const options = (props || {});
|
26
|
+
const { stage = 'develop' } = options;
|
27
|
+
super(scope, props.stackName + '-' + stage, {
|
28
|
+
...props,
|
29
|
+
stackName: props.stackName + '-' + stage
|
30
|
+
});
|
31
|
+
const stack = this;
|
32
|
+
stack.name = props.stackName || '';
|
33
|
+
stack.stage = stage;
|
34
|
+
stack.tags.setTag('Stage', stage);
|
35
|
+
stack.tags.setTag('Stack', this.genName('ui-stack'));
|
36
|
+
}
|
37
|
+
get(type, name) {
|
38
|
+
const items = this.registry[type];
|
39
|
+
return (items && items[name]) || null;
|
40
|
+
}
|
41
|
+
set(type, name, instance) {
|
42
|
+
this.registry[type] = this.registry[type] || {};
|
43
|
+
this.registry[type][name] = instance;
|
44
|
+
return instance;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
exports.IDeployStack = IDeployStack;
|
48
|
+
exports.default = IDeployStack;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.IDeployStack = exports.ApiCertificate = void 0;
|
4
|
+
var ApiCertificate_1 = require("./ApiCertificate");
|
5
|
+
Object.defineProperty(exports, "ApiCertificate", { enumerable: true, get: function () { return ApiCertificate_1.ApiCertificate; } });
|
6
|
+
var IDeployStack_1 = require("./IDeployStack");
|
7
|
+
Object.defineProperty(exports, "IDeployStack", { enumerable: true, get: function () { return IDeployStack_1.IDeployStack; } });
|
package/package.json
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@byaga/cdk-patterns",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0",
|
4
4
|
"description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
|
5
|
-
"main": "
|
5
|
+
"main": "lib/index.js",
|
6
|
+
"types": "lib/index.d.ts",
|
6
7
|
"scripts": {
|
7
|
-
"
|
8
|
+
"build": "tsc"
|
8
9
|
},
|
9
10
|
"keywords": [
|
10
11
|
"CDK",
|
@@ -19,5 +20,8 @@
|
|
19
20
|
"fs-extra": "^11.1.1",
|
20
21
|
"glob": "^10.3.3",
|
21
22
|
"js-yaml": "^4.1.0"
|
23
|
+
},
|
24
|
+
"devDependencies": {
|
25
|
+
"typescript": "^5.1.6"
|
22
26
|
}
|
23
27
|
}
|
@@ -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
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import {Stack} from 'aws-cdk-lib';
|
2
|
-
import
|
2
|
+
import IStackArguments from './IStackArguments'
|
3
3
|
import {IConstruct} from "constructs";
|
4
4
|
|
5
5
|
export class IDeployStack extends Stack {
|
@@ -53,3 +53,4 @@ export class IDeployStack extends Stack {
|
|
53
53
|
return instance;
|
54
54
|
}
|
55
55
|
}
|
56
|
+
export default IDeployStack
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "ES2022",
|
4
|
+
"module": "commonjs",
|
5
|
+
"lib": [ "es2022" ],
|
6
|
+
|
7
|
+
"strict": true,
|
8
|
+
"esModuleInterop": true,
|
9
|
+
"skipLibCheck": true,
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
11
|
+
|
12
|
+
"outDir": "lib",
|
13
|
+
"declaration": true,
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
"noImplicitAny": true,
|
18
|
+
"strictNullChecks": true,
|
19
|
+
"noImplicitThis": true,
|
20
|
+
"alwaysStrict": true,
|
21
|
+
"noUnusedLocals": false,
|
22
|
+
"noUnusedParameters": false,
|
23
|
+
"noImplicitReturns": true,
|
24
|
+
"noFallthroughCasesInSwitch": false,
|
25
|
+
"inlineSourceMap": false,
|
26
|
+
"inlineSources": false,
|
27
|
+
"experimentalDecorators": true,
|
28
|
+
"strictPropertyInitialization": false,
|
29
|
+
"typeRoots": [
|
30
|
+
"./node_modules/@types"
|
31
|
+
]
|
32
|
+
},
|
33
|
+
"include": ["src/**/*"],
|
34
|
+
"exclude": [ "node_modules" ]
|
35
|
+
}
|