dotsec 0.8.0 → 0.10.1-alpha.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/dist/cli.js +192 -77
- package/dist/cli.js.map +3 -3
- package/dist/esm/cli.js +217 -99
- package/dist/esm/cli.js.map +3 -3
- package/package.json +4 -2
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -18,6 +20,7 @@ var __spreadValues = (a, b) => {
|
|
|
18
20
|
}
|
|
19
21
|
return a;
|
|
20
22
|
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
24
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
22
25
|
var __export = (target, all) => {
|
|
23
26
|
__markAsModule(target);
|
|
@@ -75,8 +78,7 @@ var commonCliOptions = {
|
|
|
75
78
|
},
|
|
76
79
|
envFile: {
|
|
77
80
|
string: true,
|
|
78
|
-
describe: ".env file"
|
|
79
|
-
default: ".env"
|
|
81
|
+
describe: ".env file"
|
|
80
82
|
},
|
|
81
83
|
ignoreMissingEnvFile: {
|
|
82
84
|
boolean: true,
|
|
@@ -99,6 +101,14 @@ var commonCliOptions = {
|
|
|
99
101
|
boolean: true,
|
|
100
102
|
describe: "Be verbose"
|
|
101
103
|
},
|
|
104
|
+
encryptedSecretsFile: {
|
|
105
|
+
string: true,
|
|
106
|
+
describe: "filename of json file for reading encrypted secrets"
|
|
107
|
+
},
|
|
108
|
+
jsonFilter: {
|
|
109
|
+
string: true,
|
|
110
|
+
describe: "dot separated filter path, for example a.b.c will return { a: { b: { c: ... }}}"
|
|
111
|
+
},
|
|
102
112
|
yes: {
|
|
103
113
|
boolean: true,
|
|
104
114
|
describe: "Proceeds without confirmation"
|
|
@@ -321,11 +331,11 @@ __export(decryptSecCommand_exports, {
|
|
|
321
331
|
desc: () => desc2,
|
|
322
332
|
handler: () => handler2
|
|
323
333
|
});
|
|
324
|
-
var import_client_kms = __toModule(require("@aws-sdk/client-kms"));
|
|
325
|
-
var import_chalk2 = __toModule(require("chalk"));
|
|
326
|
-
var import_dotenv = __toModule(require("dotenv"));
|
|
327
334
|
var import_node_fs = __toModule(require("node:fs"));
|
|
328
335
|
var import_node_path = __toModule(require("node:path"));
|
|
336
|
+
var import_client_kms2 = __toModule(require("@aws-sdk/client-kms"));
|
|
337
|
+
var import_chalk2 = __toModule(require("chalk"));
|
|
338
|
+
var import_dotenv = __toModule(require("dotenv"));
|
|
329
339
|
|
|
330
340
|
// src/utils/io.ts
|
|
331
341
|
var import_promises = __toModule(require("fs/promises"));
|
|
@@ -357,6 +367,27 @@ var promptOverwriteIfFileExists = async ({
|
|
|
357
367
|
return overwriteResponse;
|
|
358
368
|
};
|
|
359
369
|
|
|
370
|
+
// src/utils/kms.ts
|
|
371
|
+
var import_client_kms = __toModule(require("@aws-sdk/client-kms"));
|
|
372
|
+
var getKMSClient = ({
|
|
373
|
+
configuration
|
|
374
|
+
}) => {
|
|
375
|
+
const kmsClient = new import_client_kms.KMSClient(configuration);
|
|
376
|
+
return kmsClient;
|
|
377
|
+
};
|
|
378
|
+
var getEncryptionAlgorithm = async (kmsClient, awsKeyAlias) => {
|
|
379
|
+
var _a, _b;
|
|
380
|
+
const describeKeyCommand = new import_client_kms.DescribeKeyCommand({
|
|
381
|
+
KeyId: awsKeyAlias
|
|
382
|
+
});
|
|
383
|
+
const describeKeyResult = await kmsClient.send(describeKeyCommand);
|
|
384
|
+
const encryptionAlgorithm = (_b = (_a = describeKeyResult.KeyMetadata) == null ? void 0 : _a.EncryptionAlgorithms) == null ? void 0 : _b[0];
|
|
385
|
+
if (encryptionAlgorithm === void 0) {
|
|
386
|
+
throw new Error(`Could not determine encryption algorithm`);
|
|
387
|
+
}
|
|
388
|
+
return encryptionAlgorithm;
|
|
389
|
+
};
|
|
390
|
+
|
|
360
391
|
// src/commands/decryptSecCommand.ts
|
|
361
392
|
var command2 = "decrypt-sec";
|
|
362
393
|
var desc2 = "Decrypts a dotsec file";
|
|
@@ -365,7 +396,7 @@ var builder2 = {
|
|
|
365
396
|
"aws-region": commonCliOptions.awsRegion,
|
|
366
397
|
"aws-key-alias": commonCliOptions.awsKeyAlias,
|
|
367
398
|
"assume-role-arn": commonCliOptions.awsAssumeRoleArn,
|
|
368
|
-
"env-file": commonCliOptions.envFile,
|
|
399
|
+
"env-file": __spreadProps(__spreadValues({}, commonCliOptions.envFile), { default: "env" }),
|
|
369
400
|
"sec-file": commonCliOptions.secFile,
|
|
370
401
|
verbose: commonCliOptions.verbose
|
|
371
402
|
};
|
|
@@ -381,15 +412,16 @@ var handler2 = async (argv) => {
|
|
|
381
412
|
return;
|
|
382
413
|
}
|
|
383
414
|
const parsedSec = (0, import_dotenv.parse)(import_node_fs.default.readFileSync(secSource, { encoding: "utf8" }));
|
|
384
|
-
const kmsClient = new
|
|
415
|
+
const kmsClient = new import_client_kms2.KMSClient({
|
|
385
416
|
credentials: credentialsAndOrigin.value,
|
|
386
417
|
region: regionAndOrigin.value
|
|
387
418
|
});
|
|
419
|
+
const encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, argv.awsKeyAlias);
|
|
388
420
|
const envEntries = await Promise.all(Object.entries(parsedSec).map(async ([key, cipherText]) => {
|
|
389
|
-
const decryptCommand = new
|
|
421
|
+
const decryptCommand = new import_client_kms2.DecryptCommand({
|
|
390
422
|
KeyId: argv.awsKeyAlias,
|
|
391
423
|
CiphertextBlob: Buffer.from(cipherText, "base64"),
|
|
392
|
-
EncryptionAlgorithm:
|
|
424
|
+
EncryptionAlgorithm: encryptionAlgorithm
|
|
393
425
|
});
|
|
394
426
|
const decryptionResult = await kmsClient.send(decryptCommand);
|
|
395
427
|
if (!(decryptionResult == null ? void 0 : decryptionResult.Plaintext)) {
|
|
@@ -416,22 +448,11 @@ __export(decryptSecretsJson_exports, {
|
|
|
416
448
|
desc: () => desc3,
|
|
417
449
|
handler: () => handler3
|
|
418
450
|
});
|
|
451
|
+
var import_node_fs2 = __toModule(require("node:fs"));
|
|
452
|
+
var import_node_path2 = __toModule(require("node:path"));
|
|
419
453
|
var import_client_kms3 = __toModule(require("@aws-sdk/client-kms"));
|
|
420
454
|
var import_chalk3 = __toModule(require("chalk"));
|
|
421
455
|
var import_flat = __toModule(require("flat"));
|
|
422
|
-
var import_node_fs2 = __toModule(require("node:fs"));
|
|
423
|
-
var import_node_path2 = __toModule(require("node:path"));
|
|
424
|
-
|
|
425
|
-
// src/utils/kms.ts
|
|
426
|
-
var import_client_kms2 = __toModule(require("@aws-sdk/client-kms"));
|
|
427
|
-
var getKMSClient = ({
|
|
428
|
-
configuration
|
|
429
|
-
}) => {
|
|
430
|
-
const kmsClient = new import_client_kms2.KMSClient(configuration);
|
|
431
|
-
return kmsClient;
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
// src/commands/decryptSecretsJson.ts
|
|
435
456
|
var command3 = "decrypt-secrets-json";
|
|
436
457
|
var desc3 = "Derypts an encrypted file";
|
|
437
458
|
var builder3 = {
|
|
@@ -443,11 +464,9 @@ var builder3 = {
|
|
|
443
464
|
describe: "filename of json file writing secrets",
|
|
444
465
|
default: "secrets.json"
|
|
445
466
|
},
|
|
446
|
-
"encrypted-secrets-file": {
|
|
447
|
-
string: true,
|
|
448
|
-
describe: "filename of json file for reading encrypted secrets",
|
|
467
|
+
"encrypted-secrets-file": __spreadProps(__spreadValues({}, commonCliOptions.encryptedSecretsFile), {
|
|
449
468
|
default: "secrets.encrypted.json"
|
|
450
|
-
},
|
|
469
|
+
}),
|
|
451
470
|
"assume-role-arn": commonCliOptions.awsAssumeRoleArn,
|
|
452
471
|
verbose: commonCliOptions.verbose,
|
|
453
472
|
yes: __spreadValues({}, commonCliOptions.yes)
|
|
@@ -484,11 +503,12 @@ var handler3 = async (argv) => {
|
|
|
484
503
|
const describeKeyResult = await kmsClient.send(describeKeyCommand);
|
|
485
504
|
console.log("describeKeyResult", { describeKeyResult });
|
|
486
505
|
}
|
|
506
|
+
const encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, argv.awsKeyAlias);
|
|
487
507
|
const flatParameters = Object.fromEntries(await Promise.all(Object.entries(flatEncryptedParameters).map(async ([parameterName, encryptedParameter]) => {
|
|
488
508
|
const decryptCommand = new import_client_kms3.DecryptCommand({
|
|
489
509
|
KeyId: argv.awsKeyAlias,
|
|
490
510
|
CiphertextBlob: Buffer.from(encryptedParameter, "base64"),
|
|
491
|
-
EncryptionAlgorithm:
|
|
511
|
+
EncryptionAlgorithm: encryptionAlgorithm
|
|
492
512
|
});
|
|
493
513
|
const decryptionResult = await kmsClient.send(decryptCommand);
|
|
494
514
|
if (!decryptionResult.Plaintext) {
|
|
@@ -533,9 +553,34 @@ __export(defaultCommand_exports, {
|
|
|
533
553
|
var import_node_fs3 = __toModule(require("node:fs"));
|
|
534
554
|
var import_node_path3 = __toModule(require("node:path"));
|
|
535
555
|
var import_client_kms4 = __toModule(require("@aws-sdk/client-kms"));
|
|
536
|
-
var
|
|
556
|
+
var import_chalk5 = __toModule(require("chalk"));
|
|
557
|
+
var import_constant_case = __toModule(require("constant-case"));
|
|
537
558
|
var import_cross_spawn = __toModule(require("cross-spawn"));
|
|
538
559
|
var import_dotenv2 = __toModule(require("dotenv"));
|
|
560
|
+
var import_flat2 = __toModule(require("flat"));
|
|
561
|
+
|
|
562
|
+
// src/lib/encryptedSecrets.ts
|
|
563
|
+
var import_fs = __toModule(require("fs"));
|
|
564
|
+
var import_path = __toModule(require("path"));
|
|
565
|
+
var import_chalk4 = __toModule(require("chalk"));
|
|
566
|
+
var loadEncryptedSecrets = async ({
|
|
567
|
+
encryptedSecretsFile
|
|
568
|
+
}) => {
|
|
569
|
+
const encryptedSecretsPath = import_path.default.resolve(process.cwd(), encryptedSecretsFile);
|
|
570
|
+
if (!await fileExists(encryptedSecretsPath)) {
|
|
571
|
+
throw new Error(`Could not open ${(0, import_chalk4.redBright)(encryptedSecretsPath)}`);
|
|
572
|
+
}
|
|
573
|
+
const encryptedSecrets = JSON.parse(import_fs.default.readFileSync(encryptedSecretsPath, { encoding: "utf8" }));
|
|
574
|
+
if (!encryptedSecrets) {
|
|
575
|
+
throw new Error(`No encrypted secrets found in ${(0, import_chalk4.redBright)(encryptedSecretsPath)}`);
|
|
576
|
+
}
|
|
577
|
+
if (!encryptedSecrets.encryptedParameters) {
|
|
578
|
+
throw new Error(`Expected 'encryptedParameters' property, but got none`);
|
|
579
|
+
}
|
|
580
|
+
return encryptedSecrets;
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
// src/commands/defaultCommand.ts
|
|
539
584
|
var command4 = "$0 <command>";
|
|
540
585
|
var desc4 = "Decrypts a .sec file, injects the results into a separate process and runs a command";
|
|
541
586
|
var builder4 = {
|
|
@@ -547,6 +592,8 @@ var builder4 = {
|
|
|
547
592
|
"ignore-missing-env-file": commonCliOptions.ignoreMissingEnvFile,
|
|
548
593
|
"aws-assume-role-arn": commonCliOptions.awsAssumeRoleArn,
|
|
549
594
|
"aws-assume-role-session-duration": commonCliOptions.awsAssumeRoleSessionDuration,
|
|
595
|
+
"encrypted-secrets-file": commonCliOptions.encryptedSecretsFile,
|
|
596
|
+
"json-filter": commonCliOptions.jsonFilter,
|
|
550
597
|
verbose: commonCliOptions.verbose,
|
|
551
598
|
command: { string: true, required: true }
|
|
552
599
|
};
|
|
@@ -558,7 +605,7 @@ var handleSec = async ({
|
|
|
558
605
|
}) => {
|
|
559
606
|
const secSource = import_node_path3.default.resolve(process.cwd(), secFile);
|
|
560
607
|
if (!await fileExists(secSource)) {
|
|
561
|
-
console.error(`Could not open ${(0,
|
|
608
|
+
console.error(`Could not open ${(0, import_chalk5.redBright)(secSource)}`);
|
|
562
609
|
return;
|
|
563
610
|
}
|
|
564
611
|
const parsedSec = (0, import_dotenv2.parse)(import_node_fs3.default.readFileSync(secSource, { encoding: "utf8" }));
|
|
@@ -566,11 +613,59 @@ var handleSec = async ({
|
|
|
566
613
|
credentials: credentialsAndOrigin.value,
|
|
567
614
|
region: regionAndOrigin.value
|
|
568
615
|
});
|
|
616
|
+
const encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, awsKeyAlias);
|
|
569
617
|
const envEntries = await Promise.all(Object.entries(parsedSec).map(async ([key, cipherText]) => {
|
|
570
618
|
const decryptCommand = new import_client_kms4.DecryptCommand({
|
|
571
619
|
KeyId: awsKeyAlias,
|
|
572
620
|
CiphertextBlob: Buffer.from(cipherText, "base64"),
|
|
573
|
-
EncryptionAlgorithm:
|
|
621
|
+
EncryptionAlgorithm: encryptionAlgorithm
|
|
622
|
+
});
|
|
623
|
+
const decryptionResult = await kmsClient.send(decryptCommand);
|
|
624
|
+
if (!(decryptionResult == null ? void 0 : decryptionResult.Plaintext)) {
|
|
625
|
+
throw new Error(`No: ${JSON.stringify({
|
|
626
|
+
key,
|
|
627
|
+
cipherText,
|
|
628
|
+
decryptCommand
|
|
629
|
+
})}`);
|
|
630
|
+
}
|
|
631
|
+
const value = Buffer.from(decryptionResult.Plaintext).toString();
|
|
632
|
+
return [key, value];
|
|
633
|
+
}));
|
|
634
|
+
const env = Object.fromEntries(envEntries);
|
|
635
|
+
return env;
|
|
636
|
+
};
|
|
637
|
+
var handleEncryptedJson = async ({
|
|
638
|
+
encryptedSecretsFile,
|
|
639
|
+
jsonFilter,
|
|
640
|
+
credentialsAndOrigin,
|
|
641
|
+
regionAndOrigin,
|
|
642
|
+
awsKeyAlias
|
|
643
|
+
}) => {
|
|
644
|
+
const encryptedSecrets = await loadEncryptedSecrets({
|
|
645
|
+
encryptedSecretsFile
|
|
646
|
+
});
|
|
647
|
+
const flattened = import_flat2.default.flatten(encryptedSecrets.encryptedParameters, {
|
|
648
|
+
delimiter: "__",
|
|
649
|
+
transformKey: (key) => {
|
|
650
|
+
return (0, import_constant_case.constantCase)(key);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
const kmsClient = new import_client_kms4.KMSClient({
|
|
654
|
+
credentials: credentialsAndOrigin.value,
|
|
655
|
+
region: regionAndOrigin.value
|
|
656
|
+
});
|
|
657
|
+
const encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, awsKeyAlias);
|
|
658
|
+
const filterKey = jsonFilter == null ? void 0 : jsonFilter.split(".").map((part) => (0, import_constant_case.constantCase)(part)).join("__");
|
|
659
|
+
const envEntries = await Promise.all(Object.entries(flattened).filter(([key]) => {
|
|
660
|
+
if (filterKey) {
|
|
661
|
+
return key.indexOf(filterKey) === 0;
|
|
662
|
+
}
|
|
663
|
+
return true;
|
|
664
|
+
}).map(async ([key, cipherText]) => {
|
|
665
|
+
const decryptCommand = new import_client_kms4.DecryptCommand({
|
|
666
|
+
KeyId: awsKeyAlias,
|
|
667
|
+
CiphertextBlob: Buffer.from(cipherText, "base64"),
|
|
668
|
+
EncryptionAlgorithm: encryptionAlgorithm
|
|
574
669
|
});
|
|
575
670
|
const decryptionResult = await kmsClient.send(decryptCommand);
|
|
576
671
|
if (!(decryptionResult == null ? void 0 : decryptionResult.Plaintext)) {
|
|
@@ -589,38 +684,60 @@ var handleSec = async ({
|
|
|
589
684
|
var handler4 = async (argv) => {
|
|
590
685
|
try {
|
|
591
686
|
let env;
|
|
687
|
+
let awsEnv;
|
|
592
688
|
try {
|
|
593
689
|
if (argv.envFile) {
|
|
594
690
|
env = (0, import_dotenv2.parse)(import_node_fs3.default.readFileSync(argv.envFile, { encoding: "utf8" }));
|
|
691
|
+
if (argv.awsAssumeRoleArn || process.env.AWS_ASSUME_ROLE_ARN || (env == null ? void 0 : env.AWS_ASSUME_ROLE_ARN)) {
|
|
692
|
+
const { credentialsAndOrigin, regionAndOrigin } = await handleCredentialsAndRegion({
|
|
693
|
+
argv: __spreadValues({}, argv),
|
|
694
|
+
env: __spreadValues(__spreadValues({}, process.env), env)
|
|
695
|
+
});
|
|
696
|
+
awsEnv = {
|
|
697
|
+
AWS_ACCESS_KEY_ID: credentialsAndOrigin.value.accessKeyId,
|
|
698
|
+
AWS_SECRET_ACCESS_KEY: credentialsAndOrigin.value.secretAccessKey
|
|
699
|
+
};
|
|
700
|
+
if (credentialsAndOrigin.value.sessionToken) {
|
|
701
|
+
awsEnv.AWS_SESSION_TOKEN = credentialsAndOrigin.value.sessionToken;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
const { credentialsAndOrigin, regionAndOrigin } = await handleCredentialsAndRegion({
|
|
706
|
+
argv: __spreadValues({}, argv),
|
|
707
|
+
env: __spreadValues(__spreadValues({}, process.env), env)
|
|
708
|
+
});
|
|
709
|
+
if ((argv.awsAssumeRoleArn || process.env.AWS_ASSUME_ROLE_ARN || (env == null ? void 0 : env.AWS_ASSUME_ROLE_ARN)) && credentialsAndOrigin.value.sessionToken !== void 0) {
|
|
710
|
+
awsEnv = {
|
|
711
|
+
AWS_ACCESS_KEY_ID: credentialsAndOrigin.value.accessKeyId,
|
|
712
|
+
AWS_SECRET_ACCESS_KEY: credentialsAndOrigin.value.secretAccessKey,
|
|
713
|
+
AWS_SESSION_TOKEN: credentialsAndOrigin.value.sessionToken
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
if (argv.verbose) {
|
|
717
|
+
console.log({ credentialsAndOrigin, regionAndOrigin });
|
|
718
|
+
}
|
|
719
|
+
if (argv.encryptedSecretsFile) {
|
|
720
|
+
env = await handleEncryptedJson({
|
|
721
|
+
encryptedSecretsFile: argv.encryptedSecretsFile,
|
|
722
|
+
jsonFilter: argv.jsonFilter,
|
|
723
|
+
credentialsAndOrigin,
|
|
724
|
+
regionAndOrigin,
|
|
725
|
+
awsKeyAlias: argv.awsKeyAlias
|
|
726
|
+
});
|
|
727
|
+
} else {
|
|
728
|
+
env = await handleSec({
|
|
729
|
+
secFile: argv.secFile,
|
|
730
|
+
credentialsAndOrigin,
|
|
731
|
+
regionAndOrigin,
|
|
732
|
+
awsKeyAlias: argv.awsKeyAlias
|
|
733
|
+
});
|
|
734
|
+
}
|
|
595
735
|
}
|
|
596
736
|
} catch (e) {
|
|
597
737
|
if (argv.ignoreMissingEnvFile !== true) {
|
|
598
738
|
throw e;
|
|
599
739
|
}
|
|
600
740
|
}
|
|
601
|
-
let awsEnv;
|
|
602
|
-
const { credentialsAndOrigin, regionAndOrigin } = await handleCredentialsAndRegion({
|
|
603
|
-
argv: __spreadValues({}, argv),
|
|
604
|
-
env: __spreadValues(__spreadValues({}, process.env), env)
|
|
605
|
-
});
|
|
606
|
-
if ((argv.awsAssumeRoleArn || process.env.AWS_ASSUME_ROLE_ARN || (env == null ? void 0 : env.AWS_ASSUME_ROLE_ARN)) && credentialsAndOrigin.value.sessionToken !== void 0) {
|
|
607
|
-
awsEnv = {
|
|
608
|
-
AWS_ACCESS_KEY_ID: credentialsAndOrigin.value.accessKeyId,
|
|
609
|
-
AWS_SECRET_ACCESS_KEY: credentialsAndOrigin.value.secretAccessKey,
|
|
610
|
-
AWS_SESSION_TOKEN: credentialsAndOrigin.value.sessionToken
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
if (argv.verbose) {
|
|
614
|
-
console.log({ credentialsAndOrigin, regionAndOrigin });
|
|
615
|
-
}
|
|
616
|
-
if (!argv.envFile && argv.secFile) {
|
|
617
|
-
env = await handleSec({
|
|
618
|
-
secFile: argv.secFile,
|
|
619
|
-
credentialsAndOrigin,
|
|
620
|
-
regionAndOrigin,
|
|
621
|
-
awsKeyAlias: argv.awsKeyAlias
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
741
|
const userCommandArgs = process.argv.slice(process.argv.indexOf(argv.command) + 1);
|
|
625
742
|
if (argv.command) {
|
|
626
743
|
(0, import_cross_spawn.spawn)(argv.command, [...userCommandArgs], {
|
|
@@ -642,18 +759,18 @@ __export(encryptEnvCommand_exports, {
|
|
|
642
759
|
desc: () => desc5,
|
|
643
760
|
handler: () => handler5
|
|
644
761
|
});
|
|
645
|
-
var import_client_kms5 = __toModule(require("@aws-sdk/client-kms"));
|
|
646
|
-
var import_chalk5 = __toModule(require("chalk"));
|
|
647
|
-
var import_dotenv3 = __toModule(require("dotenv"));
|
|
648
762
|
var import_node_fs4 = __toModule(require("node:fs"));
|
|
649
763
|
var import_node_path4 = __toModule(require("node:path"));
|
|
764
|
+
var import_client_kms5 = __toModule(require("@aws-sdk/client-kms"));
|
|
765
|
+
var import_chalk6 = __toModule(require("chalk"));
|
|
766
|
+
var import_dotenv3 = __toModule(require("dotenv"));
|
|
650
767
|
var command5 = "encrypt-env";
|
|
651
768
|
var desc5 = "Encrypts a dotenv file";
|
|
652
769
|
var builder5 = {
|
|
653
770
|
"aws-profile": commonCliOptions.awsProfile,
|
|
654
771
|
"aws-region": commonCliOptions.awsRegion,
|
|
655
772
|
"aws-key-alias": commonCliOptions.awsKeyAlias,
|
|
656
|
-
"env-file": commonCliOptions.envFile,
|
|
773
|
+
"env-file": __spreadProps(__spreadValues({}, commonCliOptions.envFile), { default: ".env" }),
|
|
657
774
|
"sec-file": commonCliOptions.secFile,
|
|
658
775
|
"assume-role-arn": commonCliOptions.awsAssumeRoleArn,
|
|
659
776
|
verbose: commonCliOptions.verbose
|
|
@@ -667,7 +784,7 @@ var handler5 = async (argv) => {
|
|
|
667
784
|
});
|
|
668
785
|
const envSource = import_node_path4.default.resolve(process.cwd(), argv.envFile);
|
|
669
786
|
if (!await fileExists(envSource)) {
|
|
670
|
-
error(`Could not open ${(0,
|
|
787
|
+
error(`Could not open ${(0, import_chalk6.redBright)(envSource)}`);
|
|
671
788
|
return;
|
|
672
789
|
}
|
|
673
790
|
const parsedEnv = (0, import_dotenv3.parse)(import_node_fs4.default.readFileSync(envSource, { encoding: "utf8" }));
|
|
@@ -678,6 +795,7 @@ var handler5 = async (argv) => {
|
|
|
678
795
|
},
|
|
679
796
|
verbose: argv.verbose
|
|
680
797
|
});
|
|
798
|
+
const encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, argv.awsKeyAlias);
|
|
681
799
|
if (argv.verbose) {
|
|
682
800
|
info(`Encrypting using key alias ${bold(argv.awsKeyAlias)} in ${bold(await kmsClient.config.region())}`);
|
|
683
801
|
const describeKeyCommand = new import_client_kms5.DescribeKeyCommand({
|
|
@@ -690,7 +808,7 @@ var handler5 = async (argv) => {
|
|
|
690
808
|
const encryptCommand = new import_client_kms5.EncryptCommand({
|
|
691
809
|
KeyId: argv.awsKeyAlias,
|
|
692
810
|
Plaintext: Buffer.from(value),
|
|
693
|
-
EncryptionAlgorithm:
|
|
811
|
+
EncryptionAlgorithm: encryptionAlgorithm
|
|
694
812
|
});
|
|
695
813
|
const encryptionResult = await kmsClient.send(encryptCommand);
|
|
696
814
|
if (!encryptionResult.CiphertextBlob) {
|
|
@@ -723,8 +841,8 @@ __export(encryptSecretsJson_exports, {
|
|
|
723
841
|
var import_node_fs5 = __toModule(require("node:fs"));
|
|
724
842
|
var import_node_path5 = __toModule(require("node:path"));
|
|
725
843
|
var import_client_kms6 = __toModule(require("@aws-sdk/client-kms"));
|
|
726
|
-
var
|
|
727
|
-
var
|
|
844
|
+
var import_chalk7 = __toModule(require("chalk"));
|
|
845
|
+
var import_flat3 = __toModule(require("flat"));
|
|
728
846
|
var command6 = "encrypt-secrets-json";
|
|
729
847
|
var desc6 = "Encrypts an unencrypted file";
|
|
730
848
|
var builder6 = {
|
|
@@ -754,14 +872,14 @@ var handler6 = async (argv) => {
|
|
|
754
872
|
});
|
|
755
873
|
const secretsPath = import_node_path5.default.resolve(process.cwd(), argv.secretsFile);
|
|
756
874
|
if (!await fileExists(secretsPath)) {
|
|
757
|
-
error(`Could not open ${(0,
|
|
875
|
+
error(`Could not open ${(0, import_chalk7.redBright)(secretsPath)}`);
|
|
758
876
|
return;
|
|
759
877
|
}
|
|
760
878
|
const secrets = JSON.parse(import_node_fs5.default.readFileSync(secretsPath, { encoding: "utf8" }));
|
|
761
879
|
if (!secrets.parameters) {
|
|
762
880
|
throw new Error(`Expected 'parameters' property, but got none`);
|
|
763
881
|
}
|
|
764
|
-
const flatParameters = (0,
|
|
882
|
+
const flatParameters = (0, import_flat3.default)(secrets.parameters, { delimiter: "/" });
|
|
765
883
|
if (argv.verbose) {
|
|
766
884
|
console.log(flatParameters);
|
|
767
885
|
}
|
|
@@ -780,11 +898,12 @@ var handler6 = async (argv) => {
|
|
|
780
898
|
const describeKeyResult = await kmsClient.send(describeKeyCommand);
|
|
781
899
|
console.log("describeKeyResult", { describeKeyResult });
|
|
782
900
|
}
|
|
901
|
+
const encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, argv.awsKeyAlias);
|
|
783
902
|
const encryptedFlatParameters = Object.fromEntries(await Promise.all(Object.entries(flatParameters).map(async ([parameterName, parameter]) => {
|
|
784
903
|
const encryptCommand = new import_client_kms6.EncryptCommand({
|
|
785
904
|
KeyId: argv.awsKeyAlias,
|
|
786
905
|
Plaintext: Buffer.from(parameter),
|
|
787
|
-
EncryptionAlgorithm:
|
|
906
|
+
EncryptionAlgorithm: encryptionAlgorithm
|
|
788
907
|
});
|
|
789
908
|
const encryptionResult = await kmsClient.send(encryptCommand);
|
|
790
909
|
if (!encryptionResult.CiphertextBlob) {
|
|
@@ -800,7 +919,7 @@ var handler6 = async (argv) => {
|
|
|
800
919
|
const cipherText = Buffer.from(encryptionResult.CiphertextBlob).toString("base64");
|
|
801
920
|
return [parameterName, cipherText];
|
|
802
921
|
})));
|
|
803
|
-
const encryptedParameters =
|
|
922
|
+
const encryptedParameters = import_flat3.default.unflatten(encryptedFlatParameters, { delimiter: "/" });
|
|
804
923
|
const encryptedSecrets = {
|
|
805
924
|
config: secrets.config,
|
|
806
925
|
encryptedParameters
|
|
@@ -826,12 +945,12 @@ __export(offloadToSSMCommand_exports, {
|
|
|
826
945
|
desc: () => desc7,
|
|
827
946
|
handler: () => handler7
|
|
828
947
|
});
|
|
829
|
-
var import_client_kms7 = __toModule(require("@aws-sdk/client-kms"));
|
|
830
|
-
var import_client_ssm3 = __toModule(require("@aws-sdk/client-ssm"));
|
|
831
|
-
var import_chalk7 = __toModule(require("chalk"));
|
|
832
|
-
var import_flat3 = __toModule(require("flat"));
|
|
833
948
|
var import_node_fs6 = __toModule(require("node:fs"));
|
|
834
949
|
var import_node_path6 = __toModule(require("node:path"));
|
|
950
|
+
var import_client_kms7 = __toModule(require("@aws-sdk/client-kms"));
|
|
951
|
+
var import_client_ssm3 = __toModule(require("@aws-sdk/client-ssm"));
|
|
952
|
+
var import_chalk8 = __toModule(require("chalk"));
|
|
953
|
+
var import_flat4 = __toModule(require("flat"));
|
|
835
954
|
var command7 = "offload-secrets-json-to-ssm";
|
|
836
955
|
var desc7 = "Sends decrypted values of secrets.encrypted.json file to SSM parameter store";
|
|
837
956
|
var builder7 = {
|
|
@@ -856,14 +975,14 @@ var handler7 = async (argv) => {
|
|
|
856
975
|
});
|
|
857
976
|
const encryptedSecretsPath = import_node_path6.default.resolve(process.cwd(), argv.encryptedSecretsFile);
|
|
858
977
|
if (!await fileExists(encryptedSecretsPath)) {
|
|
859
|
-
error(`Could not open ${(0,
|
|
978
|
+
error(`Could not open ${(0, import_chalk8.redBright)(encryptedSecretsPath)}`);
|
|
860
979
|
return;
|
|
861
980
|
}
|
|
862
981
|
const encryptedSecrets = JSON.parse(import_node_fs6.default.readFileSync(encryptedSecretsPath, { encoding: "utf8" }));
|
|
863
982
|
if (!encryptedSecrets.encryptedParameters) {
|
|
864
983
|
throw new Error(`Expected 'encryptedParameters' property, but got none`);
|
|
865
984
|
}
|
|
866
|
-
const flatEncryptedParameters = (0,
|
|
985
|
+
const flatEncryptedParameters = (0, import_flat4.default)(encryptedSecrets.encryptedParameters, { delimiter: "/" });
|
|
867
986
|
const kmsClient = getKMSClient({
|
|
868
987
|
configuration: {
|
|
869
988
|
credentials: credentialsAndOrigin.value,
|
|
@@ -873,17 +992,13 @@ var handler7 = async (argv) => {
|
|
|
873
992
|
});
|
|
874
993
|
if (argv.verbose) {
|
|
875
994
|
info(`Encrypting using key alias ${bold(argv.awsKeyAlias)} in ${bold(await kmsClient.config.region())}`);
|
|
876
|
-
const describeKeyCommand = new import_client_kms7.DescribeKeyCommand({
|
|
877
|
-
KeyId: argv.awsKeyAlias
|
|
878
|
-
});
|
|
879
|
-
const describeKeyResult = await kmsClient.send(describeKeyCommand);
|
|
880
|
-
console.log("describeKeyResult", { describeKeyResult });
|
|
881
995
|
}
|
|
996
|
+
const encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, argv.awsKeyAlias);
|
|
882
997
|
const flatParameters = Object.fromEntries(await Promise.all(Object.entries(flatEncryptedParameters).map(async ([parameterName, encryptedParameter]) => {
|
|
883
998
|
const decryptCommand = new import_client_kms7.DecryptCommand({
|
|
884
999
|
KeyId: argv.awsKeyAlias,
|
|
885
1000
|
CiphertextBlob: Buffer.from(encryptedParameter, "base64"),
|
|
886
|
-
EncryptionAlgorithm:
|
|
1001
|
+
EncryptionAlgorithm: encryptionAlgorithm
|
|
887
1002
|
});
|
|
888
1003
|
const decryptionResult = await kmsClient.send(decryptCommand);
|
|
889
1004
|
if (!decryptionResult.Plaintext) {
|