@dsmrt/axiom-cli 0.0.11 → 0.1.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/CHANGELOG.md +15 -0
- package/dist/bin/axiom.d.mts +1 -0
- package/{lib → dist}/bin/axiom.d.ts +0 -1
- package/dist/bin/axiom.js +403 -0
- package/dist/bin/axiom.mjs +2 -0
- package/dist/chunk-D4DGV6KK.mjs +395 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +426 -0
- package/dist/index.mjs +18 -0
- package/package.json +13 -10
- package/tsconfig.json +5 -4
- package/lib/aws/credentials-provider.d.ts +0 -17
- package/lib/aws/credentials-provider.js +0 -74
- package/lib/bin/axiom.js +0 -26
- package/lib/cache.d.ts +0 -11
- package/lib/cache.js +0 -62
- package/lib/commands/config.d.ts +0 -12
- package/lib/commands/config.js +0 -21
- package/lib/commands/index.d.ts +0 -2
- package/lib/commands/index.js +0 -18
- package/lib/commands/params/base.d.ts +0 -10
- package/lib/commands/params/base.js +0 -21
- package/lib/commands/params/delete.d.ts +0 -17
- package/lib/commands/params/delete.js +0 -63
- package/lib/commands/params/get.d.ts +0 -11
- package/lib/commands/params/get.js +0 -45
- package/lib/commands/params/index.d.ts +0 -4
- package/lib/commands/params/index.js +0 -20
- package/lib/commands/params/set.d.ts +0 -16
- package/lib/commands/params/set.js +0 -76
- package/lib/commands/params/utils.d.ts +0 -2
- package/lib/commands/params/utils.js +0 -15
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -20
- package/lib/options.d.ts +0 -7
- package/lib/options.js +0 -33
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @dsmrt/axiom-cli
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c3ffa47: Updating build and publishing tools to use tsup for esm support and @changesets/cli
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 533b167: trying to figure out changeset
|
|
12
|
+
- Updated dependencies [c3ffa47]
|
|
13
|
+
- Updated dependencies [533b167]
|
|
14
|
+
- @dsmrt/axiom-aws-sdk@0.1.0
|
|
15
|
+
- @dsmrt/axiom-config@0.1.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/bin/axiom.ts
|
|
27
|
+
var import_yargs = __toESM(require("yargs"));
|
|
28
|
+
|
|
29
|
+
// src/commands/config.ts
|
|
30
|
+
var import_axiom_config = require("@dsmrt/axiom-config");
|
|
31
|
+
var Config = class {
|
|
32
|
+
command = "config";
|
|
33
|
+
describe = "print the config";
|
|
34
|
+
builder = (args) => {
|
|
35
|
+
args.option("env", {
|
|
36
|
+
type: "string"
|
|
37
|
+
});
|
|
38
|
+
return args;
|
|
39
|
+
};
|
|
40
|
+
handler = async (args) => {
|
|
41
|
+
console.log(await this.loadConfig(args));
|
|
42
|
+
};
|
|
43
|
+
loadConfig = async (args) => {
|
|
44
|
+
return (0, import_axiom_config.loadConfig)(args);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/commands/params/base.ts
|
|
49
|
+
var ParamsCommand = class {
|
|
50
|
+
command = "params";
|
|
51
|
+
describe = "Manage SSM parameters";
|
|
52
|
+
builder = (args) => {
|
|
53
|
+
args.demandCommand().command(new GetCommand()).command(new SetCommand()).command(new DeleteCommand());
|
|
54
|
+
return args;
|
|
55
|
+
};
|
|
56
|
+
handler = async () => {
|
|
57
|
+
console.log("\u{1F44D}");
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/commands/params/get.ts
|
|
62
|
+
var import_axiom_config2 = require("@dsmrt/axiom-config");
|
|
63
|
+
var import_axiom_aws_sdk = require("@dsmrt/axiom-aws-sdk");
|
|
64
|
+
var import_client_ssm = require("@aws-sdk/client-ssm");
|
|
65
|
+
|
|
66
|
+
// src/aws/credentials-provider.ts
|
|
67
|
+
var import_credential_providers = require("@aws-sdk/credential-providers");
|
|
68
|
+
var import_client_sts = require("@aws-sdk/client-sts");
|
|
69
|
+
var import_inquirer = __toESM(require("inquirer"));
|
|
70
|
+
|
|
71
|
+
// src/cache.ts
|
|
72
|
+
var import_os = __toESM(require("os"));
|
|
73
|
+
var import_fs = __toESM(require("fs"));
|
|
74
|
+
var DEFAULT_DIRECTORY = `${import_os.default.homedir()}/.axiom/cache`;
|
|
75
|
+
var cache_default = class {
|
|
76
|
+
constructor(cacheDir = DEFAULT_DIRECTORY) {
|
|
77
|
+
this.cacheDir = cacheDir;
|
|
78
|
+
}
|
|
79
|
+
get(name) {
|
|
80
|
+
const file = `${this.cacheDir}/${name}`;
|
|
81
|
+
if (!import_fs.default.existsSync(file)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const buffer = import_fs.default.readFileSync(file);
|
|
85
|
+
const item = JSON.parse(buffer.toString());
|
|
86
|
+
if (item.expires === void 0) {
|
|
87
|
+
return item.data;
|
|
88
|
+
}
|
|
89
|
+
item.expires = new Date(item.expires);
|
|
90
|
+
if (item.expires < /* @__PURE__ */ new Date()) {
|
|
91
|
+
this.delete(name);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return item.data;
|
|
95
|
+
}
|
|
96
|
+
delete(name) {
|
|
97
|
+
import_fs.default.unlinkSync(`${this.cacheDir}/${name}`);
|
|
98
|
+
}
|
|
99
|
+
set(name, value, expires) {
|
|
100
|
+
if (!import_fs.default.existsSync(this.cacheDir)) {
|
|
101
|
+
import_fs.default.mkdirSync(this.cacheDir, {
|
|
102
|
+
recursive: true,
|
|
103
|
+
mode: 448
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
import_fs.default.writeFileSync(
|
|
107
|
+
`${this.cacheDir}/${name}`,
|
|
108
|
+
JSON.stringify({
|
|
109
|
+
expires,
|
|
110
|
+
data: value
|
|
111
|
+
}),
|
|
112
|
+
{
|
|
113
|
+
mode: 384
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/aws/credentials-provider.ts
|
|
120
|
+
var CACHE_KEY_PREFIX = "axiom#aws-credentials";
|
|
121
|
+
var cache = new cache_default();
|
|
122
|
+
var returnCredentialsFromAssumerole = (creds) => {
|
|
123
|
+
return {
|
|
124
|
+
accessKeyId: `${creds.AccessKeyId}`,
|
|
125
|
+
secretAccessKey: `${creds.SecretAccessKey}`,
|
|
126
|
+
sessionToken: `${creds.SessionToken}`
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
var CachedCredentialViaProfileAndRegion = async (profile, region) => {
|
|
130
|
+
const cacheKeyName = `${CACHE_KEY_PREFIX}#${profile}`;
|
|
131
|
+
const creds = cache.get(cacheKeyName);
|
|
132
|
+
if (creds !== void 0) {
|
|
133
|
+
return async () => returnCredentialsFromAssumerole(creds);
|
|
134
|
+
}
|
|
135
|
+
return (0, import_credential_providers.fromNodeProviderChain)({
|
|
136
|
+
profile,
|
|
137
|
+
roleAssumer: roleAssumerCallable({
|
|
138
|
+
region: region ?? "us-east-1",
|
|
139
|
+
cacheKeyName
|
|
140
|
+
}),
|
|
141
|
+
mfaCodeProvider
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
var roleAssumerCallable = (config) => {
|
|
145
|
+
return async (sourceCreds, params) => {
|
|
146
|
+
const command = new import_client_sts.AssumeRoleCommand(params);
|
|
147
|
+
const client = new import_client_sts.STSClient({
|
|
148
|
+
region: config.region,
|
|
149
|
+
credentials: sourceCreds
|
|
150
|
+
});
|
|
151
|
+
const result = await client.send(command);
|
|
152
|
+
const creds = result.Credentials;
|
|
153
|
+
if (creds === void 0 || creds?.AccessKeyId === void 0 || creds?.SecretAccessKey === void 0 || creds?.SessionToken === void 0) {
|
|
154
|
+
throw new Error("Unable to fetch credentials.");
|
|
155
|
+
}
|
|
156
|
+
cache.set(config.cacheKeyName, creds, creds.Expiration);
|
|
157
|
+
return returnCredentialsFromAssumerole(creds);
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
var mfaCodeProvider = async (mfaSerial) => {
|
|
161
|
+
const mfaCode = await import_inquirer.default.prompt({
|
|
162
|
+
name: "code",
|
|
163
|
+
message: `Enter MFA code for ${mfaSerial}: `,
|
|
164
|
+
type: "password"
|
|
165
|
+
});
|
|
166
|
+
return mfaCode.code;
|
|
167
|
+
};
|
|
168
|
+
var CachedCredentialProvider = (config) => {
|
|
169
|
+
return CachedCredentialViaProfileAndRegion(config.profile, config.region);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/options.ts
|
|
173
|
+
var commonOptions = () => {
|
|
174
|
+
return {
|
|
175
|
+
env: {
|
|
176
|
+
string: true,
|
|
177
|
+
desc: "Environment name like, prod, staging, dev, etc."
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
var awsOptions = () => {
|
|
182
|
+
return {
|
|
183
|
+
account: {
|
|
184
|
+
string: true,
|
|
185
|
+
desc: "AWS Account number like, 1243944546"
|
|
186
|
+
},
|
|
187
|
+
region: {
|
|
188
|
+
string: true,
|
|
189
|
+
desc: "AWS region like, us-east-1"
|
|
190
|
+
},
|
|
191
|
+
profile: {
|
|
192
|
+
string: true,
|
|
193
|
+
desc: "AWS configured profile"
|
|
194
|
+
},
|
|
195
|
+
baseParameterPath: {
|
|
196
|
+
string: true,
|
|
197
|
+
desc: "SSM parameter path base where configs like secrets and infrastucture managed items are set"
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/commands/params/utils.ts
|
|
203
|
+
var buildPath = (config, path) => {
|
|
204
|
+
if (path === void 0) {
|
|
205
|
+
return config.aws?.baseParameterPath;
|
|
206
|
+
}
|
|
207
|
+
if (/^\//.test(path)) {
|
|
208
|
+
return path;
|
|
209
|
+
}
|
|
210
|
+
return `${config.aws?.baseParameterPath.replace(/\/$/, "")}/${path}`;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/commands/params/get.ts
|
|
214
|
+
var import_chalk = __toESM(require("chalk"));
|
|
215
|
+
var GetCommand = class {
|
|
216
|
+
command = "get [path]";
|
|
217
|
+
describe = "Get all parameters under the base path";
|
|
218
|
+
builder = (args) => {
|
|
219
|
+
const config = (0, import_axiom_config2.loadConfig)();
|
|
220
|
+
args.options({ ...commonOptions(), ...awsOptions() });
|
|
221
|
+
args.positional("path", {
|
|
222
|
+
type: "string",
|
|
223
|
+
describe: `OPTIONAL path to parameter. Supports absolute and relative paths.
|
|
224
|
+
Example: "/root/myParam" or "service/secret" (which translates to, "${buildPath(
|
|
225
|
+
config,
|
|
226
|
+
"service/secret"
|
|
227
|
+
)})`
|
|
228
|
+
// default: config.awsSsmParameterPath,
|
|
229
|
+
});
|
|
230
|
+
return args;
|
|
231
|
+
};
|
|
232
|
+
handler = async (args) => {
|
|
233
|
+
const config = (0, import_axiom_config2.loadConfig)({ env: args.env });
|
|
234
|
+
const collection = new import_axiom_aws_sdk.ParameterCollection(
|
|
235
|
+
config.aws?.baseParameterPath,
|
|
236
|
+
new import_client_ssm.SSMClient({
|
|
237
|
+
region: config.aws.region,
|
|
238
|
+
credentials: await CachedCredentialProvider({
|
|
239
|
+
profile: config.aws.profile,
|
|
240
|
+
region: config.aws.region,
|
|
241
|
+
baseParameterPath: config.aws.baseParameterPath,
|
|
242
|
+
account: config.aws.account
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
);
|
|
246
|
+
const params = await collection.get();
|
|
247
|
+
params.forEach((parameter) => {
|
|
248
|
+
console.log(
|
|
249
|
+
import_chalk.default.gray(
|
|
250
|
+
parameter.Name?.replace(/\/([^/]+)$/, "/" + import_chalk.default.bold.green("$1"))
|
|
251
|
+
),
|
|
252
|
+
import_chalk.default.bold.white(parameter.Value)
|
|
253
|
+
);
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/commands/params/set.ts
|
|
259
|
+
var import_axiom_config3 = require("@dsmrt/axiom-config");
|
|
260
|
+
var import_inquirer2 = __toESM(require("inquirer"));
|
|
261
|
+
var import_client_ssm2 = require("@aws-sdk/client-ssm");
|
|
262
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
263
|
+
var SetCommand = class {
|
|
264
|
+
command = "set <path> <value>";
|
|
265
|
+
describe = "Set all parameters under the base path";
|
|
266
|
+
builder = (args) => {
|
|
267
|
+
const config = (0, import_axiom_config3.loadConfig)();
|
|
268
|
+
args.positional("path", {
|
|
269
|
+
type: "string",
|
|
270
|
+
describe: `Path to parameter. Supports absolute and relative paths.
|
|
271
|
+
Example: "/root/myParam" or "service/secret" (which translates to, "${buildPath(
|
|
272
|
+
config,
|
|
273
|
+
"service/secret"
|
|
274
|
+
)})`
|
|
275
|
+
});
|
|
276
|
+
args.demandOption("path", "Path is required");
|
|
277
|
+
args.positional("value", {
|
|
278
|
+
type: "string"
|
|
279
|
+
});
|
|
280
|
+
args.demandOption("value", "Value is required");
|
|
281
|
+
args.option("force", {
|
|
282
|
+
boolean: true,
|
|
283
|
+
default: false,
|
|
284
|
+
describe: "force set parameter without prompt",
|
|
285
|
+
alias: "f"
|
|
286
|
+
});
|
|
287
|
+
args.option("secure", {
|
|
288
|
+
boolean: true,
|
|
289
|
+
default: true,
|
|
290
|
+
describe: "Save parameter as a secure string"
|
|
291
|
+
});
|
|
292
|
+
args.option("overwrite", {
|
|
293
|
+
boolean: true,
|
|
294
|
+
default: true,
|
|
295
|
+
describe: "Overwrite parameter if it already exists"
|
|
296
|
+
});
|
|
297
|
+
return args.options({
|
|
298
|
+
...commonOptions(),
|
|
299
|
+
...awsOptions()
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
handler = async (args) => {
|
|
303
|
+
const config = (0, import_axiom_config3.loadConfig)({ env: args.env });
|
|
304
|
+
if (args.force !== true) {
|
|
305
|
+
const res = await import_inquirer2.default.prompt({
|
|
306
|
+
type: "confirm",
|
|
307
|
+
name: "setParam",
|
|
308
|
+
message: `Are you sure you want to set '${args.path}'?`
|
|
309
|
+
});
|
|
310
|
+
if (!res.setParam) {
|
|
311
|
+
console.log("Doing nothing.");
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const client = new import_client_ssm2.SSMClient({
|
|
316
|
+
region: config.aws.region,
|
|
317
|
+
credentials: await CachedCredentialProvider(config.aws)
|
|
318
|
+
});
|
|
319
|
+
const params = await client.send(
|
|
320
|
+
new import_client_ssm2.PutParameterCommand({
|
|
321
|
+
Name: buildPath(config, args.path),
|
|
322
|
+
Value: args.value,
|
|
323
|
+
Type: args.secure ? import_client_ssm2.ParameterType.SECURE_STRING : import_client_ssm2.ParameterType.STRING,
|
|
324
|
+
Overwrite: args.overwrite
|
|
325
|
+
})
|
|
326
|
+
);
|
|
327
|
+
console.log(import_chalk2.default.green("Version: "), import_chalk2.default.white.bold(params.Version));
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// src/commands/params/delete.ts
|
|
332
|
+
var import_axiom_config4 = require("@dsmrt/axiom-config");
|
|
333
|
+
var import_inquirer3 = __toESM(require("inquirer"));
|
|
334
|
+
var import_client_ssm3 = require("@aws-sdk/client-ssm");
|
|
335
|
+
var log = console.log;
|
|
336
|
+
var DeleteCommand = class {
|
|
337
|
+
command = "delete <path>";
|
|
338
|
+
describe = "Delete SSM parameters";
|
|
339
|
+
client;
|
|
340
|
+
builder = (args) => {
|
|
341
|
+
const config = (0, import_axiom_config4.loadConfig)();
|
|
342
|
+
args.positional("path", {
|
|
343
|
+
type: "string",
|
|
344
|
+
describe: `Path to parameter. Supports absolute and relative paths.
|
|
345
|
+
Example: "/root/myParam" or "service/secret" (which translates to, "${buildPath(
|
|
346
|
+
config,
|
|
347
|
+
"service/secret"
|
|
348
|
+
)})`,
|
|
349
|
+
default: config.aws?.baseParameterPath,
|
|
350
|
+
demandOption: true
|
|
351
|
+
}).demandOption("path", "Path is required");
|
|
352
|
+
args.option("force", {
|
|
353
|
+
boolean: true,
|
|
354
|
+
default: false,
|
|
355
|
+
describe: "force delete parameter without prompt",
|
|
356
|
+
alias: "f"
|
|
357
|
+
});
|
|
358
|
+
return args;
|
|
359
|
+
};
|
|
360
|
+
handler = async (args) => {
|
|
361
|
+
const config = (0, import_axiom_config4.loadConfig)({ env: args.env });
|
|
362
|
+
const path = buildPath(args, args.path);
|
|
363
|
+
const client = new import_client_ssm3.SSMClient({
|
|
364
|
+
region: config.aws?.region,
|
|
365
|
+
credentials: await CachedCredentialProvider(config.aws)
|
|
366
|
+
});
|
|
367
|
+
if (path === args.aws.baseParameterPath) {
|
|
368
|
+
throw new Error(
|
|
369
|
+
`Deleting the path (path: ${path}) that matches the base path (awsSsmParameterPath: ${args.awsSsmParameterPath}) is prohibited.`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
if (args.force !== true) {
|
|
373
|
+
const res = await import_inquirer3.default.prompt({
|
|
374
|
+
type: "confirm",
|
|
375
|
+
name: "delete",
|
|
376
|
+
message: `Are you sure you want to delete '${path}'?`
|
|
377
|
+
});
|
|
378
|
+
if (!res.delete) {
|
|
379
|
+
log("Doing nothing.");
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
await client.send(
|
|
384
|
+
new import_client_ssm3.DeleteParameterCommand({
|
|
385
|
+
Name: path
|
|
386
|
+
})
|
|
387
|
+
);
|
|
388
|
+
log("\u{1F44D}");
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// src/bin/axiom.ts
|
|
393
|
+
(0, import_yargs.default)(process.argv.slice(2)).env("AXIOM").scriptName("axiom").option("config", {
|
|
394
|
+
alias: "c",
|
|
395
|
+
string: true
|
|
396
|
+
}).command(new Config()).command(new ParamsCommand()).strict().usage(
|
|
397
|
+
`
|
|
398
|
+
Axiom - an AWS focused config cli
|
|
399
|
+
|
|
400
|
+
USAGE:
|
|
401
|
+
$0 [options] <command>
|
|
402
|
+
`
|
|
403
|
+
).demandCommand(1, "").alias("h", "help").argv;
|