/
public-dns-namespace.ts
99 lines (82 loc) · 2.58 KB
/
public-dns-namespace.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { Construct } from 'constructs';
import { BaseNamespaceProps, INamespace, NamespaceType } from './namespace';
import { DnsServiceProps, Service } from './service';
import { CfnPublicDnsNamespace } from './servicediscovery.generated';
import { Resource } from '../../core';
export interface PublicDnsNamespaceProps extends BaseNamespaceProps {}
export interface IPublicDnsNamespace extends INamespace { }
export interface PublicDnsNamespaceAttributes {
/**
* A name for the Namespace.
*/
readonly namespaceName: string;
/**
* Namespace Id for the Namespace.
*/
readonly namespaceId: string;
/**
* Namespace ARN for the Namespace.
*/
readonly namespaceArn: string;
}
/**
* Define a Public DNS Namespace
*/
export class PublicDnsNamespace extends Resource implements IPublicDnsNamespace {
public static fromPublicDnsNamespaceAttributes(scope: Construct, id: string, attrs: PublicDnsNamespaceAttributes): IPublicDnsNamespace {
class Import extends Resource implements IPublicDnsNamespace {
public namespaceName = attrs.namespaceName;
public namespaceId = attrs.namespaceId;
public namespaceArn = attrs.namespaceArn;
public type = NamespaceType.DNS_PUBLIC;
}
return new Import(scope, id);
}
/**
* A name for the namespace.
*/
public readonly namespaceName: string;
/**
* Namespace Id for the namespace.
*/
public readonly namespaceId: string;
/**
* Namespace Arn for the namespace.
*/
public readonly namespaceArn: string;
/**
* ID of hosted zone created by namespace
*/
public readonly namespaceHostedZoneId: string;
/**
* Type of the namespace.
*/
public readonly type: NamespaceType;
constructor(scope: Construct, id: string, props: PublicDnsNamespaceProps) {
super(scope, id);
const ns = new CfnPublicDnsNamespace(this, 'Resource', {
name: props.name,
description: props.description,
});
this.namespaceName = props.name;
this.namespaceId = ns.attrId;
this.namespaceArn = ns.attrArn;
this.namespaceHostedZoneId = ns.attrHostedZoneId;
this.type = NamespaceType.DNS_PUBLIC;
}
/** @attribute */
public get publicDnsNamespaceArn() { return this.namespaceArn; }
/** @attribute */
public get publicDnsNamespaceName() { return this.namespaceName; }
/** @attribute */
public get publicDnsNamespaceId() { return this.namespaceId; }
/**
* Creates a service within the namespace
*/
public createService(id: string, props?: DnsServiceProps): Service {
return new Service(this, id, {
namespace: this,
...props,
});
}
}