@dsmrt/axiom-cli 0.0.3 → 0.0.4
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/lib/aws/credentials-provider.js +74 -0
- package/lib/bin/axiom.js +26 -0
- package/lib/cache.d.ts +11 -0
- package/lib/cache.js +62 -0
- package/lib/commands/config.js +15 -0
- package/lib/commands/index.js +18 -0
- package/lib/commands/params/base.js +21 -0
- package/lib/commands/params/delete.js +63 -0
- package/lib/commands/params/get.js +45 -0
- package/lib/commands/params/index.js +20 -0
- package/lib/commands/params/set.js +76 -0
- package/lib/commands/params/utils.js +15 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +20 -0
- package/lib/options.d.ts +7 -0
- package/lib/options.js +33 -0
- package/package.json +3 -3
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CachedCredentialProvider = exports.mfaCodeProvider = exports.roleAssumerCallable = exports.returnCredentialsFromAssumerole = void 0;
|
|
7
|
+
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
8
|
+
const client_sts_1 = require("@aws-sdk/client-sts");
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const cache_1 = __importDefault(require("../cache"));
|
|
11
|
+
const CACHE_KEY_PREFIX = "axiom#aws-credentials";
|
|
12
|
+
const cache = new cache_1.default();
|
|
13
|
+
const returnCredentialsFromAssumerole = (creds) => {
|
|
14
|
+
return {
|
|
15
|
+
accessKeyId: `${creds.AccessKeyId}`,
|
|
16
|
+
secretAccessKey: `${creds.SecretAccessKey}`,
|
|
17
|
+
sessionToken: `${creds.SessionToken}`,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.returnCredentialsFromAssumerole = returnCredentialsFromAssumerole;
|
|
21
|
+
const CachedCredentialViaProfileAndRegion = async (profile, region) => {
|
|
22
|
+
const cacheKeyName = `${CACHE_KEY_PREFIX}#${profile}`;
|
|
23
|
+
// check if there's a cache
|
|
24
|
+
const creds = cache.get(cacheKeyName);
|
|
25
|
+
// return the cache if there's something there
|
|
26
|
+
if (creds !== undefined) {
|
|
27
|
+
return async () => (0, exports.returnCredentialsFromAssumerole)(creds);
|
|
28
|
+
}
|
|
29
|
+
// else return
|
|
30
|
+
return (0, credential_providers_1.fromNodeProviderChain)({
|
|
31
|
+
profile,
|
|
32
|
+
roleAssumer: (0, exports.roleAssumerCallable)({
|
|
33
|
+
region: region ?? "us-east-1",
|
|
34
|
+
cacheKeyName: cacheKeyName,
|
|
35
|
+
}),
|
|
36
|
+
mfaCodeProvider: exports.mfaCodeProvider,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const roleAssumerCallable = (config) => {
|
|
40
|
+
return async (sourceCreds, params) => {
|
|
41
|
+
const command = new client_sts_1.AssumeRoleCommand(params);
|
|
42
|
+
const client = new client_sts_1.STSClient({
|
|
43
|
+
region: config.region,
|
|
44
|
+
credentials: sourceCreds,
|
|
45
|
+
});
|
|
46
|
+
const result = await client.send(command);
|
|
47
|
+
const creds = result.Credentials;
|
|
48
|
+
if (creds === undefined ||
|
|
49
|
+
creds?.AccessKeyId === undefined ||
|
|
50
|
+
creds?.SecretAccessKey === undefined ||
|
|
51
|
+
creds?.SessionToken === undefined) {
|
|
52
|
+
throw new Error("Unable to fetch credentials.");
|
|
53
|
+
}
|
|
54
|
+
// set cache
|
|
55
|
+
cache.set(config.cacheKeyName, creds, creds.Expiration);
|
|
56
|
+
return (0, exports.returnCredentialsFromAssumerole)(creds);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.roleAssumerCallable = roleAssumerCallable;
|
|
60
|
+
const mfaCodeProvider = async (mfaSerial) => {
|
|
61
|
+
// return mfaSerial
|
|
62
|
+
const mfaCode = await inquirer_1.default.prompt({
|
|
63
|
+
name: "code",
|
|
64
|
+
message: `Enter MFA code for ${mfaSerial}: `,
|
|
65
|
+
type: "password",
|
|
66
|
+
});
|
|
67
|
+
return mfaCode.code;
|
|
68
|
+
};
|
|
69
|
+
exports.mfaCodeProvider = mfaCodeProvider;
|
|
70
|
+
const CachedCredentialProvider = (config) => {
|
|
71
|
+
return CachedCredentialViaProfileAndRegion(config.profile, config.region);
|
|
72
|
+
};
|
|
73
|
+
exports.CachedCredentialProvider = CachedCredentialProvider;
|
|
74
|
+
exports.default = CachedCredentialViaProfileAndRegion;
|
package/lib/bin/axiom.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
+
const commands_1 = require("../commands");
|
|
9
|
+
(0, yargs_1.default)(process.argv.slice(2))
|
|
10
|
+
.env("AXIOM")
|
|
11
|
+
.scriptName("axiom")
|
|
12
|
+
.option("config", {
|
|
13
|
+
alias: "c",
|
|
14
|
+
string: true,
|
|
15
|
+
})
|
|
16
|
+
.command(new commands_1.Config())
|
|
17
|
+
.command(new commands_1.ParamsCommand())
|
|
18
|
+
.strict()
|
|
19
|
+
.usage(`
|
|
20
|
+
Axiom - an AWS focused config cli
|
|
21
|
+
|
|
22
|
+
USAGE:
|
|
23
|
+
$0 [options] <command>
|
|
24
|
+
`)
|
|
25
|
+
.demandCommand(1, "")
|
|
26
|
+
.alias("h", "help").argv;
|
package/lib/cache.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface Item {
|
|
2
|
+
expires?: Date;
|
|
3
|
+
data: unknown;
|
|
4
|
+
}
|
|
5
|
+
export default class {
|
|
6
|
+
private cacheDir;
|
|
7
|
+
constructor(cacheDir?: string);
|
|
8
|
+
get<T = object>(name: string): T | undefined;
|
|
9
|
+
delete(name: string): void;
|
|
10
|
+
set(name: string, value: unknown, expires?: Date): void;
|
|
11
|
+
}
|
package/lib/cache.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const os_1 = __importDefault(require("os"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const DEFAULT_DIRECTORY = `${os_1.default.homedir()}/.axiom/cache`;
|
|
9
|
+
class default_1 {
|
|
10
|
+
cacheDir;
|
|
11
|
+
constructor(cacheDir = DEFAULT_DIRECTORY) {
|
|
12
|
+
this.cacheDir = cacheDir;
|
|
13
|
+
}
|
|
14
|
+
get(name) {
|
|
15
|
+
const file = `${this.cacheDir}/${name}`;
|
|
16
|
+
/**
|
|
17
|
+
* does this item exist?
|
|
18
|
+
*/
|
|
19
|
+
if (!fs_1.default.existsSync(file)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const buffer = fs_1.default.readFileSync(file);
|
|
23
|
+
/**
|
|
24
|
+
* fetch the item
|
|
25
|
+
*/
|
|
26
|
+
const item = JSON.parse(buffer.toString());
|
|
27
|
+
/**
|
|
28
|
+
* Just return it
|
|
29
|
+
*/
|
|
30
|
+
if (item.expires === undefined) {
|
|
31
|
+
return item.data;
|
|
32
|
+
}
|
|
33
|
+
item.expires = new Date(item.expires);
|
|
34
|
+
/**
|
|
35
|
+
* Exired?
|
|
36
|
+
* delete if so
|
|
37
|
+
*/
|
|
38
|
+
if (item.expires < new Date()) {
|
|
39
|
+
this.delete(name);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return item.data;
|
|
43
|
+
}
|
|
44
|
+
delete(name) {
|
|
45
|
+
fs_1.default.unlinkSync(`${this.cacheDir}/${name}`);
|
|
46
|
+
}
|
|
47
|
+
set(name, value, expires) {
|
|
48
|
+
if (!fs_1.default.existsSync(this.cacheDir)) {
|
|
49
|
+
fs_1.default.mkdirSync(this.cacheDir, {
|
|
50
|
+
recursive: true,
|
|
51
|
+
mode: 0o700,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
fs_1.default.writeFileSync(`${this.cacheDir}/${name}`, JSON.stringify({
|
|
55
|
+
expires,
|
|
56
|
+
data: value,
|
|
57
|
+
}), {
|
|
58
|
+
mode: 0o600,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Config = void 0;
|
|
4
|
+
const axiom_config_1 = require("@dsmrt/axiom-config");
|
|
5
|
+
class Config {
|
|
6
|
+
command = "config";
|
|
7
|
+
describe = "print the config";
|
|
8
|
+
handler = async (args) => {
|
|
9
|
+
console.log(await this.loadConfig(args));
|
|
10
|
+
};
|
|
11
|
+
loadConfig = async (args) => {
|
|
12
|
+
return (0, axiom_config_1.loadConfig)(args);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.Config = Config;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config"), exports);
|
|
18
|
+
__exportStar(require("./params"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParamsCommand = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
class ParamsCommand {
|
|
6
|
+
command = "params";
|
|
7
|
+
describe = "Manage SSM parameters";
|
|
8
|
+
builder = (args) => {
|
|
9
|
+
args
|
|
10
|
+
.demandCommand()
|
|
11
|
+
.command(new _1.GetCommand())
|
|
12
|
+
.command(new _1.SetCommand())
|
|
13
|
+
.command(new _1.DeleteCommand());
|
|
14
|
+
return args;
|
|
15
|
+
};
|
|
16
|
+
handler = async () => {
|
|
17
|
+
// Is this needed?
|
|
18
|
+
console.log("👍");
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.ParamsCommand = ParamsCommand;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DeleteCommand = void 0;
|
|
7
|
+
const axiom_config_1 = require("@dsmrt/axiom-config");
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const credentials_provider_1 = require("../../aws/credentials-provider");
|
|
12
|
+
const log = console.log;
|
|
13
|
+
class DeleteCommand {
|
|
14
|
+
command = "delete <path>";
|
|
15
|
+
describe = "Delete SSM parameters";
|
|
16
|
+
client;
|
|
17
|
+
builder = (args) => {
|
|
18
|
+
const config = (0, axiom_config_1.loadConfig)();
|
|
19
|
+
args
|
|
20
|
+
.positional("path", {
|
|
21
|
+
type: "string",
|
|
22
|
+
describe: `Path to parameter. Supports absolute and relative paths.` +
|
|
23
|
+
`\nExample: "/root/myParam" or "service/secret" (which translates to, "${(0, utils_1.buildPath)(config, "service/secret")})`,
|
|
24
|
+
default: config.aws?.baseParameterPath,
|
|
25
|
+
demandOption: true,
|
|
26
|
+
})
|
|
27
|
+
.demandOption("path", "Path is required");
|
|
28
|
+
args.option("force", {
|
|
29
|
+
boolean: true,
|
|
30
|
+
default: false,
|
|
31
|
+
describe: "force delete parameter without prompt",
|
|
32
|
+
alias: "f",
|
|
33
|
+
});
|
|
34
|
+
return args;
|
|
35
|
+
};
|
|
36
|
+
handler = async (args) => {
|
|
37
|
+
const config = (0, axiom_config_1.loadConfig)({ env: args.env });
|
|
38
|
+
const path = (0, utils_1.buildPath)(args, args.path);
|
|
39
|
+
const client = new client_ssm_1.SSMClient({
|
|
40
|
+
region: config.aws?.region,
|
|
41
|
+
credentials: await (0, credentials_provider_1.CachedCredentialProvider)(config.aws),
|
|
42
|
+
});
|
|
43
|
+
if (path === args.aws.baseParameterPath) {
|
|
44
|
+
throw new Error(`Deleting the path (path: ${path}) that matches the base path (awsSsmParameterPath: ${args.awsSsmParameterPath}) is prohibited.`);
|
|
45
|
+
}
|
|
46
|
+
if (args.force !== true) {
|
|
47
|
+
const res = await inquirer_1.default.prompt({
|
|
48
|
+
type: "confirm",
|
|
49
|
+
name: "delete",
|
|
50
|
+
message: `Are you sure you want to delete '${path}'?`,
|
|
51
|
+
});
|
|
52
|
+
if (!res.delete) {
|
|
53
|
+
log("Doing nothing.");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
await client.send(new client_ssm_1.DeleteParameterCommand({
|
|
58
|
+
Name: path,
|
|
59
|
+
}));
|
|
60
|
+
log("👍");
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.DeleteCommand = DeleteCommand;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GetCommand = void 0;
|
|
7
|
+
const axiom_config_1 = require("@dsmrt/axiom-config");
|
|
8
|
+
const axiom_aws_sdk_1 = require("@dsmrt/axiom-aws-sdk");
|
|
9
|
+
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
10
|
+
const credentials_provider_1 = require("../../aws/credentials-provider");
|
|
11
|
+
const options_1 = require("../../options");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
class GetCommand {
|
|
15
|
+
command = "get [path]";
|
|
16
|
+
describe = "Get all parameters under the base path";
|
|
17
|
+
builder = (args) => {
|
|
18
|
+
const config = (0, axiom_config_1.loadConfig)();
|
|
19
|
+
args.options({ ...(0, options_1.commonOptions)(), ...(0, options_1.awsOptions)() });
|
|
20
|
+
args.positional("path", {
|
|
21
|
+
type: "string",
|
|
22
|
+
describe: `OPTIONAL path to parameter. Supports absolute and relative paths.` +
|
|
23
|
+
`\nExample: "/root/myParam" or "service/secret" (which translates to, "${(0, utils_1.buildPath)(config, "service/secret")})`,
|
|
24
|
+
// default: config.awsSsmParameterPath,
|
|
25
|
+
});
|
|
26
|
+
return args;
|
|
27
|
+
};
|
|
28
|
+
handler = async (args) => {
|
|
29
|
+
const config = (0, axiom_config_1.loadConfig)({ env: args.env });
|
|
30
|
+
const collection = new axiom_aws_sdk_1.ParameterCollection(config.aws?.baseParameterPath, new client_ssm_1.SSMClient({
|
|
31
|
+
region: config.aws.region,
|
|
32
|
+
credentials: await (0, credentials_provider_1.CachedCredentialProvider)({
|
|
33
|
+
profile: config.aws.profile,
|
|
34
|
+
region: config.aws.region,
|
|
35
|
+
baseParameterPath: config.aws.baseParameterPath,
|
|
36
|
+
account: config.aws.account,
|
|
37
|
+
}),
|
|
38
|
+
}));
|
|
39
|
+
const params = await collection.get();
|
|
40
|
+
params.forEach((parameter) => {
|
|
41
|
+
console.log(chalk_1.default.gray(parameter.Name?.replace(/\/([^/]+)$/, "/" + chalk_1.default.bold.green("$1"))), chalk_1.default.bold.white(parameter.Value));
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.GetCommand = GetCommand;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base"), exports);
|
|
18
|
+
__exportStar(require("./get"), exports);
|
|
19
|
+
__exportStar(require("./set"), exports);
|
|
20
|
+
__exportStar(require("./delete"), exports);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SetCommand = void 0;
|
|
7
|
+
const axiom_config_1 = require("@dsmrt/axiom-config");
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const client_ssm_1 = require("@aws-sdk/client-ssm");
|
|
10
|
+
const credentials_provider_1 = require("../../aws/credentials-provider");
|
|
11
|
+
const options_1 = require("../../options");
|
|
12
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
class SetCommand {
|
|
15
|
+
command = "set <path> <value>";
|
|
16
|
+
describe = "Set all parameters under the base path";
|
|
17
|
+
builder = (args) => {
|
|
18
|
+
const config = (0, axiom_config_1.loadConfig)();
|
|
19
|
+
args.positional("path", {
|
|
20
|
+
type: "string",
|
|
21
|
+
describe: `Path to parameter. Supports absolute and relative paths.` +
|
|
22
|
+
`\nExample: "/root/myParam" or "service/secret" (which translates to, "${(0, utils_1.buildPath)(config, "service/secret")})`,
|
|
23
|
+
});
|
|
24
|
+
args.demandOption("path", "Path is required");
|
|
25
|
+
args.positional("value", {
|
|
26
|
+
type: "string",
|
|
27
|
+
});
|
|
28
|
+
args.demandOption("value", "Value is required");
|
|
29
|
+
args.option("force", {
|
|
30
|
+
boolean: true,
|
|
31
|
+
default: false,
|
|
32
|
+
describe: "force set parameter without prompt",
|
|
33
|
+
alias: "f",
|
|
34
|
+
});
|
|
35
|
+
args.option("secure", {
|
|
36
|
+
boolean: true,
|
|
37
|
+
default: true,
|
|
38
|
+
describe: "Save parameter as a secure string",
|
|
39
|
+
});
|
|
40
|
+
args.option("overwrite", {
|
|
41
|
+
boolean: true,
|
|
42
|
+
default: true,
|
|
43
|
+
describe: "Overwrite parameter if it already exists",
|
|
44
|
+
});
|
|
45
|
+
return args.options({
|
|
46
|
+
...(0, options_1.commonOptions)(),
|
|
47
|
+
...(0, options_1.awsOptions)(),
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
handler = async (args) => {
|
|
51
|
+
const config = (0, axiom_config_1.loadConfig)({ env: args.env });
|
|
52
|
+
if (args.force !== true) {
|
|
53
|
+
const res = await inquirer_1.default.prompt({
|
|
54
|
+
type: "confirm",
|
|
55
|
+
name: "setParam",
|
|
56
|
+
message: `Are you sure you want to set '${args.path}'?`,
|
|
57
|
+
});
|
|
58
|
+
if (!res.setParam) {
|
|
59
|
+
console.log("Doing nothing.");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const client = new client_ssm_1.SSMClient({
|
|
64
|
+
region: config.aws.region,
|
|
65
|
+
credentials: await (0, credentials_provider_1.CachedCredentialProvider)(config.aws),
|
|
66
|
+
});
|
|
67
|
+
const params = await client.send(new client_ssm_1.PutParameterCommand({
|
|
68
|
+
Name: (0, utils_1.buildPath)(config, args.path),
|
|
69
|
+
Value: args.value,
|
|
70
|
+
Type: args.secure ? client_ssm_1.ParameterType.SECURE_STRING : client_ssm_1.ParameterType.STRING,
|
|
71
|
+
Overwrite: args.overwrite,
|
|
72
|
+
}));
|
|
73
|
+
console.log(chalk_1.default.green("Version: "), chalk_1.default.white.bold(params.Version));
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.SetCommand = SetCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPath = void 0;
|
|
4
|
+
const buildPath = (config, path) => {
|
|
5
|
+
if (path === undefined) {
|
|
6
|
+
return config.aws?.baseParameterPath;
|
|
7
|
+
}
|
|
8
|
+
// if it starts with a `/` use the absolute
|
|
9
|
+
if (/^\//.test(path)) {
|
|
10
|
+
return path;
|
|
11
|
+
}
|
|
12
|
+
// if it doens't, build off of the base path
|
|
13
|
+
return `${config.aws?.baseParameterPath.replace(/\/$/, "")}/${path}`;
|
|
14
|
+
};
|
|
15
|
+
exports.buildPath = buildPath;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cache"), exports);
|
|
18
|
+
__exportStar(require("./options"), exports);
|
|
19
|
+
__exportStar(require("./commands"), exports);
|
|
20
|
+
__exportStar(require("./bin/axiom"), exports);
|
package/lib/options.d.ts
ADDED
package/lib/options.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awsOptions = exports.commonOptions = void 0;
|
|
4
|
+
const commonOptions = () => {
|
|
5
|
+
return {
|
|
6
|
+
env: {
|
|
7
|
+
string: true,
|
|
8
|
+
desc: "Environment name like, prod, staging, dev, etc.",
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
exports.commonOptions = commonOptions;
|
|
13
|
+
const awsOptions = () => {
|
|
14
|
+
return {
|
|
15
|
+
account: {
|
|
16
|
+
string: true,
|
|
17
|
+
desc: "AWS Account number like, 1243944546",
|
|
18
|
+
},
|
|
19
|
+
region: {
|
|
20
|
+
string: true,
|
|
21
|
+
desc: "AWS region like, us-east-1",
|
|
22
|
+
},
|
|
23
|
+
profile: {
|
|
24
|
+
string: true,
|
|
25
|
+
desc: "AWS configured profile",
|
|
26
|
+
},
|
|
27
|
+
baseParameterPath: {
|
|
28
|
+
string: true,
|
|
29
|
+
desc: "SSM parameter path base where configs like secrets and infrastucture managed items are set",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.awsOptions = awsOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsmrt/axiom-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "axiom cli for managing configs including secrets",
|
|
5
5
|
"main": "lib/bin/axiom.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"chalk": "^4.1.2",
|
|
49
49
|
"inquirer": "^8.0.0",
|
|
50
50
|
"yargs": "^17.7.2",
|
|
51
|
-
"@dsmrt/axiom-
|
|
52
|
-
"@dsmrt/axiom-
|
|
51
|
+
"@dsmrt/axiom-config": "^0.0.4",
|
|
52
|
+
"@dsmrt/axiom-aws-sdk": "^0.0.4"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"lint": "eslint ./src/ --ext .ts",
|