-
Notifications
You must be signed in to change notification settings - Fork 1
/
read.ts
101 lines (90 loc) · 2.94 KB
/
read.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
100
101
import { Flags } from '@oclif/core';
import { CommandError } from '@oclif/core/lib/interfaces';
import { ConfigFile, Source } from '../../config';
import { ConfigFileDoesNotExistError } from '../../errors';
import ParameterConfigNotFoundError from '../../errors/parameter-config-not-found-error';
import SSMBaseCommand from '../../ssm-base-command';
import { DataLogger } from '../../utils';
import { OutputFormat } from '../../utils/data-logger';
export default class SSMRead extends SSMBaseCommand<typeof SSMRead> {
static description = 'Read a parameter from Parameter Store.';
static examples = [
'<%= config.bin %> <%= command.id %> --name /example/var',
'<%= config.bin %> <%= command.id %> --name /example/var --latest',
'<%= config.bin %> <%= command.id %> --name /example/var --version 3 --quiet',
];
static flags = {
name: Flags.string({
char: 'n',
description: 'the name of the parameter',
required: true,
}),
version: Flags.string({
char: 'v',
description: 'the version of the parameter to read, defaults to the version in your .griffin-config.yaml file',
exclusive: ['latest'],
}),
latest: Flags.boolean({
char: 'l',
description: 'read the latest version',
exclusive: ['version'],
}),
quiet: Flags.boolean({
char: 'q',
description: 'print only the parameter value',
}),
...DataLogger.flags,
};
public async run(): Promise<void> {
try {
let { version } = this.flags;
if (!version) {
if (this.flags.latest) {
version = await this.ssmStore.getCurrentVersion(this.flags.name);
} else {
if (!await ConfigFile.doesExist(this.flags.env)) {
throw new ConfigFileDoesNotExistError();
}
const paramConfig = this.configFile.getParamConfig(Source.SSM, this.flags.name);
if (!paramConfig) {
throw new ParameterConfigNotFoundError(this.flags.name);
}
version = paramConfig.version ? paramConfig.version : await this
.ssmStore
.getCurrentVersion(
this.flags.name,
);
}
}
const res = await this.ssmStore.getParamRecord(this.flags.name, version);
if (this.flags.quiet) {
this.log(res.value);
return;
}
DataLogger.log(
{
name: {},
description: {
extended: true,
},
value: {},
version: {},
modifiedAt: {},
modifiedBy: {},
},
[res],
{
columns: this.flags.columns,
sort: this.flags.sort,
filter: this.flags.filter,
output: this.flags.output as OutputFormat,
extended: this.flags.extended,
'no-truncate': this.flags['no-truncate'],
'no-header': this.flags['no-header'],
},
);
} catch (err) {
await this.catch(err as CommandError);
}
}
}