dotsec 4.0.0-alpha.15 → 4.0.0-alpha.19

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 CHANGED
@@ -3,6 +3,22 @@
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.18](https://github.com/jpwesselink/dotsec/compare/v4.0.0-alpha.17...v4.0.0-alpha.18) (2023-05-24)
7
+
8
+ **Note:** Version bump only for package dotsec
9
+
10
+
11
+
12
+
13
+
14
+ # [4.0.0-alpha.16](https://github.com/jpwesselink/dotsec/compare/v4.0.0-alpha.15...v4.0.0-alpha.16) (2023-05-22)
15
+
16
+ **Note:** Version bump only for package dotsec
17
+
18
+
19
+
20
+
21
+
6
22
  # [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
23
 
8
24
 
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 chalk = require('chalk');
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 chalk__default = /*#__PURE__*/_interopDefault(chalk);
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) => chalk__default.default.yellow.bold(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,33 @@ 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 outputPrefixOption = {
392
+ flags: "--output-prefix <outputPrefix>",
393
+ description: "Output prefix",
394
+ env: "DOTSEC_OUTPUT_PREFIX"
395
+ };
396
+ var showOutputBackgroundColorOption = {
397
+ flags: "--show-output-background-color",
398
+ description: "Show output background color",
399
+ env: "DOTSEC_SHOW_OUTPUT_BACKGROUND_COLOR"
400
+ };
401
+ var outputBackgroundColorOption = {
402
+ flags: "--output-background-color <outputBackgroundColor>",
403
+ description: "Background color of the output.",
404
+ env: "DOTSEC_OUTPUT_BACKGROUND_COLOR",
405
+ choices: backgroundColors,
406
+ defaultValue: "red-bright"
407
+ };
350
408
  var yesOption = {
351
409
  option: ["--yes", "Skip confirmation prompts"]
352
410
  };
@@ -549,7 +607,12 @@ var runCommandDefaults = {
549
607
  configFile: configFileOption,
550
608
  envFile: envFileOption,
551
609
  yes: yesOption,
552
- engine: engineOption
610
+ engine: engineOption,
611
+ showRedacted: showRedactedOption,
612
+ outputBackgroundColor: outputBackgroundColorOption,
613
+ showOutputBackgroundColor: showOutputBackgroundColorOption,
614
+ showOutputPrefix: showOutputPrefixOption,
615
+ outputPrefix: outputPrefixOption
553
616
  },
554
617
  requiredOptions: {
555
618
  using: usingNoEncryptionEngineOption
@@ -582,7 +645,12 @@ $ DOTSEC_USING=env npx dotsec run node -e "console.log(process.env)"
582
645
  configFile: configFileOption,
583
646
  envFile: envFileOption,
584
647
  secFile: secFileOption,
585
- yes: yesOption
648
+ yes: yesOption,
649
+ showRedacted: showRedactedOption,
650
+ outputBackgroundColor: outputBackgroundColorOption,
651
+ hideOutputBackgroundColor: showOutputBackgroundColorOption,
652
+ hideOutputPrefix: showOutputPrefixOption,
653
+ outputPrefix: outputPrefixOption
586
654
  },
587
655
  requiredOptions: {
588
656
  using: usingOption
@@ -1109,7 +1177,17 @@ var addRunProgam = (program2, options) => {
1109
1177
  const subProgram = program2.command("run <command...>").allowUnknownOption(true).enablePositionalOptions().passThroughOptions().showHelpAfterError(true).action(
1110
1178
  async (commands, _options, command) => {
1111
1179
  try {
1112
- const { envFile, using, secFile, engine } = command.optsWithGlobals();
1180
+ const {
1181
+ envFile,
1182
+ using,
1183
+ secFile,
1184
+ engine,
1185
+ showRedacted,
1186
+ outputBackgroundColor,
1187
+ showOutputBackgroundColor,
1188
+ showOutputPrefix,
1189
+ outputPrefix
1190
+ } = command.optsWithGlobals();
1113
1191
  let envContents;
1114
1192
  if (using === "env" || hasDecryptEngine === false) {
1115
1193
  if (!envFile) {
@@ -1138,11 +1216,17 @@ var addRunProgam = (program2, options) => {
1138
1216
  return [key, _options[key]];
1139
1217
  })
1140
1218
  );
1141
- const dotSecContents = fs3__default.default.readFileSync(secFile, "utf8");
1142
- envContents = await pluginCliDecrypt.handler({
1143
- ciphertext: dotSecContents,
1144
- ...allOptionsValues
1145
- });
1219
+ try {
1220
+ const dotSecContents = fs3__default.default.readFileSync(secFile, "utf8");
1221
+ envContents = await pluginCliDecrypt.handler({
1222
+ ciphertext: dotSecContents,
1223
+ ...allOptionsValues
1224
+ });
1225
+ } catch (e) {
1226
+ console.error("Something bad happened while decrypting.");
1227
+ console.error(`File: ${secFile}`);
1228
+ throw e;
1229
+ }
1146
1230
  }
1147
1231
  if (envContents) {
1148
1232
  const dotenvVars = parse(envContents).obj;
@@ -1156,18 +1240,81 @@ var addRunProgam = (program2, options) => {
1156
1240
  }
1157
1241
  });
1158
1242
  const [userCommand, ...userCommandArgs] = commands;
1159
- const spawn = child_process.spawnSync(userCommand, [...userCommandArgs], {
1160
- stdio: "inherit",
1161
- shell: false,
1162
- encoding: "utf-8",
1163
- env: {
1164
- ...expandedEnvVars.parsed,
1165
- ...process.env,
1166
- __DOTSEC_ENV__: JSON.stringify(Object.keys(dotenvVars))
1243
+ const waiter = await new Promise((resolve) => {
1244
+ const cprocess = child_process.spawn(userCommand, [...userCommandArgs], {
1245
+ stdio: "pipe",
1246
+ shell: false,
1247
+ env: {
1248
+ ...expandedEnvVars.parsed,
1249
+ ...process.env,
1250
+ __DOTSEC_ENV__: JSON.stringify(Object.keys(dotenvVars))
1251
+ }
1252
+ });
1253
+ const expandedEnvVarsWithoutEnv = dotenvExpand.expand({
1254
+ ignoreProcessEnv: true,
1255
+ parsed: {
1256
+ // add standard env variables
1257
+ // add custom env variables, either from .env or .sec, (or empty object if none)
1258
+ ...dotenvVars
1259
+ }
1260
+ });
1261
+ cprocess.stdout.setEncoding("utf8");
1262
+ let addBackgroundColor = showOutputBackgroundColor || dotsecConfig.defaults?.options?.showBackgroundColor ? chalk2__default.default.bgRedBright : (str) => str;
1263
+ if (outputBackgroundColor && (showOutputBackgroundColor || dotsecConfig.defaults?.options?.showBackgroundColor)) {
1264
+ if (!backgroundColors.includes(
1265
+ outputBackgroundColor
1266
+ )) {
1267
+ throw new Error(
1268
+ `Invalid background color: ${outputBackgroundColor}`
1269
+ );
1270
+ }
1271
+ const backgroundColorFnName = camelCase.camelCase(
1272
+ `bg-${outputBackgroundColor}`
1273
+ );
1274
+ if (chalk2__default.default[backgroundColorFnName]) {
1275
+ addBackgroundColor = chalk2__default.default[backgroundColorFnName];
1276
+ } else {
1277
+ console.warn(
1278
+ `Invalid background color: ${backgroundColorFnName}, using default: red`
1279
+ );
1280
+ addBackgroundColor = chalk2__default.default.bgRedBright;
1281
+ }
1167
1282
  }
1283
+ const prefix = showOutputPrefix || dotsecConfig?.defaults?.options?.showOutputPrefix ? `${outputPrefix || "(dotsec) "}` : "";
1284
+ cprocess.stdout.on("data", function(data) {
1285
+ const lines = addBackgroundColor(
1286
+ data.split(/\r?\n/).map((line) => `${prefix}${line}`).join("\n")
1287
+ );
1288
+ const redactedLines = (showRedacted || dotsecConfig?.defaults?.options?.showRedacted) !== true ? Object.entries(expandedEnvVarsWithoutEnv.parsed || {}).sort(([, a], [, b]) => {
1289
+ if (a.length > b.length) {
1290
+ return -1;
1291
+ } else if (a.length < b.length) {
1292
+ return 1;
1293
+ } else {
1294
+ return 0;
1295
+ }
1296
+ }).reduce((acc, [key, value]) => {
1297
+ console.log("KEY", key);
1298
+ if (dotsecConfig?.redaction?.ignore?.includes(key)) {
1299
+ console.log("IGNORING", key);
1300
+ return acc;
1301
+ } else {
1302
+ const redactedValue = value.replace(/./g, "*");
1303
+ return acc.replace(value, redactedValue);
1304
+ }
1305
+ }, lines) : lines;
1306
+ console.log(redactedLines);
1307
+ });
1308
+ cprocess.stderr.setEncoding("utf8");
1309
+ cprocess.stderr.on("data", function(data) {
1310
+ process.stderr.write(data.toString());
1311
+ });
1312
+ cprocess.on("exit", (code) => {
1313
+ resolve(code);
1314
+ });
1168
1315
  });
1169
- if (spawn.status !== 0) {
1170
- process.exit(spawn.status || 1);
1316
+ if (waiter !== 0) {
1317
+ process.exit(waiter || 1);
1171
1318
  }
1172
1319
  } else {
1173
1320
  throw new Error("No .env or .sec file provided");