@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 CHANGED
@@ -1,10 +1,10 @@
1
- import {IDeployStack} from "./IDeployStack";
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 {IDomainConfig} from "./IDomainConfig";
4
+ import IDeployStack from "./IDeployStack";
5
+ import IDomainConfig from "./IDomainConfig";
6
6
 
7
- export default class ApiCertificate extends DnsValidatedCertificate {
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
@@ -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
@@ -0,0 +1,8 @@
1
+ import IHostedZoneConfig from "./IHostedZoneConfig";
2
+
3
+ export interface IDomainConfig {
4
+ domainName: string,
5
+ subdomain?: string,
6
+ hostedZone: IHostedZoneConfig
7
+ }
8
+ export default IDomainConfig
@@ -0,0 +1,5 @@
1
+ export interface IHostedZoneConfig {
2
+ name: string,
3
+ id: string
4
+ }
5
+ export default IHostedZoneConfig
@@ -0,0 +1,8 @@
1
+ import {StackProps} from 'aws-cdk-lib/core';
2
+
3
+ export interface IStackArguments extends StackProps {
4
+ stage: string,
5
+ project: string,
6
+ owner: string
7
+ }
8
+ export default IStackArguments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byaga/cdk-patterns",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
5
5
  "main": " ",
6
6
  "scripts": {
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>