/
ingresses.ts
58 lines (50 loc) · 1.72 KB
/
ingresses.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
import AccountUtils from '../../architect/account/account.utils';
import { EnvironmentUtils } from '../../architect/environment/environment.utils';
import BaseCommand from '../../base-command';
type CertificateResponse = {
spec: {
dnsNames: string[];
};
status: {
notAfter: Date;
notBefore: Date;
renewalTime: Date;
}
};
export default class GetEnvironmentIngressesCmd extends BaseCommand {
static description = 'List the resolvable URLs for services exposed by your environment';
static aliases = ['environment:ingresses', 'envs:ingresses', 'env:ingresses'];
static flags = {
...BaseCommand.flags,
...AccountUtils.flags,
};
static args = [
{
sensitive: false,
required: false,
name: 'environment',
description: 'Name to give the environment',
parse: async (value: string): Promise<string> => value.toLowerCase(),
},
];
async run(): Promise<void> {
const { args, flags } = await this.parse(GetEnvironmentIngressesCmd);
const account = await AccountUtils.getAccount(this.app, flags.account);
const environment = await EnvironmentUtils.getEnvironment(this.app.api, account, { environment_name: args.environment });
const { data: certificates } = await this.app.api.get<CertificateResponse[]>(`/environments/${environment.id}/certificates`);
if (certificates.length > 0) {
const dns_records: string[] = [];
for (const cert of certificates) {
for (const dns_name of cert.spec.dnsNames
.filter(dns_name => !dns_name.startsWith('env--'))) {
dns_records.push(dns_name);
}
}
this.log(
dns_records
.map(record => `https://${record}`)
.join('\r\n'),
);
}
}
}