@dsmrt/axiom-cli 0.0.10 → 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/lib/cache.js DELETED
@@ -1,62 +0,0 @@
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;
@@ -1,12 +0,0 @@
1
- import { CommandModule, ArgumentsCamelCase, CommandBuilder } from "yargs";
2
- interface ConfigOptions {
3
- env: string;
4
- }
5
- export declare class Config<U extends ConfigOptions> implements CommandModule<object, U> {
6
- command: string;
7
- describe: string;
8
- builder?: CommandBuilder<object, U> | undefined;
9
- handler: (args: ArgumentsCamelCase<U>) => Promise<void>;
10
- loadConfig: (args: ConfigOptions) => Promise<import("@dsmrt/axiom-config").ConfigContainer<object>>;
11
- }
12
- export {};
@@ -1,21 +0,0 @@
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
- builder = (args) => {
9
- args.option("env", {
10
- type: "string",
11
- });
12
- return args;
13
- };
14
- handler = async (args) => {
15
- console.log(await this.loadConfig(args));
16
- };
17
- loadConfig = async (args) => {
18
- return (0, axiom_config_1.loadConfig)(args);
19
- };
20
- }
21
- exports.Config = Config;
@@ -1,2 +0,0 @@
1
- export * from "./config";
2
- export * from "./params";
@@ -1,18 +0,0 @@
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);
@@ -1,10 +0,0 @@
1
- import { CommandModule, Argv } from "yargs";
2
- interface Options {
3
- }
4
- export declare class ParamsCommand<U extends Options> implements CommandModule<object, U> {
5
- command: string;
6
- describe: string;
7
- builder: (args: Argv) => Argv<U>;
8
- handler: () => Promise<void>;
9
- }
10
- export {};
@@ -1,21 +0,0 @@
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;
@@ -1,17 +0,0 @@
1
- import { CommandModule, Argv, ArgumentsCamelCase } from "yargs";
2
- import { Config } from "@dsmrt/axiom-config";
3
- import { SSMClient } from "@aws-sdk/client-ssm";
4
- type Path = string;
5
- export interface DeleteOptions {
6
- path?: Path;
7
- force: boolean;
8
- }
9
- type config = Config & DeleteOptions;
10
- export declare class DeleteCommand<U extends config> implements CommandModule<object, U> {
11
- command: string;
12
- describe: string;
13
- protected client: SSMClient | undefined;
14
- builder: (args: Argv) => Argv<U>;
15
- handler: (args: ArgumentsCamelCase<U>) => Promise<void>;
16
- }
17
- export {};
@@ -1,63 +0,0 @@
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;
@@ -1,11 +0,0 @@
1
- import { CommandModule, Argv, ArgumentsCamelCase } from "yargs";
2
- export interface GetOptions {
3
- env: string;
4
- path: string;
5
- }
6
- export declare class GetCommand<U extends GetOptions> implements CommandModule<object, U> {
7
- command: string;
8
- describe: string;
9
- builder: (args: Argv) => Argv<U>;
10
- handler: (args: ArgumentsCamelCase<U>) => Promise<void>;
11
- }
@@ -1,45 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- export * from "./base";
2
- export * from "./get";
3
- export * from "./set";
4
- export * from "./delete";
@@ -1,20 +0,0 @@
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);
@@ -1,16 +0,0 @@
1
- import { CommandModule, Argv, ArgumentsCamelCase } from "yargs";
2
- import { AwsConfigs } from "@dsmrt/axiom-config";
3
- export interface SetOptions extends AwsConfigs {
4
- env: string;
5
- path: string;
6
- value: string;
7
- force: boolean;
8
- secure: boolean;
9
- overwrite: boolean;
10
- }
11
- export declare class SetCommand<U extends SetOptions> implements CommandModule<object, U> {
12
- command: string;
13
- describe: string;
14
- builder: (args: Argv) => Argv<U>;
15
- handler: (args: ArgumentsCamelCase<U>) => Promise<void>;
16
- }
@@ -1,76 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import { Config } from "@dsmrt/axiom-config";
2
- export declare const buildPath: (config: Config, path?: string) => string;
@@ -1,15 +0,0 @@
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 DELETED
@@ -1,4 +0,0 @@
1
- export * from "./cache";
2
- export * from "./options";
3
- export * from "./commands";
4
- export * from "./bin/axiom";
package/lib/index.js DELETED
@@ -1,20 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- import { Options } from "yargs";
2
- export declare const commonOptions: () => {
3
- [key: string]: Options;
4
- };
5
- export declare const awsOptions: () => {
6
- [key: string]: Options;
7
- };
package/lib/options.js DELETED
@@ -1,33 +0,0 @@
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;