dotsec 4.0.0-alpha.15 → 4.0.0-alpha.17
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 +8 -0
- package/dist/cli/index.js +154 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +154 -21
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.0.0-alpha.16](https://github.com/jpwesselink/dotsec/compare/v4.0.0-alpha.15...v4.0.0-alpha.16) (2023-05-22)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package dotsec
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [4.0.0-alpha.14](https://github.com/jpwesselink/dotsec/compare/v4.0.0-alpha.13...v4.0.0-alpha.14) (2023-05-22)
|
|
7
15
|
|
|
8
16
|
|
package/dist/cli/index.js
CHANGED
|
@@ -7,9 +7,10 @@ var bundleRequire = require('bundle-require');
|
|
|
7
7
|
var JoyCon = require('joycon');
|
|
8
8
|
var fs2 = require('fs/promises');
|
|
9
9
|
var prompts = require('prompts');
|
|
10
|
-
var
|
|
10
|
+
var chalk2 = require('chalk');
|
|
11
11
|
require('cli-table');
|
|
12
12
|
var dotenvExpand = require('dotenv-expand');
|
|
13
|
+
var camelCase = require('camel-case');
|
|
13
14
|
var child_process = require('child_process');
|
|
14
15
|
var Ajv = require('ajv');
|
|
15
16
|
var yargsParser = require('yargs-parser');
|
|
@@ -21,7 +22,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
21
22
|
var JoyCon__default = /*#__PURE__*/_interopDefault(JoyCon);
|
|
22
23
|
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
23
24
|
var prompts__default = /*#__PURE__*/_interopDefault(prompts);
|
|
24
|
-
var
|
|
25
|
+
var chalk2__default = /*#__PURE__*/_interopDefault(chalk2);
|
|
25
26
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
26
27
|
var yargsParser__default = /*#__PURE__*/_interopDefault(yargsParser);
|
|
27
28
|
|
|
@@ -89,6 +90,10 @@ var getMagicalConfig = async (filename) => {
|
|
|
89
90
|
defaults: {
|
|
90
91
|
...data?.defaults,
|
|
91
92
|
...defaultConfig.defaults,
|
|
93
|
+
output: {
|
|
94
|
+
...data?.defaults?.output,
|
|
95
|
+
...defaultConfig.defaults?.output
|
|
96
|
+
},
|
|
92
97
|
plugins: {
|
|
93
98
|
...data?.defaults?.plugins,
|
|
94
99
|
...defaultConfig.defaults?.plugins
|
|
@@ -112,6 +117,10 @@ var getMagicalConfig = async (filename) => {
|
|
|
112
117
|
defaults: {
|
|
113
118
|
...data?.defaults,
|
|
114
119
|
...defaultConfig.defaults,
|
|
120
|
+
output: {
|
|
121
|
+
...data?.defaults?.output,
|
|
122
|
+
...defaultConfig.defaults?.output
|
|
123
|
+
},
|
|
115
124
|
plugins: {
|
|
116
125
|
...data?.defaults?.plugins,
|
|
117
126
|
...defaultConfig.defaults?.plugins
|
|
@@ -316,7 +325,29 @@ if (undefined) {
|
|
|
316
325
|
`);
|
|
317
326
|
});
|
|
318
327
|
}
|
|
319
|
-
var strong = (str) =>
|
|
328
|
+
var strong = (str) => chalk2__default.default.yellow.bold(str);
|
|
329
|
+
|
|
330
|
+
// src/types/colors.ts
|
|
331
|
+
var backgroundColors = [
|
|
332
|
+
"black",
|
|
333
|
+
"red",
|
|
334
|
+
"green",
|
|
335
|
+
"yellow",
|
|
336
|
+
"blue",
|
|
337
|
+
"magenta",
|
|
338
|
+
"cyan",
|
|
339
|
+
"white",
|
|
340
|
+
"black-bright",
|
|
341
|
+
"gray",
|
|
342
|
+
"grey",
|
|
343
|
+
"red-bright",
|
|
344
|
+
"green-bright",
|
|
345
|
+
"yellow-bright",
|
|
346
|
+
"blue-bright",
|
|
347
|
+
"magenta-bright",
|
|
348
|
+
"cyan-bright",
|
|
349
|
+
"white-bright"
|
|
350
|
+
];
|
|
320
351
|
|
|
321
352
|
// src/cli/options/sharedOptions.ts
|
|
322
353
|
var envFileOption = {
|
|
@@ -347,6 +378,28 @@ var usingNoEncryptionEngineOption = {
|
|
|
347
378
|
choices: ["env"],
|
|
348
379
|
env: "DOTSEC_USING"
|
|
349
380
|
};
|
|
381
|
+
var showRedactedOption = {
|
|
382
|
+
flags: "--show-redacted",
|
|
383
|
+
description: 'Wether to show redacted values."',
|
|
384
|
+
env: "DOTSEC_SHOW_REDACTED"
|
|
385
|
+
};
|
|
386
|
+
var showOutputPrefixOption = {
|
|
387
|
+
flags: "--show-output-prefix",
|
|
388
|
+
description: "Show output prefix",
|
|
389
|
+
env: "DOTSEC_SHOW_OUTPUT_PREFIX"
|
|
390
|
+
};
|
|
391
|
+
var showOutputBackgroundColorOption = {
|
|
392
|
+
flags: "--show-output-background-color",
|
|
393
|
+
description: "Show output background color",
|
|
394
|
+
env: "DOTSEC_SHOW_OUTPUT_BACKGROUND_COLOR"
|
|
395
|
+
};
|
|
396
|
+
var outputBackgroundColorOption = {
|
|
397
|
+
flags: "--output-background-color <outputBackgroundColor>",
|
|
398
|
+
description: "Background color of the output.",
|
|
399
|
+
env: "DOTSEC_OUTPUT_BACKGROUND_COLOR",
|
|
400
|
+
choices: backgroundColors,
|
|
401
|
+
defaultValue: "red-bright"
|
|
402
|
+
};
|
|
350
403
|
var yesOption = {
|
|
351
404
|
option: ["--yes", "Skip confirmation prompts"]
|
|
352
405
|
};
|
|
@@ -549,7 +602,11 @@ var runCommandDefaults = {
|
|
|
549
602
|
configFile: configFileOption,
|
|
550
603
|
envFile: envFileOption,
|
|
551
604
|
yes: yesOption,
|
|
552
|
-
engine: engineOption
|
|
605
|
+
engine: engineOption,
|
|
606
|
+
showRedacted: showRedactedOption,
|
|
607
|
+
outputBackgroundColor: outputBackgroundColorOption,
|
|
608
|
+
hideOutputBackgroundColor: showOutputBackgroundColorOption,
|
|
609
|
+
hideOutputPrefix: showOutputPrefixOption
|
|
553
610
|
},
|
|
554
611
|
requiredOptions: {
|
|
555
612
|
using: usingNoEncryptionEngineOption
|
|
@@ -582,7 +639,11 @@ $ DOTSEC_USING=env npx dotsec run node -e "console.log(process.env)"
|
|
|
582
639
|
configFile: configFileOption,
|
|
583
640
|
envFile: envFileOption,
|
|
584
641
|
secFile: secFileOption,
|
|
585
|
-
yes: yesOption
|
|
642
|
+
yes: yesOption,
|
|
643
|
+
showRedacted: showRedactedOption,
|
|
644
|
+
outputBackgroundColor: outputBackgroundColorOption,
|
|
645
|
+
hideOutputBackgroundColor: showOutputBackgroundColorOption,
|
|
646
|
+
hideOutputPrefix: showOutputPrefixOption
|
|
586
647
|
},
|
|
587
648
|
requiredOptions: {
|
|
588
649
|
using: usingOption
|
|
@@ -1109,7 +1170,16 @@ var addRunProgam = (program2, options) => {
|
|
|
1109
1170
|
const subProgram = program2.command("run <command...>").allowUnknownOption(true).enablePositionalOptions().passThroughOptions().showHelpAfterError(true).action(
|
|
1110
1171
|
async (commands, _options, command) => {
|
|
1111
1172
|
try {
|
|
1112
|
-
const {
|
|
1173
|
+
const {
|
|
1174
|
+
envFile,
|
|
1175
|
+
using,
|
|
1176
|
+
secFile,
|
|
1177
|
+
engine,
|
|
1178
|
+
showRedacted,
|
|
1179
|
+
outputBackgroundColor,
|
|
1180
|
+
showOutputBackgroundColor,
|
|
1181
|
+
showOutputPrefix
|
|
1182
|
+
} = command.optsWithGlobals();
|
|
1113
1183
|
let envContents;
|
|
1114
1184
|
if (using === "env" || hasDecryptEngine === false) {
|
|
1115
1185
|
if (!envFile) {
|
|
@@ -1138,11 +1208,17 @@ var addRunProgam = (program2, options) => {
|
|
|
1138
1208
|
return [key, _options[key]];
|
|
1139
1209
|
})
|
|
1140
1210
|
);
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1211
|
+
try {
|
|
1212
|
+
const dotSecContents = fs3__default.default.readFileSync(secFile, "utf8");
|
|
1213
|
+
envContents = await pluginCliDecrypt.handler({
|
|
1214
|
+
ciphertext: dotSecContents,
|
|
1215
|
+
...allOptionsValues
|
|
1216
|
+
});
|
|
1217
|
+
} catch (e) {
|
|
1218
|
+
console.error("Something bad happened while decrypting.");
|
|
1219
|
+
console.error(`File: ${secFile}`);
|
|
1220
|
+
throw e;
|
|
1221
|
+
}
|
|
1146
1222
|
}
|
|
1147
1223
|
if (envContents) {
|
|
1148
1224
|
const dotenvVars = parse(envContents).obj;
|
|
@@ -1156,18 +1232,75 @@ var addRunProgam = (program2, options) => {
|
|
|
1156
1232
|
}
|
|
1157
1233
|
});
|
|
1158
1234
|
const [userCommand, ...userCommandArgs] = commands;
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1235
|
+
const waiter = await new Promise((resolve) => {
|
|
1236
|
+
const cprocess = child_process.spawn(userCommand, [...userCommandArgs], {
|
|
1237
|
+
stdio: "pipe",
|
|
1238
|
+
shell: false,
|
|
1239
|
+
env: {
|
|
1240
|
+
...expandedEnvVars.parsed,
|
|
1241
|
+
...process.env,
|
|
1242
|
+
__DOTSEC_ENV__: JSON.stringify(Object.keys(dotenvVars))
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
const expandedEnvVarsWithoutEnv = dotenvExpand.expand({
|
|
1246
|
+
ignoreProcessEnv: true,
|
|
1247
|
+
parsed: {
|
|
1248
|
+
// add standard env variables
|
|
1249
|
+
// add custom env variables, either from .env or .sec, (or empty object if none)
|
|
1250
|
+
...dotenvVars
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
cprocess.stdout.setEncoding("utf8");
|
|
1254
|
+
let addBackgroundColor = showOutputBackgroundColor || dotsecConfig.defaults?.output?.showBackgroundColor ? chalk2__default.default.bgRedBright : (str) => str;
|
|
1255
|
+
if (outputBackgroundColor && (showOutputBackgroundColor || dotsecConfig.defaults?.output?.showBackgroundColor)) {
|
|
1256
|
+
if (!backgroundColors.includes(
|
|
1257
|
+
outputBackgroundColor
|
|
1258
|
+
)) {
|
|
1259
|
+
throw new Error(
|
|
1260
|
+
`Invalid background color: ${outputBackgroundColor}`
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
const backgroundColorFnName = camelCase.camelCase(
|
|
1264
|
+
`bg-${outputBackgroundColor}`
|
|
1265
|
+
);
|
|
1266
|
+
if (chalk2__default.default[backgroundColorFnName]) {
|
|
1267
|
+
addBackgroundColor = chalk2__default.default[backgroundColorFnName];
|
|
1268
|
+
} else {
|
|
1269
|
+
console.warn(
|
|
1270
|
+
`Invalid background color: ${backgroundColorFnName}, using default: red`
|
|
1271
|
+
);
|
|
1272
|
+
addBackgroundColor = chalk2__default.default.bgRedBright;
|
|
1273
|
+
}
|
|
1167
1274
|
}
|
|
1275
|
+
const prefix = showOutputPrefix || dotsecConfig?.defaults?.output?.showOutputPrefix ? "(dxotsec) " : "";
|
|
1276
|
+
cprocess.stdout.on("data", function(data) {
|
|
1277
|
+
const lines = addBackgroundColor(
|
|
1278
|
+
data.split(/\r?\n/).map((line) => `${prefix}${line}`).join("\n")
|
|
1279
|
+
);
|
|
1280
|
+
const redactedLines = showRedacted !== true ? Object.values(expandedEnvVarsWithoutEnv.parsed || {}).sort((a, b) => {
|
|
1281
|
+
if (a.length > b.length) {
|
|
1282
|
+
return -1;
|
|
1283
|
+
} else if (a.length < b.length) {
|
|
1284
|
+
return 1;
|
|
1285
|
+
} else {
|
|
1286
|
+
return 0;
|
|
1287
|
+
}
|
|
1288
|
+
}).reduce((acc, value) => {
|
|
1289
|
+
const redactedValue = value.replace(/./g, "*");
|
|
1290
|
+
return acc.replace(value, redactedValue);
|
|
1291
|
+
}, lines) : lines;
|
|
1292
|
+
console.log(redactedLines);
|
|
1293
|
+
});
|
|
1294
|
+
cprocess.stderr.setEncoding("utf8");
|
|
1295
|
+
cprocess.stderr.on("data", function(data) {
|
|
1296
|
+
process.stderr.write(data.toString());
|
|
1297
|
+
});
|
|
1298
|
+
cprocess.on("exit", (code) => {
|
|
1299
|
+
resolve(code);
|
|
1300
|
+
});
|
|
1168
1301
|
});
|
|
1169
|
-
if (
|
|
1170
|
-
process.exit(
|
|
1302
|
+
if (waiter !== 0) {
|
|
1303
|
+
process.exit(waiter || 1);
|
|
1171
1304
|
}
|
|
1172
1305
|
} else {
|
|
1173
1306
|
throw new Error("No .env or .sec file provided");
|