dotsec 1.0.0-alpha.2 → 1.0.0-alpha.20

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.
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/cli.ts", "../../src/commonCliOptions.ts", "../../src/commands/convert.ts", "../../src/commands/defaultCommand.ts", "../../src/lib/config-old/index.ts", "../../src/lib/json.ts", "../../src/lib/config-old/constants.ts", "../../src/lib/encryptedSecrets.ts", "../../src/utils/io.ts", "../../src/utils/getCredentialsProfileRegion.ts", "../../src/utils/logger.ts", "../../src/lib/partial-commands/handleCredentialsAndRegion.ts", "../../src/utils/kms.ts", "../../src/commands/dot-sec-to-dot-env.ts", "../../src/lib/wtf/crypto.ts", "../../src/utils/secretsManager.ts", "../../src/utils/ssm.ts", "../../src/lib/wtf/types.ts", "../../src/lib/wtf/flat.ts", "../../src/lib/wtf/io.ts", "../../src/lib/wtf/json.ts", "../../src/lib/wtf/yaml.ts", "../../src/commands/encrypted-secrets-to-dot-env.ts", "../../src/lib/wtf/dotenv.ts", "../../src/commands/encrypted-secrets-to-dot-sec.ts", "../../src/lib/wtf/dotsec.ts", "../../src/commands/encrypted-secrets-to-plaintext-secrets.ts", "../../src/commands/offload-plaintext-secrets.ts", "../../src/commands/plaintext-secrets-to-dot-env.ts", "../../src/commands/plaintext-secrets-to-dot-sec.ts", "../../src/commands/plaintext-secrets-to-encrypted-secrets.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-shadow */\nimport { hideBin } from 'yargs/helpers';\nimport yargs from 'yargs/yargs';\n\n// import * as createAwsKey from './commands/createAwsKey';\n// import * as awsDecrypt from './commands/aws-decrypt';\n// import * as awsEncrypt from './commands/aws-encrypt';\n// import * as awsPush from './commands/aws-push';\n// import * as debugCommand from './commands/debugCommand';\n// import * as decryptSecCommand from './commands/decryptSecCommand';\n// import * as decryptSecretsJson from './commands/decryptSecretsJson';\nimport convertCommand from './commands/convert';\nimport * as defaultCommmand from './commands/defaultCommand';\n// import * as deleteAwsKey from './commands/deleteAwsKey';\nimport * as dotSecToDotEnv from './commands/dot-sec-to-dot-env';\nimport * as encryptedSecretsToDotEnv from './commands/encrypted-secrets-to-dot-env';\nimport * as encryptedSecretsToDotSec from './commands/encrypted-secrets-to-dot-sec';\nimport * as encryptedSecretsToPlaintextSecrets from './commands/encrypted-secrets-to-plaintext-secrets';\n// import * as encryptEnvCommand from './commands/encryptEnvCommand';\n// import * as encryptSecretsJson from './commands/encryptSecretsJson';\n// import * as offloadToSSMCommand from './commands/offloadToSSMCommand';\nimport * as offloadPlaintextSecrets from './commands/offload-plaintext-secrets';\nimport * as plaintextSecretsToDotEnv from './commands/plaintext-secrets-to-dot-env';\nimport * as plaintextSecretsToDotSec from './commands/plaintext-secrets-to-dot-sec';\nimport * as plaintextSecretsToEncryptedSecrets from './commands/plaintext-secrets-to-encrypted-secrets';\n\nvoid yargs(hideBin(process.argv))\n .command(convertCommand)\n .command(defaultCommmand)\n .command(plaintextSecretsToEncryptedSecrets)\n .command(encryptedSecretsToPlaintextSecrets)\n .command(encryptedSecretsToDotEnv)\n .command(encryptedSecretsToDotSec)\n .command(plaintextSecretsToDotEnv)\n .command(plaintextSecretsToDotSec)\n .command(dotSecToDotEnv)\n .command(offloadPlaintextSecrets)\n\n // .command(awsEncrypt)\n // .command(awsDecrypt)\n // .command(awsPush)\n // .command(offloadToSSMCommand)\n // .command(debugCommand)\n // .command(encryptEnvCommand)\n // .command(decryptSecCommand)\n // .command(encryptSecretsJson)\n // .command(decryptSecretsJson)\n // .command(createAwsKey)\n // .command(deleteAwsKey)\n .parse();\n", "// import regions from 'aws-regions/regions.json';\n\nexport const commonCliOptions = {\n awsProfile: {\n string: true,\n describe: 'AWS profile',\n },\n awsRegion: {\n string: true,\n describe: 'AWS region',\n },\n awsKeyAlias: {\n string: true,\n describe: 'AWS KMS key alias',\n },\n awsKeyArn: {\n string: true,\n describe: 'AWS KMS key id',\n },\n awsKey: {\n string: true,\n describe: 'AWS KMS key arn',\n },\n envFile: {\n string: true,\n describe: '.env file',\n },\n ignoreMissingEnvFile: {\n boolean: true,\n describe: `Don't halt on missing .env file`,\n },\n secFile: {\n string: true,\n describe: '.sec file',\n default: '.sec',\n },\n awsAssumeRoleArn: {\n string: true,\n describe:\n 'arn or role to assume. Can also be set using the AWS_ASSUME_ROLE_ARN environment variable, or, when using --env-file in the target env file. The cli option overrides the environment variable.',\n },\n awsAssumeRoleSessionDuration: {\n number: true,\n describe:\n 'Duration of assume role sessions. Defaults to 3600 seconds. Can also be set using the AWS_ASSUME_ROLE_SESSION_DURATION environment variable, or, when using --env-file in the target env file. The cli option overrides the environment variable.',\n },\n useTopLevelsAsEnvironments: {\n boolean: true,\n describe: 'Use top level keys as environments',\n },\n verbose: {\n boolean: true,\n describe: 'Be verbose',\n },\n encryptedSecretsFile: {\n string: true,\n describe: 'filename of json file for reading encrypted secrets',\n },\n jsonFilter: {\n string: true,\n describe:\n 'dot separated filter path, for example a.b.c will return { a: { b: { c: ... }}}',\n },\n searchpath: {\n string: true,\n describe: 'search path in which to look for secrets tree',\n },\n // regions: {\n // describe: 'AWS region',\n // array: true,\n // choices: regions.map(({ code }) => code),\n // },\n // baseRegion: {\n // describe: 'AWS region where to store encyption secrets. This is also the same region where *you* should deploy the Top Secret! stack.',\n // choices: regions.map(({ code }) => code),\n // },\n yes: {\n boolean: true,\n describe: 'Proceeds without confirmation',\n },\n dryRun: {\n boolean: true,\n describe: 'Do a dry run',\n },\n} as const;\n", "import { CommandModule } from 'yargs';\n\nimport { commonCliOptions } from '../commonCliOptions';\n\n// export const command = 'convert';\n// export const desc = `Converts between .env, .sec, secrets.json and secrets.encrypted.json.\n// If '--use-top-levels-as-environments' is set, it will create a .env file for each top level key in the encrypted secrets file.`;\n\nconst convertModule: CommandModule<\n { 'env-file': { type: string } },\n { envFile: { type: string } }\n> = {\n command: 'convert',\n describe: 'does stuff',\n builder: {\n 'env-file': commonCliOptions.envFile,\n 'search-path': commonCliOptions.searchpath,\n 'aws-profile': commonCliOptions.awsProfile,\n 'aws-region': commonCliOptions.awsRegion,\n 'aws-key-alias': commonCliOptions.awsKeyAlias,\n 'aws-assume-role-arn': commonCliOptions.awsAssumeRoleArn,\n 'aws-assume-role-session-duration':\n commonCliOptions.awsAssumeRoleSessionDuration,\n 'use-top-levels-as-environments':\n commonCliOptions.useTopLevelsAsEnvironments,\n verbose: commonCliOptions.verbose,\n yes: { ...commonCliOptions.yes },\n },\n handler: (a) => {\n console.log(a.d);\n console.log(a['env-file']);\n },\n};\n\nexport default convertModule;\n\n// export const builder = {\n// 'env-file': commonCliOptions.envFile,\n// 'search-path': commonCliOptions.searchpath,\n// 'aws-profile': commonCliOptions.awsProfile,\n// 'aws-region': commonCliOptions.awsRegion,\n// 'aws-key-alias': commonCliOptions.awsKeyAlias,\n// 'aws-assume-role-arn': commonCliOptions.awsAssumeRoleArn,\n// 'aws-assume-role-session-duration':\n// commonCliOptions.awsAssumeRoleSessionDuration,\n// 'use-top-levels-as-environments':\n// commonCliOptions.useTopLevelsAsEnvironments,\n// verbose: commonCliOptions.verbose,\n// yes: { ...commonCliOptions.yes },\n// } as const;\n\n// export const handler = async (\n// argv: YargsHandlerParams<typeof builder>,\n// ): Promise<void> => {\n// const config = await getConfig();\n\n// const { info, error } = getLogger();\n// try {\n// const defaultRegion = config.aws.region || argv.awsRegion;\n// const { credentialsAndOrigin, regionAndOrigin } =\n// await handleCredentialsAndRegion({\n// argv: {\n// ...argv,\n// awsRegion: defaultRegion,\n// awsProfile: config.aws.profile || argv.awsProfile,\n// awsAssumeRoleArn:\n// config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n// awsAssumeRoleSessionDuration:\n// config.aws.assumeRoleSessionDuration ||\n// argv.awsAssumeRoleSessionDuration,\n// },\n// env: { ...process.env },\n// });\n\n// const { fileType, dotSecEncrypted } = await getDotSecEncrypted({\n// defaultConfig: {\n// config: {\n// aws: {\n// keyAlias: 'alias/dotsec',\n// regions: [regionAndOrigin.value],\n// },\n// },\n// },\n// options: {\n// verbose: argv.verbose,\n// },\n// });\n// if (!dotSecEncrypted.encrypted) {\n// throw new Error(`Expected 'encrypted' property, but got none`);\n// }\n// // const dotSecEncryptedFlattened = flattenEncrypted(dotSecEncrypted);\n// // const expanded = expandEncrypted(dotSecEncryptedFlattened);\n\n// const dotSecPlainText = await decryptedEncrypted({\n// dotSecEncrypted,\n// credentials: credentialsAndOrigin.value,\n// region: regionAndOrigin.value,\n// keyAlias: argv.awsKeyAlias,\n// verbose: argv.verbose,\n// });\n\n// if (\n// argv.useTopLevelsAsEnvironments ||\n// dotSecEncrypted.config?.useTopLevelsAsEnvironments\n// ) {\n// const dotEnvsPerEnvironment = toDotEnvPerEnvironment({\n// dotSecPlainText,\n// verbose: argv.verbose,\n// });\n\n// for (const [environment, dotEnv] of Object.entries(\n// dotEnvsPerEnvironment,\n// )) {\n// const fileName = `.env.${environment}`;\n// const dotEnvPath = path.resolve(process.cwd(), fileName);\n\n// info(`target: ${strong(dotEnvPath)}\\n`);\n// info(prettyCode(dotEnv));\n// info(`\\n`);\n// const overwriteResponse = await promptOverwriteIfFileExists({\n// filePath: dotEnvPath,\n// skip: argv.yes,\n// });\n\n// if (\n// overwriteResponse === undefined ||\n// overwriteResponse.overwrite === true\n// ) {\n// fs.writeFileSync(dotEnvPath, dotEnv);\n// }\n\n// // write to file, prompt if file exists\n// }\n// } else {\n// const dotEnv = toDotEnv({\n// dotSecPlainText,\n// verbose: argv.verbose,\n// searchPath: argv.searchPath,\n// });\n\n// const fileName = argv.envFile || `.env`;\n// const dotEnvPath = path.resolve(process.cwd(), fileName);\n// info(`target: ${strong(dotEnvPath)}\\n`);\n// info(prettyCode(dotEnv));\n// info(`\\n`);\n\n// const overwriteResponse = await promptOverwriteIfFileExists({\n// filePath: dotEnvPath,\n// skip: argv.yes,\n// });\n\n// if (\n// overwriteResponse === undefined ||\n// overwriteResponse.overwrite === true\n// ) {\n// fs.writeFileSync(dotEnvPath, dotEnv);\n// }\n// }\n// } catch (e) {\n// error(e);\n// }\n// };\n", "import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { KMSClient, DecryptCommand } from \"@aws-sdk/client-kms\";\nimport { redBright } from \"chalk\";\nimport { constantCase } from \"constant-case\";\nimport { spawn } from \"cross-spawn\";\nimport { parse } from \"dotenv\";\nimport flat from \"flat\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { loadEncryptedSecrets } from \"../lib/encryptedSecrets\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport {\n\tCredentialsAndOrigin,\n\tRegionAndOrigin,\n\tYargsHandlerParams,\n} from \"../types\";\nimport { fileExists } from \"../utils/io\";\nimport { getEncryptionAlgorithm } from \"../utils/kms\";\n\nexport const command = \"$0 <command>\";\nexport const desc =\n\t\"Decrypts a .sec file, injects the results into a separate process and runs a command\";\n\nexport const builder = {\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"sec-file\": commonCliOptions.secFile,\n\t\"env-file\": commonCliOptions.envFile,\n\t\"ignore-missing-env-file\": commonCliOptions.ignoreMissingEnvFile,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\t\"encrypted-secrets-file\": commonCliOptions.encryptedSecretsFile,\n\t\"json-filter\": commonCliOptions.jsonFilter,\n\n\tverbose: commonCliOptions.verbose,\n\t// yes: { ...commonCliOptions.yes },\n\tcommand: { string: true, required: true },\n} as const;\n\nconst handleSec = async ({\n\tsecFile,\n\tcredentialsAndOrigin,\n\tregionAndOrigin,\n\tawsKeyAlias,\n}: {\n\tsecFile: string;\n\tcredentialsAndOrigin: CredentialsAndOrigin;\n\tregionAndOrigin: RegionAndOrigin;\n\tawsKeyAlias: string;\n}) => {\n\tconst secSource = path.resolve(process.cwd(), secFile);\n\tif (!(await fileExists(secSource))) {\n\t\tconsole.error(`Could not open ${redBright(secSource)}`);\n\t\treturn;\n\t}\n\tconst parsedSec = parse(fs.readFileSync(secSource, { encoding: \"utf8\" }));\n\n\tconst kmsClient = new KMSClient({\n\t\tcredentials: credentialsAndOrigin.value,\n\t\tregion: regionAndOrigin.value,\n\t});\n\n\tconst encryptionAlgorithm = await getEncryptionAlgorithm(\n\t\tkmsClient,\n\t\tawsKeyAlias,\n\t);\n\n\tconst envEntries: [string, string][] = await Promise.all(\n\t\tObject.entries(parsedSec).map(async ([key, cipherText]) => {\n\t\t\tconst decryptCommand = new DecryptCommand({\n\t\t\t\tKeyId: awsKeyAlias,\n\t\t\t\tCiphertextBlob: Buffer.from(cipherText, \"base64\"),\n\t\t\t\tEncryptionAlgorithm: encryptionAlgorithm,\n\t\t\t});\n\t\t\tconst decryptionResult = await kmsClient.send(decryptCommand);\n\n\t\t\tif (!decryptionResult?.Plaintext) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No: ${JSON.stringify({\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tcipherText,\n\t\t\t\t\t\tdecryptCommand,\n\t\t\t\t\t})}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst value = Buffer.from(decryptionResult.Plaintext).toString();\n\t\t\treturn [key, value];\n\t\t}),\n\t);\n\tconst env = Object.fromEntries(envEntries);\n\n\treturn env;\n};\nconst handleEncryptedJson = async ({\n\tencryptedSecretsFile,\n\tjsonFilter,\n\tcredentialsAndOrigin,\n\tregionAndOrigin,\n\tawsKeyAlias,\n}: {\n\tencryptedSecretsFile: string;\n\tjsonFilter?: string;\n\tcredentialsAndOrigin: CredentialsAndOrigin;\n\tregionAndOrigin: RegionAndOrigin;\n\tawsKeyAlias: string;\n}) => {\n\tconst encryptedSecrets = await loadEncryptedSecrets({\n\t\tencryptedSecretsFile: encryptedSecretsFile,\n\t});\n\n\tconst flattened: Record<string, string> = flat.flatten(\n\t\tencryptedSecrets.encryptedParameters,\n\t\t{\n\t\t\tdelimiter: \"__\",\n\t\t\ttransformKey: (key) => {\n\t\t\t\treturn constantCase(key);\n\t\t\t},\n\t\t},\n\t);\n\n\tconst kmsClient = new KMSClient({\n\t\tcredentials: credentialsAndOrigin.value,\n\t\tregion: regionAndOrigin.value,\n\t});\n\n\tconst encryptionAlgorithm = await getEncryptionAlgorithm(\n\t\tkmsClient,\n\t\tawsKeyAlias,\n\t);\n\n\tconst filterKey = jsonFilter\n\t\t?.split(\".\")\n\t\t.map((part) => constantCase(part))\n\t\t.join(\"__\");\n\tconst envEntries: [string, string][] = await Promise.all(\n\t\tObject.entries(flattened)\n\t\t\t.filter(([key]) => {\n\t\t\t\tif (filterKey) {\n\t\t\t\t\treturn key.indexOf(filterKey) === 0;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t})\n\t\t\t.map(async ([key, cipherText]) => {\n\t\t\t\tconst decryptCommand = new DecryptCommand({\n\t\t\t\t\tKeyId: awsKeyAlias,\n\t\t\t\t\tCiphertextBlob: Buffer.from(cipherText, \"base64\"),\n\t\t\t\t\tEncryptionAlgorithm: encryptionAlgorithm,\n\t\t\t\t});\n\t\t\t\tconst decryptionResult = await kmsClient.send(decryptCommand);\n\n\t\t\t\tif (!decryptionResult?.Plaintext) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`No: ${JSON.stringify({\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcipherText,\n\t\t\t\t\t\t\tdecryptCommand,\n\t\t\t\t\t\t})}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst value = Buffer.from(decryptionResult.Plaintext).toString();\n\t\t\t\treturn [key, value];\n\t\t\t}),\n\t);\n\tconst env = Object.fromEntries(envEntries);\n\n\treturn env;\n};\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\n\ttry {\n\t\tlet env: Record<string, string> | undefined;\n\t\tlet awsEnv: Record<string, string> | undefined;\n\n\t\ttry {\n\t\t\tif (argv.envFile) {\n\t\t\t\tenv = parse(fs.readFileSync(argv.envFile, { encoding: \"utf8\" }));\n\n\t\t\t\tif (\n\t\t\t\t\targv.awsAssumeRoleArn ||\n\t\t\t\t\tprocess.env.AWS_ASSUME_ROLE_ARN ||\n\t\t\t\t\tenv?.AWS_ASSUME_ROLE_ARN\n\t\t\t\t) {\n\t\t\t\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\t\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\t\t\t\targv: {\n\t\t\t\t\t\t\t\t...argv,\n\t\t\t\t\t\t\t\tawsRegion: config.aws.region || argv.awsRegion,\n\t\t\t\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\t\t\t\tawsAssumeRoleArn:\n\t\t\t\t\t\t\t\t\tconfig.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tenv: { ...process.env },\n\t\t\t\t\t\t});\n\n\t\t\t\t\tawsEnv = {\n\t\t\t\t\t\tAWS_ACCESS_KEY_ID: credentialsAndOrigin.value.accessKeyId,\n\t\t\t\t\t\tAWS_SECRET_ACCESS_KEY: credentialsAndOrigin.value.secretAccessKey,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (credentialsAndOrigin.value.sessionToken) {\n\t\t\t\t\t\tawsEnv.AWS_SESSION_TOKEN = credentialsAndOrigin.value.sessionToken;\n\t\t\t\t\t}\n\t\t\t\t\t// this means we have\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\t\t\targv: {\n\t\t\t\t\t\t\t...argv,\n\t\t\t\t\t\t\tawsRegion: config.aws.region || argv.awsRegion,\n\t\t\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\t\t\tawsAssumeRoleArn:\n\t\t\t\t\t\t\t\tconfig.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tenv: { ...process.env },\n\t\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\t(argv.awsAssumeRoleArn ||\n\t\t\t\t\t\tprocess.env.AWS_ASSUME_ROLE_ARN ||\n\t\t\t\t\t\tenv?.AWS_ASSUME_ROLE_ARN) &&\n\t\t\t\t\tcredentialsAndOrigin.value.sessionToken !== undefined\n\t\t\t\t) {\n\t\t\t\t\tawsEnv = {\n\t\t\t\t\t\tAWS_ACCESS_KEY_ID: credentialsAndOrigin.value.accessKeyId,\n\t\t\t\t\t\tAWS_SECRET_ACCESS_KEY: credentialsAndOrigin.value.secretAccessKey,\n\t\t\t\t\t\tAWS_SESSION_TOKEN: credentialsAndOrigin.value.sessionToken,\n\t\t\t\t\t};\n\t\t\t\t\t// this means we have\n\t\t\t\t}\n\t\t\t\tif (argv.verbose) {\n\t\t\t\t\tconsole.log({ credentialsAndOrigin, regionAndOrigin });\n\t\t\t\t}\n\t\t\t\tconst awsKeyAlias = argv.awsKeyAlias || config.aws.keyAlias;\n\n\t\t\t\tif (argv.encryptedSecretsFile) {\n\t\t\t\t\tenv = await handleEncryptedJson({\n\t\t\t\t\t\tencryptedSecretsFile: argv.encryptedSecretsFile,\n\t\t\t\t\t\tjsonFilter: argv.jsonFilter,\n\t\t\t\t\t\tcredentialsAndOrigin,\n\t\t\t\t\t\tregionAndOrigin,\n\t\t\t\t\t\tawsKeyAlias,\n\t\t\t\t\t});\n\t\t\t\t\t// // load that file\n\t\t\t\t\t// const encryptedSecrets = await loadEncryptedSecrets({\n\t\t\t\t\t// encryptedSecretsFile: argv.encryptedSecretsFile,\n\t\t\t\t\t// });\n\n\t\t\t\t\t// const flattened = flat.flatten(encryptedSecrets, {\n\t\t\t\t\t// delimiter: '__',\n\t\t\t\t\t// transformKey: (key) => {\n\t\t\t\t\t// return constantCase(key);\n\t\t\t\t\t// },\n\t\t\t\t\t// });\n\n\t\t\t\t\t// console.log('flattened', flattened);\n\n\t\t\t\t\t// const unflattend = flat.unflatten(flattened, {\n\t\t\t\t\t// delimiter: '__',\n\t\t\t\t\t// transformKey: (key) => {\n\t\t\t\t\t// return camelCase(key);\n\t\t\t\t\t// },\n\t\t\t\t\t// });\n\n\t\t\t\t\t// console.log(JSON.stringify(unflattend, null, 4));\n\t\t\t\t} else {\n\t\t\t\t\tenv = await handleSec({\n\t\t\t\t\t\tsecFile: argv.secFile,\n\t\t\t\t\t\tcredentialsAndOrigin,\n\t\t\t\t\t\tregionAndOrigin,\n\t\t\t\t\t\tawsKeyAlias,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (argv.ignoreMissingEnvFile !== true) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\t//\n\t\tconst userCommandArgs = process.argv.slice(\n\t\t\tprocess.argv.indexOf(argv.command) + 1,\n\t\t);\n\n\t\tif (argv.command) {\n\t\t\tspawn(argv.command, [...userCommandArgs], {\n\t\t\t\tstdio: \"inherit\",\n\t\t\t\tshell: false,\n\t\t\t\tenv: { ...process.env, ...awsEnv, ...env },\n\t\t\t});\n\t\t}\n\t} catch (e) {\n\t\tconsole.error(e);\n\t}\n};\n", "import path from 'node:path';\n\nimport { bundleRequire } from 'bundle-require';\nimport JoyCon from 'joycon';\n\nimport { loadJson } from '../json';\nimport { defaultConfig } from './constants';\nimport { DotsecConfig, PartialConfig } from './types';\nexport { DotsecConfig, PartialConfig } from './types';\n\nexport const getConfig = async (): Promise<DotsecConfig> => {\n const cwd = process.cwd();\n const configJoycon = new JoyCon();\n const configPath = await configJoycon.resolve({\n files: [\n 'dotsec.config.ts',\n 'dotsec.config.js',\n 'dotsec.config.cjs',\n 'dotsec.config.mjs',\n 'dotsec.config.json',\n 'package.json',\n ],\n cwd,\n stopDir: path.parse(cwd).root,\n packageKey: 'dotsec',\n });\n\n if (configPath) {\n if (configPath.endsWith('.json')) {\n const rawData = (await loadJson(configPath)) as PartialConfig;\n\n let data: Partial<DotsecConfig>;\n\n if (\n configPath.endsWith('package.json') &&\n (rawData as { dotsec: Partial<DotsecConfig> }).dotsec !==\n undefined\n ) {\n data = (rawData as { dotsec: Partial<DotsecConfig> }).dotsec;\n } else {\n data = rawData as Partial<DotsecConfig>;\n }\n\n return {\n ...defaultConfig,\n ...data,\n aws: { ...defaultConfig.aws, ...data.aws },\n };\n }\n\n const config = await bundleRequire({\n filepath: configPath,\n });\n\n const retrievedConfig =\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n (config.mod.dotsec as Partial<DotsecConfig>) ||\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n (config.mod.default as Partial<DotsecConfig>) ||\n config.mod;\n return {\n ...defaultConfig,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ...retrievedConfig,\n };\n }\n\n return { ...defaultConfig };\n};\n", "import fs from 'fs';\nimport path from 'node:path';\n\nexport function jsoncParse(data: string) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-implied-eval\n return new Function('return ' + data.trim())();\n } catch {\n // Silently ignore any error\n // That's what tsc/jsonc-parser did after all\n return {};\n }\n}\n\nexport const loadJson = async (filepath: string) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return jsoncParse(await fs.promises.readFile(filepath, 'utf8'));\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Failed to parse ${path.relative(process.cwd(), filepath)}: ${\n error.message\n }`,\n );\n } else {\n throw error;\n }\n }\n};\n", "import { DotsecConfig } from './types';\n\nexport const defaultConfig: DotsecConfig = {\n aws: {\n keyAlias: 'alias/top-secret',\n },\n} as const;\n", "import fs from 'fs';\nimport path from 'path';\n\nimport { redBright } from 'chalk';\n\nimport { EncryptedSecrets } from '../types';\nimport { fileExists } from '../utils/io';\n\nexport const loadEncryptedSecrets = async ({\n encryptedSecretsFile,\n}: {\n encryptedSecretsFile: string;\n}) => {\n const encryptedSecretsPath = path.resolve(\n process.cwd(),\n encryptedSecretsFile,\n );\n if (!(await fileExists(encryptedSecretsPath))) {\n throw new Error(`Could not open ${redBright(encryptedSecretsPath)}`);\n }\n const encryptedSecrets = JSON.parse(\n fs.readFileSync(encryptedSecretsPath, { encoding: 'utf8' }),\n ) as EncryptedSecrets;\n if (!encryptedSecrets) {\n throw new Error(\n `No encrypted secrets found in ${redBright(encryptedSecretsPath)}`,\n );\n }\n if (!encryptedSecrets.encryptedParameters) {\n throw new Error(\n `Expected 'encryptedParameters' property, but got none`,\n );\n }\n\n return encryptedSecrets;\n};\n", "import { stat } from \"fs/promises\";\n\nimport prompts from \"prompts\";\nimport path from \"node:path\";\n\nexport const fileExists = async (source: string): Promise<boolean> => {\n\ttry {\n\t\tawait stat(source);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const promptOverwriteIfFileExists = async ({\n\tfilePath,\n\tskip,\n}: {\n\tfilePath: string;\n\tskip?: boolean;\n}) => {\n\tlet overwriteResponse: prompts.Answers<\"overwrite\"> | undefined;\n\n\tif ((await fileExists(filePath)) && skip !== true) {\n\t\toverwriteResponse = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"overwrite\",\n\t\t\tmessage: () => {\n\t\t\t\treturn `Overwrite './${path.relative(process.cwd(), filePath)}' ?`;\n\t\t\t},\n\t\t});\n\t} else {\n\t\toverwriteResponse = undefined;\n\t}\n\treturn overwriteResponse;\n};\n", "import {\n fromEnv,\n fromIni,\n fromTemporaryCredentials,\n} from '@aws-sdk/credential-providers';\nimport { loadSharedConfigFiles } from '@aws-sdk/shared-ini-file-loader';\n\nimport {\n CredentialsAndOrigin,\n ProfileAndOrigin,\n RegionAndOrigin,\n} from '../types';\nimport { emphasis, strong } from './logger';\n\nexport const getCredentialsProfileRegion = async ({\n argv,\n env,\n}: {\n argv: {\n profile?: string;\n region?: string;\n assumeRoleArn?: string;\n assumeRoleSessionDuration?: number;\n };\n env: {\n AWS_PROFILE?: string;\n AWS_ACCESS_KEY_ID?: string;\n AWS_SECRET_ACCESS_KEY?: string;\n AWS_REGION?: string;\n AWS_DEFAULT_REGION?: string;\n AWS_ASSUME_ROLE_ARN?: string | undefined;\n AWS_ASSUME_ROLE_SESSION_DURATION?: string | undefined;\n TZ?: string;\n };\n}) => {\n const sharedConfigFiles = await loadSharedConfigFiles();\n let credentialsAndOrigin: CredentialsAndOrigin | undefined = undefined;\n let profileAndOrigin: ProfileAndOrigin | undefined = undefined;\n let regionAndOrigin: RegionAndOrigin | undefined = undefined;\n if (argv.profile) {\n profileAndOrigin = {\n value: argv.profile,\n origin: `command line option: ${emphasis(argv.profile)}`,\n };\n credentialsAndOrigin = {\n value: await fromIni({\n profile: argv.profile,\n })(),\n origin: `${emphasis(`[${argv.profile}]`)} in credentials file`,\n };\n } else if (env.AWS_PROFILE) {\n profileAndOrigin = {\n value: env.AWS_PROFILE,\n origin: `env variable ${emphasis('AWS_PROFILE')}: ${strong(\n env.AWS_PROFILE,\n )}`,\n };\n credentialsAndOrigin = {\n value: await fromIni({\n profile: env.AWS_PROFILE,\n })(),\n origin: `env variable ${emphasis('AWS_PROFILE')}: ${strong(\n env.AWS_PROFILE,\n )}`,\n };\n } else if (env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY) {\n credentialsAndOrigin = {\n value: await fromEnv()(),\n origin: `env variables ${emphasis(\n 'AWS_ACCESS_KEY_ID',\n )} and ${emphasis('AWS_SECRET_ACCESS_KEY')}`,\n };\n } else if (sharedConfigFiles.credentialsFile?.default) {\n profileAndOrigin = {\n value: 'default',\n origin: `${emphasis('[default]')} in credentials file`,\n };\n credentialsAndOrigin = {\n value: await fromIni({\n profile: 'default',\n })(),\n origin: `profile ${emphasis('[default]')}`,\n };\n }\n\n if (argv.region) {\n regionAndOrigin = {\n value: argv.region,\n origin: `command line option: ${emphasis(argv.region)}`,\n };\n } else if (env.AWS_REGION) {\n regionAndOrigin = {\n value: env.AWS_REGION,\n origin: `env variable ${emphasis('AWS_REGION')}: ${strong(\n env.AWS_REGION,\n )}`,\n };\n } else if (env.AWS_DEFAULT_REGION) {\n regionAndOrigin = {\n value: env.AWS_DEFAULT_REGION,\n origin: `env variable ${emphasis('AWS_DEFAULT_REGION')}: ${strong(\n env.AWS_DEFAULT_REGION,\n )}`,\n };\n } else if (profileAndOrigin) {\n const foundRegion =\n sharedConfigFiles?.configFile?.[profileAndOrigin.value]?.region;\n\n if (foundRegion) {\n regionAndOrigin = {\n value: foundRegion,\n origin: `${emphasis(\n `[profile ${profileAndOrigin.value}]`,\n )} in config file`,\n };\n }\n }\n\n const assumedRole = argv.assumeRoleArn || env.AWS_ASSUME_ROLE_ARN;\n if (assumedRole) {\n const origin = argv.assumeRoleArn\n ? 'command line option'\n : 'env variable';\n credentialsAndOrigin = {\n value: await fromTemporaryCredentials({\n masterCredentials: credentialsAndOrigin?.value,\n\n params: {\n DurationSeconds:\n argv.assumeRoleSessionDuration ||\n Number(env.AWS_ASSUME_ROLE_SESSION_DURATION) ||\n 3600,\n RoleArn: assumedRole,\n },\n\n clientConfig: {\n region: regionAndOrigin?.value,\n },\n })(),\n origin: `${origin} ${emphasis(`[${assumedRole}]`)}`,\n };\n }\n\n return { credentialsAndOrigin, regionAndOrigin, profileAndOrigin };\n};\n\nexport const printVerboseCredentialsProfileRegion = ({\n credentialsAndOrigin,\n regionAndOrigin,\n profileAndOrigin,\n}: {\n credentialsAndOrigin?: CredentialsAndOrigin;\n regionAndOrigin?: RegionAndOrigin;\n profileAndOrigin?: ProfileAndOrigin;\n}): string => {\n const out: string[] = [];\n if (profileAndOrigin) {\n out.push(`Got profile name from ${profileAndOrigin.origin}`);\n }\n if (credentialsAndOrigin) {\n out.push(`Resolved credentials from ${credentialsAndOrigin.origin}`);\n }\n if (regionAndOrigin) {\n out.push(`Resolved region from ${regionAndOrigin.origin}`);\n }\n return out.join('\\n');\n};\n", "import chalk from 'chalk';\nimport { highlight, Theme, plain } from 'cli-highlight';\n// eslint-disable-next-line @typescript-eslint/naming-convention\nlet _logger: Pick<Console, 'info' | 'error' | 'table'>;\nexport const getLogger = () => {\n if (!_logger) {\n _logger = console;\n }\n\n return _logger;\n};\nexport const writeLine = (str: string) => {\n process.stdout.write(str);\n};\nexport const emphasis = (str: string): string => chalk.yellowBright(str);\nexport const strong = (str: string): string => chalk.yellow.bold(str);\n\nconst myTheme: Theme = {\n attr: chalk.yellow.bold,\n string: chalk.yellowBright.dim,\n params: chalk.red,\n deletion: chalk.red.strikethrough,\n number: plain,\n};\n\nexport const prettyCode = (str: string): string => {\n return highlight(str, { theme: myTheme });\n};\nexport const clientLogger = {\n debug(content: object) {\n console.log(content);\n },\n info(content: object) {\n console.log(content);\n },\n warn(content: object) {\n console.log(content);\n },\n error(content: object) {\n console.error(content);\n },\n};\n", "import {\n getCredentialsProfileRegion,\n printVerboseCredentialsProfileRegion,\n} from '../../utils/getCredentialsProfileRegion';\n\nexport const handleCredentialsAndRegion = async ({\n argv,\n env,\n}: {\n argv: {\n awsRegion?: string;\n awsProfile?: string;\n verbose?: boolean;\n awsAssumeRoleArn?: string;\n awsAssumeRoleSessionDuration?: number;\n };\n env: {\n AWS_PROFILE?: string | undefined;\n AWS_ACCESS_KEY_ID?: string | undefined;\n AWS_SECRET_ACCESS_KEY?: string | undefined;\n AWS_REGION?: string | undefined;\n AWS_DEFAULT_REGION?: string | undefined;\n AWS_ASSUME_ROLE_ARN?: string | undefined;\n AWS_ASSUME_ROLE_SESSION_DURATION?: string | undefined;\n TZ?: string;\n };\n}) => {\n const { credentialsAndOrigin, regionAndOrigin, profileAndOrigin } =\n await getCredentialsProfileRegion({\n argv: {\n region: argv.awsRegion,\n profile: argv.awsProfile,\n assumeRoleArn: argv.awsAssumeRoleArn,\n assumeRoleSessionDuration: argv.awsAssumeRoleSessionDuration,\n },\n env: {\n ...env,\n },\n });\n\n if (argv.verbose === true) {\n console.log(\n printVerboseCredentialsProfileRegion({\n credentialsAndOrigin,\n regionAndOrigin,\n profileAndOrigin,\n }),\n );\n }\n\n if (!credentialsAndOrigin || !regionAndOrigin) {\n if (!credentialsAndOrigin) {\n console.error('Could not find credentials');\n throw new Error('Could not find credentials');\n }\n if (!regionAndOrigin) {\n console.error('Could not find region');\n throw new Error('Could not find region');\n }\n }\n\n return { credentialsAndOrigin, regionAndOrigin };\n};\n", "import {\n DescribeKeyCommand,\n KMSClient,\n KMSClientConfig,\n} from '@aws-sdk/client-kms';\n\nexport const getKMSClient = ({\n configuration,\n}: {\n verbose?: boolean;\n configuration: KMSClientConfig;\n}) => {\n const kmsClient = new KMSClient(configuration);\n\n return kmsClient;\n};\n\nexport const getEncryptionAlgorithm = async (\n kmsClient: KMSClient,\n awsKeyAlias: string,\n) => {\n // describe key *once*\n const describeKeyCommand = new DescribeKeyCommand({\n KeyId: awsKeyAlias,\n });\n\n const describeKeyResult = await kmsClient.send(describeKeyCommand);\n const encryptionAlgorithm =\n describeKeyResult.KeyMetadata?.EncryptionAlgorithms?.[0];\n\n if (encryptionAlgorithm === undefined) {\n throw new Error(`Could not determine encryption algorithm`);\n }\n\n return encryptionAlgorithm;\n};\n", "import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport * as dotenv from \"dotenv\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport { decryptRawDotSecValues } from \"../lib/wtf/crypto\";\nimport { loadFile } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { promptOverwriteIfFileExists } from \"../utils/io\";\nimport { getLogger } from \"../utils/logger\";\nexport const command = \"dot-sec-to-dot-env\";\nexport const desc = `Creates .env file from a .sec file.`;\n\nexport const builder = {\n\t\"sec-file\": commonCliOptions.secFile,\n\t\"env-file\": commonCliOptions.envFile,\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\t\"use-top-levels-as-environments\": commonCliOptions.useTopLevelsAsEnvironments,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\n\tconst { error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\targv: {\n\t\t\t\t\t...argv,\n\t\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t},\n\t\t\t\tenv: { ...process.env },\n\t\t\t});\n\n\t\t// load .env file\n\t\tconst dotSecFilename = argv.secFile || \".sec\";\n\t\tconst dotSecPath = path.resolve(process.cwd(), dotSecFilename);\n\t\tconst dotSecString = await loadFile(dotSecPath);\n\t\tconst dotSecKeysValues = dotenv.parse(dotSecString);\n\t\tconst dotEnvString = await decryptRawDotSecValues({\n\t\t\tdotSecKeysValues,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias || \"alias/dotsec\",\n\t\t\tverbose: argv.verbose,\n\t\t});\n\n\t\tconst dotEnvFilename = argv.envFile || `.env`;\n\t\tconst dotEnvPath = path.resolve(process.cwd(), dotEnvFilename);\n\n\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\tfilePath: dotEnvPath,\n\t\t\tskip: argv.yes,\n\t\t});\n\n\t\tif (\n\t\t\toverwriteResponse === undefined ||\n\t\t\toverwriteResponse.overwrite === true\n\t\t) {\n\t\t\tfs.writeFileSync(dotEnvPath, dotEnvString);\n\t\t}\n\n\t\t// const { fileType, dotSecPlainText } = await getDotSecPlainText({\n\t\t// defaultConfig: {\n\t\t// config: {\n\t\t// aws: {\n\t\t// keyAlias: 'alias/dotsec',\n\t\t// regions: [regionAndOrigin.value],\n\t\t// },\n\t\t// },\n\t\t// },\n\t\t// options: {\n\t\t// verbose: argv.verbose,\n\t\t// },\n\t\t// });\n\t\t// if (!dotSecPlainText.plaintext) {\n\t\t// throw new Error(`Expected 'encrypted' property, but got none`);\n\t\t// }\n\n\t\t// if (\n\t\t// argv.useTopLevelsAsEnvironments ||\n\t\t// dotSecPlainText.config?.useTopLevelsAsEnvironments\n\t\t// ) {\n\t\t// const dotEnvsPerEnvironment = toDotEnvPerEnvironment({\n\t\t// dotSecPlainText,\n\t\t// verbose: argv.verbose,\n\t\t// });\n\n\t\t// for (const [environment, dotEnv] of Object.entries(\n\t\t// dotEnvsPerEnvironment,\n\t\t// )) {\n\t\t// const fileName = `.env.${environment}`;\n\t\t// const dotEnvPath = path.resolve(process.cwd(), fileName);\n\n\t\t// const overwriteResponse = await promptOverwriteIfFileExists({\n\t\t// filePath: dotEnvPath,\n\t\t// skip: argv.yes,\n\t\t// });\n\n\t\t// if (\n\t\t// overwriteResponse === undefined ||\n\t\t// overwriteResponse.overwrite === true\n\t\t// ) {\n\t\t// fs.writeFileSync(dotEnvPath, dotEnv);\n\t\t// }\n\n\t\t// // write to file, prompt if file exists\n\t\t// }\n\t\t// } else {\n\t\t// const dotEnv = toDotEnv({\n\t\t// dotSecPlainText,\n\t\t// verbose: argv.verbose,\n\t\t// });\n\n\t\t// const fileName = `.env`;\n\t\t// const dotEnvPath = path.resolve(process.cwd(), fileName);\n\n\t\t// const overwriteResponse = await promptOverwriteIfFileExists({\n\t\t// filePath: dotEnvPath,\n\t\t// skip: argv.yes,\n\t\t// });\n\n\t\t// if (\n\t\t// overwriteResponse === undefined ||\n\t\t// overwriteResponse.overwrite === true\n\t\t// ) {\n\t\t// fs.writeFileSync(dotEnvPath, dotEnv);\n\t\t// }\n\t\t// }\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n", "import {\n\tDecryptCommand,\n\tDescribeKeyCommand,\n\tEncryptCommand,\n} from \"@aws-sdk/client-kms\";\nimport {\n\tCreateSecretCommand,\n\tListSecretsCommand,\n\tPutSecretValueCommand,\n} from \"@aws-sdk/client-secrets-manager\";\nimport {\n\tParameterTier,\n\tParameterType,\n\tPutParameterCommand,\n} from \"@aws-sdk/client-ssm\";\nimport { Credentials } from \"@aws-sdk/types\";\nimport { constantCase } from \"constant-case\";\n\nimport { getEncryptionAlgorithm, getKMSClient } from \"../../utils/kms\";\nimport { emphasis, getLogger, strong } from \"../../utils/logger\";\nimport { getSecretsManagerClient } from \"../../utils/secretsManager\";\nimport { getSSMClient } from \"../../utils/ssm\";\nimport {\n\texpandEncrypted,\n\texpandPlainText,\n\tflattenEncrypted,\n\tflattenPlainText,\n} from \"./flat\";\nimport {\n\tDotSecEncrypted,\n\tDotSecEncryptedFlattened,\n\tDotSecPlainText,\n\tDotSecPlainTextFlattened,\n\tDotSecValue,\n\tisBoolean,\n\tisNumber,\n\tisRegularParameter,\n\tisRegularParameterObject,\n\tisSecretsManagerParameter,\n\tisSSMParameter,\n\tisString,\n} from \"./types\";\n\nconst maybeJson = (value: string): string | JSON => {\n\ttry {\n\t\treturn JSON.parse(value) as JSON;\n\t} catch (e) {\n\t\treturn value;\n\t}\n};\nexport const decryptedEncrypted = async (options: {\n\tdotSecEncrypted: DotSecEncrypted;\n\tcredentials: Credentials;\n\tregion: string;\n\tverbose?: boolean;\n\tkeyAlias?: string;\n}): Promise<DotSecPlainText> => {\n\tconst { dotSecEncrypted, credentials, region, verbose, keyAlias } = options;\n\tconst dotSecEncryptedFlattened = flattenEncrypted(dotSecEncrypted);\n\t// get logger\n\tconst { info, table } = getLogger();\n\t// create KMS client\n\tconst kmsClient = getKMSClient({\n\t\tconfiguration: {\n\t\t\tcredentials,\n\t\t\tregion,\n\t\t},\n\t\tverbose,\n\t});\n\n\tconst awsKeyAlias = keyAlias || dotSecEncrypted.config?.aws?.keyAlias;\n\tif (!awsKeyAlias) {\n\t\tthrow new Error(\"No key alias specified\");\n\t}\n\tif (verbose) {\n\t\tinfo(\n\t\t\t`Encrypting using key alias ${emphasis(awsKeyAlias)} in ${emphasis(\n\t\t\t\tawait kmsClient.config.region(),\n\t\t\t)}`,\n\t\t);\n\n\t\t// describe key *once*\n\n\t\tconst describeKeyCommand = new DescribeKeyCommand({\n\t\t\tKeyId: awsKeyAlias,\n\t\t});\n\n\t\tconst describeKeyResult = await kmsClient.send(describeKeyCommand);\n\n\t\tinfo(\"keyMetaData\", { ...describeKeyResult.KeyMetadata });\n\t}\n\n\tconst encryptionAlgorithm = await getEncryptionAlgorithm(\n\t\tkmsClient,\n\t\tawsKeyAlias,\n\t);\n\n\tconst dotSecFlattened: DotSecPlainTextFlattened = {\n\t\tconfig: { ...dotSecEncrypted.config },\n\t\tplaintext: {},\n\t};\n\tfor (const [key, encryptedValue] of Object.entries(\n\t\tdotSecEncryptedFlattened.encrypted,\n\t)) {\n\t\tconst decryptCommand = new DecryptCommand({\n\t\t\tKeyId: awsKeyAlias,\n\t\t\tCiphertextBlob: Buffer.from(encryptedValue.encryptedValue, \"base64\"),\n\t\t\tEncryptionAlgorithm: encryptionAlgorithm,\n\t\t});\n\n\t\tconst decryptionResult = await kmsClient.send(decryptCommand);\n\n\t\tif (!decryptionResult.Plaintext) {\n\t\t\tthrow new Error(\n\t\t\t\t`Something bad happened: ${JSON.stringify({\n\t\t\t\t\tkey,\n\t\t\t\t\tcipherText: encryptedValue,\n\t\t\t\t\tdecryptCommand: decryptCommand,\n\t\t\t\t})}`,\n\t\t\t);\n\t\t}\n\n\t\tif (verbose) {\n\t\t\tinfo(`Decrypting key ${emphasis(key)} ${strong(\"ok\")}`);\n\t\t}\n\n\t\tconst decryptedValue = Buffer.from(decryptionResult.Plaintext).toString();\n\t\tconst decryptedKeyValue = JSON.parse(decryptedValue) as {\n\t\t\tkey: string;\n\t\t\tvalue: string;\n\t\t};\n\t\t/**\n\t\t * We don't really know for sure if this is JSON or not, so we'll try to parse it\n\t\t * Since we do not accept JSON at top level, we have a nice foot gun here.\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t// @ts-ignore\n\t\tdotSecFlattened.plaintext[key] = maybeJson(decryptedKeyValue.value);\n\t}\n\treturn expandPlainText(dotSecFlattened);\n};\n\nexport const encryptPlainText = async (options: {\n\tdotSecPlainText: DotSecPlainText;\n\tcredentials: Credentials;\n\tregion: string;\n\tverbose?: boolean;\n\tkeyAlias?: string;\n}): Promise<DotSecEncrypted> => {\n\tconst { dotSecPlainText, credentials, region, verbose, keyAlias } = options;\n\tconst dotSecFlattened = flattenPlainText(dotSecPlainText);\n\tconst { info } = getLogger();\n\t// create KMS client\n\tconst kmsClient = getKMSClient({\n\t\tconfiguration: {\n\t\t\tcredentials,\n\t\t\tregion,\n\t\t},\n\t\tverbose,\n\t});\n\n\tconst awsKeyAlias = keyAlias || dotSecFlattened.config?.aws?.keyAlias;\n\tif (!awsKeyAlias) {\n\t\tthrow new Error(\"No key alias specified\");\n\t}\n\tif (verbose) {\n\t\tinfo(\n\t\t\t`Encrypting using key alias ${emphasis(awsKeyAlias)} in ${emphasis(\n\t\t\t\tawait kmsClient.config.region(),\n\t\t\t)}`,\n\t\t);\n\n\t\t// describe key *once*\n\n\t\tconst describeKeyCommand = new DescribeKeyCommand({\n\t\t\tKeyId: awsKeyAlias,\n\t\t});\n\n\t\tconst describeKeyResult = await kmsClient.send(describeKeyCommand);\n\n\t\tinfo(\"keyMetaData\", { ...describeKeyResult.KeyMetadata });\n\t}\n\n\tconst encryptionAlgorithm = await getEncryptionAlgorithm(\n\t\tkmsClient,\n\t\tawsKeyAlias,\n\t);\n\n\tconst encryptedDotSecFlattened: DotSecEncryptedFlattened = {\n\t\tconfig: { ...dotSecFlattened.config },\n\t\tencrypted: {},\n\t};\n\tfor (const [key, plainTextValue] of Object.entries(\n\t\tdotSecFlattened.plaintext,\n\t)) {\n\t\tlet plainTextValueCopy = plainTextValue;\n\t\t// check if parameter is string, number or boolean, if not, encode to json\n\t\tif (\n\t\t\ttypeof plainTextValueCopy !== \"string\" &&\n\t\t\ttypeof plainTextValueCopy !== \"number\" &&\n\t\t\ttypeof plainTextValueCopy !== \"boolean\"\n\t\t) {\n\t\t\tplainTextValueCopy = JSON.stringify(plainTextValue);\n\t\t}\n\n\t\tconst damn = JSON.stringify({ key, value: plainTextValueCopy });\n\t\tconst encryptCommand = new EncryptCommand({\n\t\t\tKeyId: awsKeyAlias,\n\t\t\tPlaintext: Buffer.from(String(damn)),\n\t\t\tEncryptionAlgorithm: encryptionAlgorithm,\n\t\t});\n\n\t\tconst encryptionResult = await kmsClient.send(encryptCommand);\n\n\t\tif (!encryptionResult.CiphertextBlob) {\n\t\t\tthrow new Error(\n\t\t\t\t`Something bad happened: ${JSON.stringify({\n\t\t\t\t\tkey,\n\t\t\t\t\tvalue: plainTextValue,\n\t\t\t\t\tencryptCommand,\n\t\t\t\t})}`,\n\t\t\t);\n\t\t}\n\n\t\tif (verbose) {\n\t\t\tinfo(`Encrypting key ${emphasis(key)} ${strong(\"ok\")}`);\n\t\t}\n\n\t\tconst cipherText = Buffer.from(encryptionResult.CiphertextBlob).toString(\n\t\t\t\"base64\",\n\t\t);\n\n\t\tif (isRegularParameter(plainTextValue)) {\n\t\t\tencryptedDotSecFlattened.encrypted[key] = {\n\t\t\t\ttype: \"standard\",\n\t\t\t\tencryptedValue: cipherText,\n\t\t\t};\n\t\t\t// do something ssm\n\t\t} else if (isSSMParameter(plainTextValue)) {\n\t\t\tencryptedDotSecFlattened.encrypted[key] = {\n\t\t\t\ttype: \"ssm\",\n\t\t\t\tencryptedValue: cipherText,\n\t\t\t};\n\t\t\t// do something ssm\n\t\t} else if (isSecretsManagerParameter(plainTextValue)) {\n\t\t\tencryptedDotSecFlattened.encrypted[key] = {\n\t\t\t\ttype: \"secretsManager\",\n\t\t\t\tencryptedValue: cipherText,\n\t\t\t};\n\t\t}\n\t}\n\treturn expandEncrypted(encryptedDotSecFlattened);\n};\n\ntype SyncTasks = {\n\ttotal: number;\n\tputParameterCommands: PutParameterCommand[];\n\tcreateSecretCommands: CreateSecretCommand[];\n\tputSecretValueCommands: PutSecretValueCommand[];\n};\nexport const createStorePlaintextTasks = async (options: {\n\tdotSecPlainText: DotSecPlainText;\n\tcredentials: Credentials;\n\tregion: string;\n\tverbose?: boolean;\n\tkeyAlias?: string;\n}): Promise<SyncTasks> => {\n\tconst { dotSecPlainText, credentials, region, verbose, keyAlias } = options;\n\tconst dotSecPlainTextFlattened = flattenPlainText(dotSecPlainText);\n\t// get logger\n\tconst { info } = getLogger();\n\t// create KMS client\n\t// create ssm client\n\tconst ssmClient = getSSMClient({\n\t\tconfiguration: {\n\t\t\tcredentials,\n\t\t\tregion,\n\t\t},\n\t\tverbose,\n\t});\n\n\tconst secretsManagerClient = getSecretsManagerClient({\n\t\tconfiguration: {\n\t\t\tcredentials,\n\t\t\tregion,\n\t\t},\n\t\tverbose,\n\t});\n\n\t// Array<[secretName: string, arn: string]>\n\tconst secretNameArnTuples = (\n\t\tawait secretsManagerClient.send(new ListSecretsCommand({}))\n\t)?.SecretList?.map((secret) => [secret.Name, secret.ARN]).filter(\n\t\t([name, ARN]) => name && ARN,\n\t) as [string, string][];\n\n\t// { [secretName: string] : arn }\n\tconst existingSecrets = secretNameArnTuples\n\t\t? Object.fromEntries(secretNameArnTuples)\n\t\t: {};\n\n\tconst awsKeyAlias = keyAlias || dotSecPlainText.config?.aws?.keyAlias;\n\tif (!awsKeyAlias) {\n\t\tthrow new Error(`No key alias specified`);\n\t}\n\tif (verbose) {\n\t\tinfo(`Encrypting to SSM and/or SecretsManager in ${emphasis(region)}`);\n\t}\n\n\tconst putParameterCommands: PutParameterCommand[] = [];\n\tconst createSecretCommands: CreateSecretCommand[] = [];\n\tconst putSecretValueCommands: PutSecretValueCommand[] = [];\n\n\tfor (const [keyPath, plainTextValue] of Object.entries(\n\t\tdotSecPlainTextFlattened.plaintext,\n\t)) {\n\t\tlet storageValue: DotSecValue;\n\t\tif (isRegularParameter(plainTextValue)) {\n\t\t\tif (isRegularParameterObject(plainTextValue)) {\n\t\t\t\tstorageValue = plainTextValue.value;\n\t\t\t} else {\n\t\t\t\tstorageValue = plainTextValue;\n\t\t\t}\n\t\t} else if (isSSMParameter(plainTextValue)) {\n\t\t\t// if (isSSMParameterObject(plainTextValue)) {\n\t\t\tstorageValue = plainTextValue.value;\n\t\t\t// } else {\n\t\t\t// storageValue = plainTextValue;\n\t\t\t// }\n\t\t} else if (isSecretsManagerParameter(plainTextValue)) {\n\t\t\tstorageValue = plainTextValue.value;\n\t\t} else {\n\t\t\tthrow new Error(\"Invalid parameter type\");\n\t\t}\n\t\t// check if parameter is string, number or boolean, if not, encode to json\n\t\tif (\n\t\t\t!isString(storageValue) &&\n\t\t\t!isNumber(storageValue) &&\n\t\t\t!isBoolean(storageValue)\n\t\t) {\n\t\t\tstorageValue = JSON.stringify(storageValue);\n\t\t}\n\t\tif (\n\t\t\tisSSMParameter(plainTextValue) ||\n\t\t\t(isRegularParameter(plainTextValue) &&\n\t\t\t\tdotSecPlainText.config?.standardParameterStorageType === \"ssm\" &&\n\t\t\t\t(isRegularParameterObject(plainTextValue)\n\t\t\t\t\t? plainTextValue.dontStore !== true\n\t\t\t\t\t: true))\n\t\t) {\n\t\t\tlet parameterTier: ParameterTier = ParameterTier.STANDARD;\n\t\t\tlet parameterType: ParameterType = ParameterType.STRING;\n\t\t\tlet description: string | undefined;\n\t\t\tif (isSSMParameter(plainTextValue)) {\n\t\t\t\tif (plainTextValue?.ssm?.tier) {\n\t\t\t\t\tparameterTier = plainTextValue.ssm.tier;\n\t\t\t\t}\n\t\t\t\tif (plainTextValue?.ssm?.type) {\n\t\t\t\t\tparameterType = plainTextValue.ssm.type;\n\t\t\t\t}\n\t\t\t\tif (plainTextValue?.description) {\n\t\t\t\t\tdescription = plainTextValue.description;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst putParameterCommand = new PutParameterCommand({\n\t\t\t\tName: `/${keyPath}`,\n\t\t\t\tValue: String(storageValue),\n\t\t\t\tType: parameterType,\n\t\t\t\tTier: parameterTier,\n\t\t\t\tDescription: description,\n\t\t\t\tOverwrite: true,\n\t\t\t});\n\t\t\tputParameterCommands.push(putParameterCommand);\n\t\t\t// await ssmClient.send(putParameterCommand);\n\t\t} else if (\n\t\t\tisSecretsManagerParameter(plainTextValue) ||\n\t\t\t(isRegularParameter(plainTextValue) &&\n\t\t\t\tdotSecPlainText.config?.standardParameterStorageType ===\n\t\t\t\t\t\"secretsManager\" &&\n\t\t\t\t(isRegularParameterObject(plainTextValue)\n\t\t\t\t\t? plainTextValue.dontStore !== true\n\t\t\t\t\t: true))\n\t\t) {\n\t\t\tconst existingSecretARN = existingSecrets[keyPath];\n\t\t\tif (!existingSecretARN) {\n\t\t\t\tconst createSecretCommand = new CreateSecretCommand({\n\t\t\t\t\tName: keyPath,\n\t\t\t\t\tSecretString: String(storageValue),\n\t\t\t\t});\n\t\t\t\tcreateSecretCommands.push(createSecretCommand);\n\t\t\t\t// await secretsManagerClient.send(createSecretCommand);\n\t\t\t} else {\n\t\t\t\tconst putSecretCommand = new PutSecretValueCommand({\n\t\t\t\t\tSecretId: existingSecretARN,\n\t\t\t\t\tSecretString: String(storageValue),\n\t\t\t\t});\n\t\t\t\tputSecretValueCommands.push(putSecretCommand);\n\t\t\t\t// await secretsManagerClient.send(putSecretCommand);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttotal:\n\t\t\tputParameterCommands.length +\n\t\t\tcreateSecretCommands.length +\n\t\t\tputSecretValueCommands.length,\n\t\tputParameterCommands,\n\t\tcreateSecretCommands,\n\t\tputSecretValueCommands,\n\t};\n};\n\nexport const executeStorePlainTextTasks = async (options: {\n\tcredentials: Credentials;\n\tregion: string;\n\tverbose?: boolean;\n\ttasks: SyncTasks;\n}): Promise<void> => {\n\tconst { credentials, region, verbose, tasks } = options;\n\tconst { info } = getLogger();\n\tconst ssmClient = getSSMClient({\n\t\tconfiguration: {\n\t\t\tcredentials,\n\t\t\tregion,\n\t\t},\n\t\tverbose,\n\t});\n\n\tconst secretsManagerClient = getSecretsManagerClient({\n\t\tconfiguration: {\n\t\t\tcredentials,\n\t\t\tregion,\n\t\t},\n\t\tverbose,\n\t});\n\tfor (const putParameterCommand of tasks.putParameterCommands) {\n\t\tprocess.stdout.write(\n\t\t\t`Storing SSM parameter ${emphasis(\n\t\t\t\tputParameterCommand.input.Name || \"<unnamed> \",\n\t\t\t)}... `,\n\t\t);\n\t\tawait ssmClient.send(putParameterCommand);\n\t\tprocess.stdout.write(`done\\n`);\n\t}\n\tfor (const createSecretCommand of tasks.createSecretCommands) {\n\t\tprocess.stdout.write(\n\t\t\t`Creating Secret ${emphasis(\n\t\t\t\tcreateSecretCommand.input.Name || \"<unnamed> \",\n\t\t\t)}... `,\n\t\t);\n\t\tawait secretsManagerClient.send(createSecretCommand);\n\t\tprocess.stdout.write(`done\\n`);\n\t}\n\tfor (const putSecretValueCommand of tasks.putSecretValueCommands) {\n\t\tprocess.stdout.write(\n\t\t\t`Updating Secret ${emphasis(\n\t\t\t\tputSecretValueCommand.input.SecretId || \"<unknown id> \",\n\t\t\t)}... `,\n\t\t);\n\t\tawait secretsManagerClient.send(putSecretValueCommand);\n\t\tprocess.stdout.write(`done\\n`);\n\t}\n};\n\nexport const prettyPrintTasks = (tasks: SyncTasks) => {\n\tconst { info, table } = getLogger();\n\tconst { putParameterCommands, createSecretCommands, putSecretValueCommands } =\n\t\ttasks;\n\n\tconst ssmTasks = putParameterCommands.map((command) => {\n\t\treturn {\n\t\t\tname: command.input.Name,\n\t\t\tdescription: command.input.Description || \"<no description>\",\n\t\t\ttier: command.input.Tier,\n\t\t\ttype: command.input.Type,\n\t\t\tvalue: command.input.Value,\n\t\t};\n\t});\n\tinfo(emphasis(`AWS Systems Manager > Parameter Store: create or update`));\n\ttable(ssmTasks);\n\n\tconst createSecretTasks = createSecretCommands.map((command) => {\n\t\treturn {\n\t\t\tsecretName: command.input.Name,\n\t\t\tdescription: command.input.Description || \"<no description>\",\n\t\t\tvalue: \"**** redacted ****>\",\n\t\t};\n\t});\n\tif (createSecretTasks.length) {\n\t\tinfo(emphasis(`AWS Secrets Manager Secrets: create`));\n\t\ttable(createSecretTasks);\n\t}\n\tconst updateSecretTasks = putSecretValueCommands.map((command) => {\n\t\treturn {\n\t\t\tsecretName: command.input.SecretId,\n\t\t\tvalue: \"**** redacted ****>\",\n\t\t};\n\t});\n\tif (updateSecretTasks.length) {\n\t\tinfo(emphasis(`AWS Secrets Manager Secrets: update`));\n\t\ttable(updateSecretTasks);\n\t}\n};\nexport const decryptRawDotSecValues = async (options: {\n\tdotSecKeysValues: Record<string, string>;\n\tcredentials: Credentials;\n\tregion: string;\n\tverbose?: boolean;\n\tkeyAlias?: string;\n\tsearchPath?: string;\n}): Promise<string> => {\n\tconst { info } = getLogger();\n\n\tconst {\n\t\tdotSecKeysValues: rawDotSec,\n\t\tcredentials,\n\t\tregion,\n\t\tverbose,\n\t\tkeyAlias,\n\t\tsearchPath,\n\t} = options;\n\n\tconst kmsClient = getKMSClient({\n\t\tconfiguration: {\n\t\t\tcredentials,\n\t\t\tregion,\n\t\t},\n\t\tverbose,\n\t});\n\n\tconst s = searchPath\n\t\t?.split(\".\")\n\t\t.map((part) => `${constantCase(part)}_`)\n\t\t.join(\"\");\n\tconst awsKeyAlias = keyAlias;\n\tif (!keyAlias) {\n\t\tthrow new Error(\"No key alias specified\");\n\t}\n\n\tconst encryptionAlgorithm = await getEncryptionAlgorithm(kmsClient, keyAlias);\n\tconst dotEnvLines: string[] = [];\n\n\tconst filtered = s\n\t\t? Object.fromEntries(\n\t\t\t\tObject.entries(rawDotSec)\n\t\t\t\t\t.filter(([key]) => key.startsWith(s))\n\t\t\t\t\t.map(([key, value]) => [key.replace(s, \"\"), value]),\n\t\t )\n\t\t: rawDotSec;\n\tfor (const [key, encryptedValue] of Object.entries(filtered)) {\n\t\tconst decryptCommand = new DecryptCommand({\n\t\t\tKeyId: awsKeyAlias,\n\t\t\tCiphertextBlob: Buffer.from(encryptedValue, \"base64\"),\n\t\t\tEncryptionAlgorithm: encryptionAlgorithm,\n\t\t});\n\n\t\tconst decryptionResult = await kmsClient.send(decryptCommand);\n\n\t\tif (!decryptionResult.Plaintext) {\n\t\t\tthrow new Error(\n\t\t\t\t`Something bad happened: ${JSON.stringify({\n\t\t\t\t\tkey,\n\t\t\t\t\tcipherText: encryptedValue,\n\t\t\t\t\tdecryptCommand: decryptCommand,\n\t\t\t\t})}`,\n\t\t\t);\n\t\t}\n\n\t\tif (verbose) {\n\t\t\tinfo(`Decrypting key ${emphasis(key)} ${strong(\"ok\")}`);\n\t\t}\n\n\t\tconst decryptedValue = Buffer.from(decryptionResult.Plaintext).toString();\n\t\t// this *is* json\n\t\tconst parsedValue = JSON.parse(decryptedValue) as {\n\t\t\tkey: string;\n\t\t\tvalue: string;\n\t\t};\n\n\t\tconst stringOrJson = maybeJson(parsedValue.value);\n\n\t\tif (isRegularParameter(stringOrJson)) {\n\t\t\tif (isRegularParameterObject(stringOrJson)) {\n\t\t\t\tdotEnvLines.push(`${key}=${JSON.stringify(stringOrJson.value)}`);\n\t\t\t} else {\n\t\t\t\tdotEnvLines.push(`${key}=${String(stringOrJson)}`);\n\t\t\t}\n\t\t} else if (isSSMParameter(stringOrJson)) {\n\t\t\t// if (isSSMParameterObject(stringOrJson)) {\n\t\t\tdotEnvLines.push(`${key}=${JSON.stringify(stringOrJson.value)}`);\n\t\t\t// } else {\n\t\t\t// dotEnvLines.push(`${key}=${String(stringOrJson)}`);\n\t\t\t// }\n\t\t} else if (isSecretsManagerParameter(stringOrJson)) {\n\t\t\tdotEnvLines.push(`${key}=${JSON.stringify(stringOrJson.value)}`);\n\t\t}\n\n\t\t// unbox values\n\t}\n\n\treturn dotEnvLines.join(\"\\n\");\n};\n", "import {\n SecretsManagerClient,\n SecretsManagerClientConfig,\n} from '@aws-sdk/client-secrets-manager';\n\nexport const getSecretsManagerClient = ({\n configuration,\n}: {\n verbose?: boolean;\n configuration: SecretsManagerClientConfig;\n}) => {\n const secretsManagerClient = new SecretsManagerClient(configuration);\n return secretsManagerClient;\n};\n", "import { SSMClient, SSMClientConfig } from '@aws-sdk/client-ssm';\n\nexport const getSSMClient = ({\n configuration,\n}: {\n verbose?: boolean;\n configuration: SSMClientConfig;\n}) => {\n const ssmClient = new SSMClient(configuration);\n return ssmClient;\n};\n", "import { ParameterTier, ParameterType } from \"@aws-sdk/client-ssm\";\n\n// type Not<T extends { [key: string]: unknown }> = Id<{ [P in keyof T]?: never }>;\ntype Id<T> = T extends { [key: string]: unknown }\n\t? Record<string, unknown> & { [P in keyof T]: Id<T[P]> }\n\t: T;\nexport const dotSecFileTypes = [\"json\", \"ts\", \"yaml\", \"yml\"] as const;\nexport type DotSecFileType = typeof dotSecFileTypes[number];\nexport type DotSecEncryptedEncoding = \"encrypted\";\nexport type DotSecPlaintextEncoding = \"plaintext\";\nexport type DotSecEncoding = DotSecPlaintextEncoding | DotSecEncryptedEncoding;\nexport type DotSecValue =\n\t| string\n\t| number\n\t| boolean\n\t| { [key: string]: DotSecValue }\n\t| Array<DotSecValue>;\nexport type SSMParameterObject = {\n\ttype: \"ssm\";\n\tdescription?: string;\n\tssm?: {\n\t\ttype?: ParameterType;\n\t\ttier?: ParameterTier;\n\t};\n\tvalue: DotSecValue;\n\tencryptedValue?: never;\n};\nexport type SSMEncryptedParameterObject = {\n\ttype: \"ssm\";\n\tdescription?: string;\n\tvalue?: never;\n\tencryptedValue: string;\n};\nexport type StandardParameterObject = {\n\ttype: \"standard\";\n\tdescription?: string;\n\tvalue: DotSecValue;\n\tdontStore?: boolean;\n\tencryptedValue?: never;\n};\nexport type StandardEncryptedParameterObject = {\n\ttype: \"standard\";\n\tdescription?: string;\n\tvalue?: never;\n\tencryptedValue: string;\n};\nexport type SSMParameter<\n\tEncoding extends DotSecEncoding = DotSecPlaintextEncoding,\n> = Encoding extends DotSecPlaintextEncoding\n\t? SSMParameterObject\n\t: SSMEncryptedParameterObject;\nexport type StandardParameter<\n\tEncoding extends DotSecEncoding = DotSecPlaintextEncoding,\n> = Encoding extends DotSecPlaintextEncoding\n\t? string | number | boolean | StandardParameterObject\n\t: StandardEncryptedParameterObject;\n\nexport type DotSecSecretsManagerParameter = {\n\tvalue: DotSecValue;\n\tencryptedValue?: never;\n};\n\nexport type SecretsManagerParameter<\n\tEncoding extends DotSecEncoding = DotSecPlaintextEncoding,\n> = {\n\ttype: \"secretsManager\";\n\tdescription?: string;\n} & (Encoding extends DotSecPlaintextEncoding\n\t? DotSecSecretsManagerParameter\n\t: {\n\t\t\ttype: \"secretsManager\";\n\n\t\t\tvalue?: never;\n\t\t\tencryptedValue: string;\n\t });\n\nexport type DotSecLeaf<\n\tEncoding extends DotSecEncoding /* = DotSecPlainTextEncoding */,\n> =\n\t| SSMParameter<Encoding>\n\t| SecretsManagerParameter<Encoding>\n\t| StandardParameter<Encoding>;\n\nexport type DotSecTree<\n\tEncoding extends DotSecEncoding,\n\tTreeShape extends DotSecTreeShape,\n> = {\n\t[key: string]: TreeShape extends DotSecExpandedTree\n\t\t? DotSecLeaf<Encoding> | DotSecTree<Encoding, TreeShape>\n\t\t: DotSecLeaf<Encoding>;\n};\ntype DotSecFlatTree<Encoding extends DotSecEncoding = DotSecPlaintextEncoding> =\n\tDotSecTree<Encoding, DotSecExpandedTree>;\n\nexport type DeepPartial<T> = T extends object\n\t? {\n\t\t\t[P in keyof T]?: DeepPartial<T[P]>;\n\t }\n\t: T;\n\nexport type OptionalDeepPartial<\n\tT,\n\tIgnorePartials extends boolean = false,\n> = IgnorePartials extends true\n\t? T\n\t: T extends object\n\t? {\n\t\t\t[P in keyof T]?: DeepPartial<T[P]>;\n\t }\n\t: T;\nexport type DotSecConfig<\n\tConfigDemand extends DotSecConfigDemand = DotSecWithOptionalConfig,\n> = OptionalDeepPartial<\n\t{\n\t\tconfig: {\n\t\t\tpathPrefix?: string;\n\t\t\tuseTopLevelsAsEnvironments?: boolean;\n\t\t\tstandardParameterStorageType?: \"none\" | \"ssm\" | \"secretsManager\";\n\t\t\taws: {\n\t\t\t\tkeyAlias: string;\n\t\t\t\tregions: Array<string>;\n\t\t\t\t// environmentMapping?: {\n\t\t\t\t// [awsEnvironment: string]: {\n\t\t\t\t// accountId: string;\n\t\t\t\t// accessKeyId: string;\n\t\t\t\t// secretAccessKey: string;\n\t\t\t\t// };\n\t\t\t\t// };\n\t\t\t};\n\t\t};\n\t},\n\tConfigDemand extends DotSecWithOptionalConfig ? false : true\n>;\nexport type DotSecPlainTextByFileType = {\n\tfileType: DotSecFileType;\n\tpath: string;\n\tdotSecPlainText: DotSecPlainText;\n\traw: string;\n};\nexport type DotSecEncryptedByFileType = {\n\tfileType: DotSecFileType;\n\tpath: string;\n\tdotSecEncrypted: DotSecEncrypted;\n};\nexport type DotSecRequiredConfig = DotSecConfig<DotSecWithRequiredConfig>;\nexport type DotSecTrees =\n\t| DotSecTree<DotSecPlaintextEncoding, DotSecExpandedTree>\n\t| DotSecTree<DotSecEncryptedEncoding, DotSecExpandedTree>\n\t| DotSecTree<DotSecPlaintextEncoding, DotSecFlattenedTree>\n\t| DotSecTree<DotSecEncryptedEncoding, DotSecFlattenedTree>;\n\nexport type DotSec<\n\tTree extends DotSecTrees = DotSecTree<\n\t\tDotSecPlaintextEncoding,\n\t\tDotSecExpandedTree\n\t>,\n\tEncoding extends DotSecEncoding = DotSecPlaintextEncoding,\n\tFlattened extends DotSecTreeShape = DotSecExpandedTree,\n\tWithRequiredConfig extends DotSecConfigDemand = DotSecWithOptionalConfig,\n> = DS<Tree, Encoding, Flattened, WithRequiredConfig>;\n\nexport type DS<\n\tTree extends DotSecTrees,\n\tEncoding extends DotSecEncoding = DotSecPlaintextEncoding,\n\tFlattened extends DotSecTreeShape = DotSecExpandedTree,\n\tWithRequiredConfig extends DotSecConfigDemand = DotSecWithOptionalConfig,\n> = DotSecConfig<WithRequiredConfig> &\n\t(Encoding extends DotSecPlaintextEncoding\n\t\t? {\n\t\t\t\tplaintext: Tree extends DotSecTree<DotSecPlaintextEncoding, Flattened>\n\t\t\t\t\t? Tree\n\t\t\t\t\t: never;\n\t\t\t\tencrypted?: never;\n\t\t }\n\t\t: {\n\t\t\t\tencrypted: Tree extends DotSecTree<DotSecEncryptedEncoding, Flattened>\n\t\t\t\t\t? Tree\n\t\t\t\t\t: never;\n\t\t\t\tplaintext?: never;\n\t\t });\n\nexport type DotSecFlattenedTree = \"flattened\";\nexport type DotSecExpandedTree = \"expanded\";\nexport type DotSecTreeShape = DotSecFlattenedTree | DotSecExpandedTree;\nexport type DotSecWithOptionalConfig = \"with-optional-config\";\nexport type DotSecWithRequiredConfig = \"with-required-config\";\nexport type DotSecConfigDemand =\n\t| DotSecWithOptionalConfig\n\t| DotSecWithRequiredConfig;\nexport type DotSecEncrypted<\n\tT extends DotSecTree<\n\t\tDotSecEncryptedEncoding,\n\t\tDotSecExpandedTree\n\t> = DotSecTree<DotSecEncryptedEncoding, DotSecExpandedTree>,\n> = DotSec<T, DotSecEncryptedEncoding>;\n\nexport type DotSecPlainText<\n\tT extends DotSecTree<\n\t\tDotSecPlaintextEncoding,\n\t\tDotSecExpandedTree\n\t> = DotSecTree<DotSecPlaintextEncoding, DotSecExpandedTree>,\n> = DotSec<T, DotSecPlaintextEncoding>;\n\nexport type DotSecPlainTextWithOptionalConfig<\n\tT extends DotSecTree<\n\t\tDotSecPlaintextEncoding,\n\t\tDotSecExpandedTree\n\t> = DotSecTree<DotSecPlaintextEncoding, DotSecExpandedTree>,\n> = DotSec<\n\tT,\n\tDotSecPlaintextEncoding,\n\tDotSecExpandedTree,\n\tDotSecWithOptionalConfig\n>;\nexport type DotSecEncryptedWithOptionalConfig<\n\tT extends DotSecTree<\n\t\tDotSecEncryptedEncoding,\n\t\tDotSecExpandedTree\n\t> = DotSecTree<DotSecEncryptedEncoding, DotSecExpandedTree>,\n> = DotSec<\n\tT,\n\tDotSecEncryptedEncoding,\n\tDotSecExpandedTree,\n\tDotSecWithOptionalConfig\n>;\n\n// user types\nexport type DotSecVariables<\n\tT extends DotSecTree<\n\t\tDotSecPlaintextEncoding,\n\t\tDotSecExpandedTree\n\t> = DotSecTree<DotSecPlaintextEncoding, DotSecExpandedTree>,\n> = DotSec<\n\tT,\n\tDotSecPlaintextEncoding,\n\tDotSecExpandedTree,\n\tDotSecWithOptionalConfig\n>;\n\nexport type DotSecPlainTextFlattened<\n\tT extends DotSecTree<\n\t\tDotSecPlaintextEncoding,\n\t\tDotSecFlattenedTree\n\t> = DotSecTree<DotSecPlaintextEncoding, DotSecFlattenedTree>,\n> = DotSec<T, DotSecPlaintextEncoding, DotSecFlattenedTree>;\n\nexport type DotSecEncryptedFlattened<\n\tT extends DotSecTree<\n\t\tDotSecEncryptedEncoding,\n\t\tDotSecFlattenedTree\n\t> = DotSecTree<DotSecEncryptedEncoding, DotSecFlattenedTree>,\n> = DotSec<T, DotSecEncryptedEncoding, DotSecFlattenedTree>;\n\nexport const environments = [\"dev\", \"prod\"] as const;\nexport type Environment = typeof environments[number];\nconst dotSecPlainText: DotSecPlainText = {\n\tplaintext: {\n\t\tfoo: { type: \"ssm\", value: \"asd\" },\n\t\tbar: { foo: { type: \"ssm\", value: \"asd\" } },\n\t},\n};\nconst dotSecEncrypted: DotSecEncrypted = {\n\tencrypted: {\n\t\tfoo: { type: \"ssm\", encryptedValue: \"asd\" },\n\t\tbar: { foo: { type: \"ssm\", encryptedValue: \"asd\" } },\n\t},\n};\nconst dotSecPlainTextFlattened: DotSecPlainTextFlattened = {\n\tplaintext: {\n\t\tfoo: { type: \"ssm\", value: \"asd\" },\n\t},\n};\nconst dotSecEncryptedFlattened: DotSecEncryptedFlattened = {\n\tencrypted: {\n\t\tfoo: { type: \"secretsManager\", encryptedValue: \"asd\" },\n\t},\n};\nconst t: DotSec<\n\t{\n\t\t[key in Environment]: {\n\t\t\tother: {\n\t\t\t\tfoo: StandardParameter;\n\t\t\t\tbar: SSMParameter;\n\t\t\t\tshit: {\n\t\t\t\t\tanother: SecretsManagerParameter;\n\t\t\t\t\tmekker: SSMParameter;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t},\n\tDotSecPlaintextEncoding\n> = {\n\tplaintext: {\n\t\tdev: {\n\t\t\tother: {\n\t\t\t\tfoo: \"123\",\n\t\t\t\tbar: { type: \"ssm\", value: \"asd\" },\n\t\t\t\tshit: {\n\t\t\t\t\tanother: { type: \"secretsManager\", value: \"qasd\" },\n\t\t\t\t\tmekker: { type: \"ssm\", value: \"off\" },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tprod: {\n\t\t\tother: {\n\t\t\t\tfoo: \"123\",\n\t\t\t\tbar: { type: \"ssm\", value: \"asd\" },\n\t\t\t\tshit: {\n\t\t\t\t\tanother: {\n\t\t\t\t\t\ttype: \"secretsManager\",\n\t\t\t\t\t\tvalue: \"asdasd\",\n\t\t\t\t\t},\n\t\t\t\t\tmekker: { type: \"ssm\", value: \"on\" },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n};\n\nconst tt: DotSec = {\n\tplaintext: {\n\t\tdev: {\n\t\t\tother: {\n\t\t\t\tfoo: \"123\",\n\t\t\t\tbar: { type: \"ssm\", value: \"asd\" },\n\t\t\t\tshit: {\n\t\t\t\t\tanother: { type: \"secretsManager\", value: \"qasd\" },\n\t\t\t\t\tmekker: 123,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tprod: {\n\t\t\tother: {\n\t\t\t\tfoo: \"123\",\n\t\t\t\tbar: { type: \"ssm\", value: \"asd\" },\n\t\t\t\tshit: {\n\t\t\t\t\tanother: {\n\t\t\t\t\t\ttype: \"secretsManager\",\n\t\t\t\t\t\tvalue: \"asdasd\",\n\t\t\t\t\t},\n\t\t\t\t\tmekker: { type: \"ssm\", value: \"fuck off\" },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n};\n\nexport const isString = (value: unknown): value is string => {\n\treturn typeof value === \"string\";\n};\n\nexport const isNumber = (value: unknown): value is number => {\n\treturn typeof value === \"number\";\n};\nexport const isBoolean = (value: unknown): value is boolean => {\n\treturn typeof value === \"boolean\";\n};\n\nexport const isSSMParameterObject = (\n\tvalue: unknown,\n): value is SSMParameterObject => {\n\tconst ssmParameter = value as SSMParameter;\n\treturn (\n\t\ttypeof ssmParameter === \"object\" &&\n\t\tssmParameter !== null &&\n\t\t\"type\" in ssmParameter &&\n\t\tssmParameter.type === \"ssm\"\n\t);\n};\n\nexport const isSSMParameter = <Encoding extends DotSecEncoding>(\n\tleafOrTree: unknown,\n): leafOrTree is SSMParameter<Encoding> => {\n\tconst ssmParameter = leafOrTree as SSMParameter<Encoding>;\n\treturn (\n\t\ttypeof ssmParameter === \"object\" &&\n\t\tssmParameter !== null &&\n\t\t\"type\" in ssmParameter &&\n\t\tssmParameter.type === \"ssm\"\n\t);\n};\n\nexport const isRegularParameterObject = (\n\tvalue: unknown,\n): value is StandardParameterObject => {\n\tconst regularParameter = value as StandardParameter;\n\treturn (\n\t\ttypeof regularParameter === \"object\" &&\n\t\tregularParameter !== null &&\n\t\t\"type\" in regularParameter &&\n\t\tregularParameter.type === \"standard\"\n\t);\n};\n\nexport const isRegularParameter = <Encoding extends DotSecEncoding>(\n\tleafOrTree: unknown,\n): leafOrTree is StandardParameter<Encoding> => {\n\tconst leaf = leafOrTree as StandardParameter<Encoding>;\n\treturn (\n\t\tisString(leaf) ||\n\t\tisNumber(leaf) ||\n\t\tisBoolean(leaf) ||\n\t\tisRegularParameterObject(leaf)\n\t);\n};\n\nexport const isEncryptedSSMParameter = (\n\tleafOrTree: unknown,\n): leafOrTree is SSMParameter<DotSecEncryptedEncoding> => {\n\tconst leaf = leafOrTree as SSMParameter<DotSecEncryptedEncoding>;\n\treturn (\n\t\tleaf.type !== undefined &&\n\t\tleaf.type === \"ssm\" &&\n\t\tleaf.encryptedValue !== undefined\n\t);\n};\n\nexport const isEncryptedRegularParameter = (\n\tleafOrTree: unknown,\n): leafOrTree is StandardParameter<DotSecEncryptedEncoding> => {\n\tconst leaf = leafOrTree as StandardParameter<DotSecEncryptedEncoding>;\n\treturn (\n\t\tleaf.type !== undefined &&\n\t\tleaf.type === \"standard\" &&\n\t\tleaf.encryptedValue !== undefined\n\t);\n};\n\nexport const isSecretsManagerParameter = <Encoding extends DotSecEncoding>(\n\tleafOrTree: unknown,\n): leafOrTree is SecretsManagerParameter<Encoding> => {\n\tconst leaf = leafOrTree as SecretsManagerParameter<Encoding>;\n\treturn (\n\t\tleaf.type !== undefined &&\n\t\tleaf.type === \"secretsManager\" &&\n\t\t!(isString(leaf) || isNumber(leaf) || isBoolean(leaf))\n\t);\n};\n\nexport const isDotSecTree = <Encoding extends DotSecEncoding>(\n\tleafOrTree: unknown,\n): leafOrTree is DotSecTree<Encoding, DotSecExpandedTree> => {\n\tif (\n\t\ttypeof leafOrTree === \"object\" &&\n\t\t!Array.isArray(leafOrTree) &&\n\t\tleafOrTree !== null &&\n\t\t!isSSMParameter(leafOrTree) &&\n\t\t!isRegularParameter(leafOrTree) &&\n\t\t!isEncryptedSSMParameter(leafOrTree) &&\n\t\t!isEncryptedRegularParameter(leafOrTree) &&\n\t\t!isSecretsManagerParameter(leafOrTree)\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n\nexport const isDotSecPlaintTextTree = <Encoding extends DotSecEncoding>(\n\tleafOrTree: unknown,\n): leafOrTree is DotSecTree<Encoding, DotSecExpandedTree> => {\n\tif (\n\t\ttypeof leafOrTree === \"object\" &&\n\t\t!Array.isArray(leafOrTree) &&\n\t\tleafOrTree !== null &&\n\t\t!isSSMParameter(leafOrTree) &&\n\t\t!isRegularParameter(leafOrTree) &&\n\t\t!isSecretsManagerParameter(leafOrTree)\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n", "import {\n\tDotSecEncoding,\n\tDotSecEncrypted,\n\tDotSecEncryptedFlattened,\n\tDotSecExpandedTree,\n\tDotSecFlattenedTree,\n\tDotSecLeaf,\n\tDotSecPlainText,\n\tDotSecPlainTextFlattened,\n\tDotSecTree,\n\tisDotSecTree,\n} from \"./types\";\nexport const flattenTree = <\n\tEncoding extends DotSecEncoding,\n\tTree extends DotSecTree<Encoding, DotSecExpandedTree> | DotSecLeaf<Encoding>,\n>(\n\ttree: Tree,\n): DotSecTree<Encoding, DotSecFlattenedTree> => {\n\tconst lazy: DotSecTree<Encoding, DotSecFlattenedTree> = {};\n\n\tconst innerParser = (\n\t\tleafOrTree: DotSecTree<Encoding, DotSecExpandedTree> | DotSecLeaf<Encoding>,\n\t\tpaths: Array<string> = [],\n\t) => {\n\t\tif (isDotSecTree(leafOrTree)) {\n\t\t\tObject.entries(leafOrTree).map(([key, value]) => {\n\t\t\t\tinnerParser(value, [...paths, key]);\n\t\t\t});\n\t\t} else {\n\t\t\tlazy[paths.join(\"/\")] = leafOrTree;\n\t\t}\n\t};\n\n\tinnerParser(tree);\n\treturn lazy;\n};\n\nexport const flattenPlainText = (\n\tdotSec: DotSecPlainText,\n): DotSecPlainTextFlattened => {\n\treturn { ...dotSec, plaintext: flattenTree(dotSec.plaintext) };\n};\n\nexport const flattenEncrypted = (\n\tdotSec: DotSecEncrypted,\n): DotSecEncryptedFlattened => {\n\treturn { ...dotSec, encrypted: flattenTree(dotSec.encrypted) };\n};\n\nconst expandTree = <\n\tEncoding extends DotSecEncoding,\n\tTree extends DotSecTree<Encoding, DotSecFlattenedTree>,\n>(\n\ttree: Tree,\n): DotSecTree<Encoding, DotSecExpandedTree> => {\n\tconst lazy: DotSecTree<Encoding, DotSecExpandedTree> = {};\n\tObject.entries(tree).map(([key, value]) => {\n\t\tconst paths = key.split(\"/\");\n\t\tlet current = lazy;\n\t\tpaths.forEach((pathKey, index) => {\n\t\t\tif (!current[pathKey]) {\n\t\t\t\tif (index === paths.length - 1) {\n\t\t\t\t\tcurrent[pathKey] = value;\n\t\t\t\t} else {\n\t\t\t\t\tcurrent[pathKey] = {};\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore\n\t\t\tcurrent = current[pathKey];\n\t\t});\n\t});\n\n\treturn lazy;\n};\n\nexport const expandPlainText = (\n\tdotSec: DotSecPlainTextFlattened,\n): DotSecPlainText => {\n\treturn { ...dotSec, plaintext: expandTree(dotSec.plaintext) };\n};\n\nexport const expandEncrypted = (\n\tdotSec: DotSecEncryptedFlattened,\n): DotSecEncrypted => {\n\treturn { ...dotSec, encrypted: expandTree(dotSec.encrypted) };\n};\n", "import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { bundleRequire } from 'bundle-require';\nimport JoyCon from 'joycon';\n\nimport { getLogger, strong } from '../../utils/logger';\nimport { loadJson } from './json';\nimport {\n DotSecConfig,\n DotSecFileType,\n DotSecRequiredConfig,\n DotSecPlainTextByFileType,\n DotSecPlainTextWithOptionalConfig,\n DotSecEncryptedByFileType,\n DotSecEncryptedWithOptionalConfig,\n DotSec,\n DotSecEncoding,\n DotSecExpandedTree,\n DotSecPlaintextEncoding,\n DotSecTree,\n} from './types';\nimport { loadYml } from './yaml';\n\nexport const getValidatedConfig = (\n partialConfig: DotSecRequiredConfig,\n userConfig?: DotSecConfig,\n): DotSecRequiredConfig => {\n const keyAlias: string | undefined =\n partialConfig?.config?.aws?.keyAlias ||\n userConfig?.config?.aws?.keyAlias;\n\n if (!keyAlias) {\n throw new Error('Expected keyAlias, but gone none');\n }\n const regions: Array<string | undefined> | undefined =\n partialConfig?.config?.aws?.regions || userConfig?.config?.aws?.regions;\n\n if (!regions) {\n throw new Error('Expected regions, but gone none');\n }\n return {\n config: {\n aws: {\n keyAlias,\n regions: regions as Array<string>,\n },\n },\n };\n};\n\nexport const getDotSecPlainText = async ({\n defaultConfig,\n options,\n}: {\n defaultConfig: DotSecRequiredConfig;\n options?: { filename?: string; verbose?: boolean };\n}): Promise<DotSecPlainTextByFileType> => {\n const { info } = getLogger();\n const { filename, verbose } = options || {};\n\n const cwd = process.cwd();\n const configJoycon = new JoyCon();\n const files = filename\n ? [filename]\n : [\n 'secrets.json',\n 'secrets.yaml',\n 'secrets.yml',\n 'secrets.ts',\n // 'secrets.js',\n // 'secrets.cjs',\n // 'secrets.mjs',\n ];\n\n if (verbose) {\n info(\n `Looking for file(s) with the following signature(s): ${strong(\n files.join(', '),\n )}`,\n );\n }\n const configPath = await configJoycon.resolve({\n files,\n cwd,\n stopDir: path.parse(cwd).root,\n packageKey: 'secrets',\n });\n if (configPath) {\n if (verbose) {\n info(`Found plaintext secrets at ${strong(configPath)}`);\n }\n let configType: DotSecFileType | undefined;\n let data: DotSecPlainTextWithOptionalConfig | undefined;\n\n if (configPath.endsWith('.json')) {\n configType = 'json';\n // this is not entirely correct, since it could not contain all the required configuration\n data = (await loadJson(\n configPath,\n )) as DotSecPlainTextWithOptionalConfig;\n } else if (\n configPath.endsWith('.yaml') ||\n configPath.endsWith('.yml')\n ) {\n configType = 'yml';\n // this is not entirely correct, since it could not contain all the required configuration\n data = (await loadYml(\n configPath,\n )) as DotSecPlainTextWithOptionalConfig;\n } else if (configPath.endsWith('.ts')) {\n const bundleRequireResult = await bundleRequire({\n filepath: configPath,\n });\n configType = 'ts';\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n data = (bundleRequireResult.mod.dotsec ||\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n bundleRequireResult.mod.default ||\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n bundleRequireResult.mod) as DotSecPlainTextWithOptionalConfig;\n }\n\n if (!configType) {\n throw new Error(`Expected configType, but got none`);\n }\n if (!data) {\n throw new Error(`Expected data, but got none`);\n }\n const validatedConfig: DotSecRequiredConfig = {\n config: {\n ...data.config,\n aws: {\n regions:\n data?.config?.aws?.regions &&\n Array.isArray(data?.config?.aws?.regions)\n ? (data.config.aws.regions as string[])\n : defaultConfig.config.aws.regions,\n keyAlias:\n data?.config?.aws?.keyAlias ||\n defaultConfig.config.aws.keyAlias,\n },\n },\n };\n return {\n fileType: configType,\n path: configPath,\n dotSecPlainText: {\n ...data,\n ...validatedConfig,\n },\n };\n }\n throw new Error('No secrets file found');\n};\n\nexport const getDotSecEncrypted = async ({\n defaultConfig,\n options,\n}: {\n defaultConfig: DotSecRequiredConfig;\n options?: { filename?: string; verbose?: boolean };\n}): Promise<DotSecEncryptedByFileType> => {\n const { filename, verbose } = options || {};\n\n const cwd = process.cwd();\n const configJoycon = new JoyCon();\n const configPath = await configJoycon.resolve({\n files: filename\n ? [filename]\n : [\n 'secrets.encrypted.json',\n 'secrets.encrypted.yaml',\n 'secrets.encrypted.yml',\n 'secrets.encrypted.ts',\n // 'secrets.cjs',\n // 'secrets.mjs',\n ],\n cwd,\n stopDir: path.parse(cwd).root,\n packageKey: 'secrets',\n });\n if (configPath) {\n if (verbose) {\n console.log(`Found encrypted secrets file at ${configPath}`);\n }\n let configType: DotSecFileType | undefined;\n let data: DotSecEncryptedWithOptionalConfig | undefined;\n if (configPath.endsWith('.json')) {\n configType = 'json';\n data = (await loadJson(\n configPath,\n )) as DotSecEncryptedWithOptionalConfig;\n } else if (\n configPath.endsWith('.yaml') ||\n configPath.endsWith('.yml')\n ) {\n configType = path\n .parse(configPath)\n .ext.substring(1) as DotSecFileType;\n data = (await loadYml(\n configPath,\n )) as DotSecEncryptedWithOptionalConfig;\n }\n if (!configType) {\n throw new Error(`Config file ${configPath} is not supported`);\n }\n if (!data) {\n throw new Error('Did not find any data');\n }\n\n const validatedConfig: DotSecRequiredConfig = {\n config: {\n ...data.config,\n aws: {\n regions:\n data?.config?.aws?.regions &&\n Array.isArray(data?.config?.aws?.regions)\n ? (data.config.aws.regions as string[])\n : defaultConfig.config.aws.regions,\n keyAlias:\n data?.config?.aws?.keyAlias ||\n defaultConfig.config.aws.keyAlias,\n },\n },\n };\n return {\n fileType: configType,\n path: configPath,\n dotSecEncrypted: {\n ...data,\n ...validatedConfig,\n },\n };\n }\n throw new Error('No encrypted secrets file found');\n};\n\nexport const loadFile = async (filepath: string) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return await fs.promises.readFile(filepath, 'utf8');\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Failed to parse ${path.relative(process.cwd(), filepath)}: ${\n error.message\n }`,\n );\n } else {\n throw error;\n }\n }\n};\n\nexport const returnSecretsFile = (str: string) => {\n try {\n return JSON.parse(str) as DotSec<\n DotSecTree<DotSecPlaintextEncoding, DotSecExpandedTree>,\n DotSecEncoding\n >;\n } catch (error) {\n return;\n }\n};\n", "import fs from 'fs';\nimport path from 'node:path';\n\nexport function jsoncParse(data: string) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-implied-eval\n return new Function('return ' + data.trim())();\n } catch {\n // Silently ignore any error\n // That's what tsc/jsonc-parser did after all\n return {};\n }\n}\n\nexport const loadJson = async (filepath: string) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return jsoncParse(await fs.promises.readFile(filepath, 'utf8'));\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Failed to parse ${path.relative(process.cwd(), filepath)}: ${\n error.message\n }`,\n );\n } else {\n throw error;\n }\n }\n};\n", "import fs from 'fs';\nimport path from 'node:path';\n\nimport YAML from 'yaml';\n\nexport const loadYml = async (filepath: string) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return YAML.parse(await fs.promises.readFile(filepath, 'utf8'));\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Failed to parse ${path.relative(process.cwd(), filepath)}: ${\n error.message\n }`,\n );\n } else {\n throw error;\n }\n }\n};\n", "import fs from \"fs\";\nimport path from \"node:path\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport { decryptedEncrypted } from \"../lib/wtf/crypto\";\nimport { toDotEnv, toDotEnvPerEnvironment } from \"../lib/wtf/dotenv\";\nimport { getDotSecEncrypted } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { promptOverwriteIfFileExists } from \"../utils/io\";\nimport { getLogger, prettyCode, strong } from \"../utils/logger\";\n\nexport const command = \"encrypted-secrets-to-dot-env\";\nexport const desc = `Creates .env file from an encrypted secrets file.\nIf '--use-top-levels-as-environments' is set, it will create a .env file for each top level key in the encrypted secrets file.`;\n\nexport const builder = {\n\t\"encrypted-secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file for writing encrypted secrets\",\n\t\tdefault: \"secrets.encrypted.json\",\n\t},\n\t\"env-file\": commonCliOptions.envFile,\n\t\"search-path\": commonCliOptions.searchpath,\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\t\"use-top-levels-as-environments\": commonCliOptions.useTopLevelsAsEnvironments,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\n\tconst { info, error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\targv: {\n\t\t\t\t\t...argv,\n\t\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t},\n\t\t\t\tenv: { ...process.env },\n\t\t\t});\n\n\t\tconst { fileType, dotSecEncrypted } = await getDotSecEncrypted({\n\t\t\tdefaultConfig: {\n\t\t\t\tconfig: {\n\t\t\t\t\taws: {\n\t\t\t\t\t\tkeyAlias: \"alias/dotsec\",\n\t\t\t\t\t\tregions: [regionAndOrigin.value],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tverbose: argv.verbose,\n\t\t\t},\n\t\t});\n\t\tif (!dotSecEncrypted.encrypted) {\n\t\t\tthrow new Error(`Expected 'encrypted' property, but got none`);\n\t\t}\n\t\t// const dotSecEncryptedFlattened = flattenEncrypted(dotSecEncrypted);\n\t\t// const expanded = expandEncrypted(dotSecEncryptedFlattened);\n\n\t\tconst dotSecPlainText = await decryptedEncrypted({\n\t\t\tdotSecEncrypted,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias,\n\t\t\tverbose: argv.verbose,\n\t\t});\n\n\t\tif (\n\t\t\targv.useTopLevelsAsEnvironments ||\n\t\t\tdotSecEncrypted.config?.useTopLevelsAsEnvironments\n\t\t) {\n\t\t\tconst dotEnvsPerEnvironment = toDotEnvPerEnvironment({\n\t\t\t\tdotSecPlainText,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t});\n\n\t\t\tfor (const [environment, dotEnv] of Object.entries(\n\t\t\t\tdotEnvsPerEnvironment,\n\t\t\t)) {\n\t\t\t\tconst fileName = `.env.${environment}`;\n\t\t\t\tconst dotEnvPath = path.resolve(process.cwd(), fileName);\n\n\t\t\t\tinfo(`target: ${strong(dotEnvPath)}\\n`);\n\t\t\t\tinfo(prettyCode(dotEnv));\n\t\t\t\tinfo(`\\n`);\n\t\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\tfilePath: dotEnvPath,\n\t\t\t\t\tskip: argv.yes,\n\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tfs.writeFileSync(dotEnvPath, dotEnv);\n\t\t\t\t}\n\n\t\t\t\t// write to file, prompt if file exists\n\t\t\t}\n\t\t} else {\n\t\t\tconst dotEnv = toDotEnv({\n\t\t\t\tdotSecPlainText,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t\tsearchPath: argv.searchPath,\n\t\t\t});\n\n\t\t\tconst fileName = argv.envFile || `.env`;\n\t\t\tconst dotEnvPath = path.resolve(process.cwd(), fileName);\n\t\t\tinfo(`target: ${strong(dotEnvPath)}\\n`);\n\t\t\tinfo(prettyCode(dotEnv));\n\t\t\tinfo(`\\n`);\n\n\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\tfilePath: dotEnvPath,\n\t\t\t\tskip: argv.yes,\n\t\t\t});\n\n\t\t\tif (\n\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t) {\n\t\t\t\tfs.writeFileSync(dotEnvPath, dotEnv);\n\t\t\t}\n\t\t}\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n", "import { constantCase } from 'constant-case';\n\nimport { getLogger, strong } from '../../utils/logger';\nimport { flattenTree } from './flat';\nimport {\n DotSecExpandedTree,\n DotSecPlainText,\n DotSecPlaintextEncoding,\n DotSecTree,\n DotSecValue,\n isBoolean,\n isNumber,\n isRegularParameter,\n isRegularParameterObject,\n isSecretsManagerParameter,\n isSSMParameter,\n isString,\n} from './types';\n\nconst fromPlainTextLeafsToEnvEntries = (\n leafs: DotSecTree<'plaintext', 'flattened'>,\n) => {\n return Object.entries(leafs).map(([key, plainTextValue]) => {\n const parts = key.split('/');\n\n const dotEnvKeyPath = parts.map((k) => constantCase(k)).join('_');\n\n let storageValue: DotSecValue;\n if (isRegularParameter(plainTextValue)) {\n if (isRegularParameterObject(plainTextValue)) {\n storageValue = plainTextValue.value;\n } else {\n storageValue = plainTextValue;\n }\n } else if (isSSMParameter(plainTextValue)) {\n storageValue = plainTextValue.value;\n } else if (isSecretsManagerParameter(plainTextValue)) {\n storageValue = plainTextValue.value;\n } else {\n throw new Error('Invalid parameter type');\n }\n // check if parameter is string, number or boolean, if not, encode to json\n if (\n !isString(storageValue) &&\n !isNumber(storageValue) &&\n !isBoolean(storageValue)\n ) {\n storageValue = JSON.stringify(storageValue);\n }\n\n return `${dotEnvKeyPath}=${String(storageValue)}`;\n });\n};\n\nexport const toDotEnv = (options: {\n dotSecPlainText: DotSecPlainText;\n verbose?: boolean;\n searchPath?: string;\n}) => {\n const { info } = getLogger();\n const { dotSecPlainText, searchPath, verbose } = options;\n let tree = dotSecPlainText.plaintext;\n if (searchPath) {\n if (verbose) {\n info(`Searching for path: ${strong(searchPath)}`);\n }\n const pathParts = searchPath.split('/');\n for (const pathPart of pathParts) {\n // questionable cast\n tree = tree[pathPart] as DotSecTree<\n DotSecPlaintextEncoding,\n DotSecExpandedTree\n >;\n\n if (tree === undefined) {\n throw new Error(\n `Invalid search path: '${searchPath}', part: '${pathPart}' could not be found`,\n );\n }\n }\n }\n\n const flattenedTree = flattenTree(tree);\n\n return fromPlainTextLeafsToEnvEntries(flattenedTree).join('\\n');\n};\n\nexport const toDotEnvPerEnvironment = (options: {\n dotSecPlainText: DotSecPlainText;\n verbose?: boolean;\n searchPath?: string;\n}) => {\n const { info } = getLogger();\n const { dotSecPlainText, searchPath, verbose } = options;\n\n const environments = Object.keys(dotSecPlainText.plaintext);\n\n return Object.fromEntries(\n environments.map((environment) => {\n let tree = dotSecPlainText.plaintext[environment];\n if (searchPath) {\n if (verbose) {\n info(`Searching for path: ${strong(searchPath)}`);\n }\n const pathParts = searchPath.split('/');\n for (const pathPart of pathParts) {\n // questionable cast\n tree = tree[pathPart] as DotSecTree<\n DotSecPlaintextEncoding,\n DotSecExpandedTree\n >;\n\n if (tree === undefined) {\n throw new Error(\n `Invalid search path: '${searchPath}', part: '${pathPart}' could not be found`,\n );\n }\n }\n }\n return [\n environment,\n fromPlainTextLeafsToEnvEntries(flattenTree(tree)).join('\\n'),\n ];\n }),\n );\n};\n", "import fs from \"fs\";\nimport path from \"node:path\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport { decryptedEncrypted } from \"../lib/wtf/crypto\";\nimport { toDotSec, toDotSecPerEnvironment } from \"../lib/wtf/dotsec\";\nimport { getDotSecEncrypted } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { promptOverwriteIfFileExists } from \"../utils/io\";\nimport { getLogger, prettyCode, strong } from \"../utils/logger\";\n\nexport const command = \"encrypted-secrets-to-dot-sec\";\nexport const desc = `Creates .sec file from an encrypted secrets file.\nIf '--use-top-levels-as-environments' is set, it will create a .sec file for each top level key in the encrypted secrets file.`;\n\nexport const builder = {\n\t\"encrypted-secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file for writing encrypted secrets\",\n\t\tdefault: \"secrets.encrypted.json\",\n\t},\n\t\"sec-file\": commonCliOptions.secFile,\n\t\"search-path\": commonCliOptions.searchpath,\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\t\"use-top-levels-as-environments\": commonCliOptions.useTopLevelsAsEnvironments,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\n\tconst { info, error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\targv: {\n\t\t\t\t\t...argv,\n\t\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t},\n\t\t\t\tenv: { ...process.env },\n\t\t\t});\n\n\t\tconst { fileType, dotSecEncrypted } = await getDotSecEncrypted({\n\t\t\tdefaultConfig: {\n\t\t\t\tconfig: {\n\t\t\t\t\taws: {\n\t\t\t\t\t\tkeyAlias: \"alias/dotsec\",\n\t\t\t\t\t\tregions: [regionAndOrigin.value],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tverbose: argv.verbose,\n\t\t\t},\n\t\t});\n\t\tif (!dotSecEncrypted.encrypted) {\n\t\t\tthrow new Error(`Expected 'encrypted' property, but got none`);\n\t\t}\n\t\t// const dotSecEncryptedFlattened = flattenEncrypted(dotSecEncrypted);\n\t\t// const expanded = expandEncrypted(dotSecEncryptedFlattened);\n\n\t\tconst dotSecPlainText = await decryptedEncrypted({\n\t\t\tdotSecEncrypted,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias,\n\t\t\tverbose: argv.verbose,\n\t\t});\n\n\t\tif (\n\t\t\targv.useTopLevelsAsEnvironments ||\n\t\t\tdotSecEncrypted.config?.useTopLevelsAsEnvironments\n\t\t) {\n\t\t\tconst dotSecsPerEnvironment = toDotSecPerEnvironment({\n\t\t\t\tdotSecEncrypted,\n\t\t\t\tsearchPath: argv.searchPath,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t});\n\n\t\t\tfor (const [environment, dotSec] of Object.entries(\n\t\t\t\tdotSecsPerEnvironment,\n\t\t\t)) {\n\t\t\t\tconst fileName = `.sec.${environment}`;\n\t\t\t\tconst dotSecPath = path.resolve(process.cwd(), fileName);\n\n\t\t\t\tinfo(`target: ${strong(dotSecPath)}\\n`);\n\t\t\t\tinfo(prettyCode(dotSec));\n\t\t\t\tinfo(`\\n`);\n\n\t\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\tfilePath: dotSecPath,\n\t\t\t\t\tskip: argv.yes,\n\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tfs.writeFileSync(dotSecPath, dotSec);\n\t\t\t\t}\n\n\t\t\t\t// write to file, prompt if file exists\n\t\t\t}\n\t\t} else {\n\t\t\tconst dotSec = toDotSec({\n\t\t\t\tdotSecEncrypted,\n\t\t\t\tsearchPath: argv.searchPath,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t});\n\n\t\t\tconst fileName = argv.secFile || `.sec`;\n\t\t\tconst dotSecPath = path.resolve(process.cwd(), fileName);\n\n\t\t\tinfo(`target: ${strong(dotSecPath)}\\n`);\n\t\t\tinfo(prettyCode(dotSec));\n\t\t\tinfo(`\\n`);\n\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\tfilePath: dotSecPath,\n\t\t\t\tskip: argv.yes,\n\t\t\t});\n\n\t\t\tif (\n\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t) {\n\t\t\t\tfs.writeFileSync(dotSecPath, dotSec);\n\t\t\t}\n\t\t}\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n", "import { constantCase } from 'constant-case';\n\nimport { getLogger, strong } from '../../utils/logger';\nimport { flattenTree } from './flat';\nimport {\n DotSecEncrypted,\n DotSecEncryptedEncoding,\n DotSecExpandedTree,\n DotSecTree,\n isEncryptedRegularParameter,\n isEncryptedSSMParameter,\n isSecretsManagerParameter,\n} from './types';\n\nconst fromEncryptedLeafsToEnvEntries = (\n leafs: DotSecTree<'encrypted', 'flattened'>,\n) => {\n return Object.entries(leafs).map(([key, plainTextValue]) => {\n const parts = key.split('/');\n\n const dotEnvKeyPath = parts.map((k) => constantCase(k)).join('_');\n\n let storageValue: string;\n if (isEncryptedRegularParameter(plainTextValue)) {\n storageValue = plainTextValue.encryptedValue;\n } else if (isEncryptedSSMParameter(plainTextValue)) {\n storageValue = plainTextValue.encryptedValue;\n } else if (isSecretsManagerParameter(plainTextValue)) {\n storageValue = plainTextValue.encryptedValue;\n } else {\n throw new Error('Invalid parameter type');\n }\n\n return `${dotEnvKeyPath}=${String(storageValue)}`;\n });\n};\n\nexport const toDotSec = (options: {\n dotSecEncrypted: DotSecEncrypted;\n verbose?: boolean;\n searchPath?: string;\n}) => {\n const { info } = getLogger();\n const { dotSecEncrypted, searchPath, verbose } = options;\n\n let tree = dotSecEncrypted.encrypted;\n if (searchPath) {\n if (verbose) {\n info(`Searching for path: ${strong(searchPath)}`);\n }\n const pathParts = searchPath.split('/');\n for (const pathPart of pathParts) {\n // questionable cast\n tree = tree[pathPart] as DotSecTree<\n DotSecEncryptedEncoding,\n DotSecExpandedTree\n >;\n }\n }\n\n const flattenedTree = flattenTree(tree);\n\n return fromEncryptedLeafsToEnvEntries(flattenedTree).join('\\n');\n};\n\nexport const toDotSecPerEnvironment = (options: {\n dotSecEncrypted: DotSecEncrypted;\n verbose?: boolean;\n searchPath?: string;\n}) => {\n const { info } = getLogger();\n\n const { dotSecEncrypted, searchPath, verbose } = options;\n\n const environments = Object.keys(dotSecEncrypted.encrypted);\n\n return Object.fromEntries(\n environments.map((environment) => {\n let tree = dotSecEncrypted.encrypted[environment];\n if (searchPath) {\n if (verbose) {\n info(`Searching for path: ${strong(searchPath)}`);\n }\n const pathParts = searchPath.split('/');\n for (const pathPart of pathParts) {\n // questionable cast\n tree = tree[pathPart] as DotSecTree<\n DotSecEncryptedEncoding,\n DotSecExpandedTree\n >;\n }\n }\n\n return [\n environment,\n fromEncryptedLeafsToEnvEntries(flattenTree(tree)).join('\\n'),\n ];\n }),\n );\n};\n", "import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport YAML from \"yaml\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport { decryptedEncrypted } from \"../lib/wtf/crypto\";\nimport { getDotSecEncrypted } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { promptOverwriteIfFileExists } from \"../utils/io\";\nimport { getLogger, prettyCode, strong } from \"../utils/logger\";\nexport const command = \"encrypted-secrets-to-plaintext-secrets\";\nexport const desc =\n\t\"Decrypts an encrypted file and stores the result in a plaintext file\";\n\nexport const builder = {\n\t\"secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file reading secrets\",\n\t\tdefault: \"secrets.json\",\n\t},\n\t\"encrypted-secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file for writing encrypted secrets\",\n\t\tdefault: \"secrets.encrypted.json\",\n\t},\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\n\tconst { info, error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\targv: {\n\t\t\t\t\t...argv,\n\t\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t},\n\t\t\t\tenv: { ...process.env },\n\t\t\t});\n\n\t\tconst { fileType, dotSecEncrypted } = await getDotSecEncrypted({\n\t\t\tdefaultConfig: {\n\t\t\t\tconfig: {\n\t\t\t\t\taws: {\n\t\t\t\t\t\tkeyAlias: \"alias/dotsec\",\n\t\t\t\t\t\tregions: [regionAndOrigin.value],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\toptions: {},\n\t\t});\n\t\tif (!dotSecEncrypted.encrypted) {\n\t\t\tthrow new Error(`Expected 'encrypted' property, but got none`);\n\t\t}\n\t\t// const dotSecEncryptedFlattened = flattenEncrypted(dotSecEncrypted);\n\t\t// const expanded = expandEncrypted(dotSecEncryptedFlattened);\n\n\t\tconst dotSecPlainText = await decryptedEncrypted({\n\t\t\tdotSecEncrypted,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias,\n\t\t\tverbose: argv.verbose,\n\t\t});\n\n\t\tif (argv.secretsFile) {\n\t\t\t// let's inspect this one first\n\t\t\tconst secretsFileExtension = path.extname(argv.secretsFile).substring(1);\n\t\t}\n\n\t\tconst secretsPath = path.resolve(\n\t\t\tprocess.cwd(),\n\t\t\tpath.parse(argv.secretsFile || `secrets.json`).name + \".\" + fileType,\n\t\t);\n\n\t\tconsole.log(\n\t\t\t\"secretsPath\",\n\t\t\tfileType,\n\t\t\tpath.parse(argv.secretsFile || `secrets.json`).name,\n\t\t);\n\t\tconst converted =\n\t\t\tfileType === \"yaml\" || fileType === \"yml\"\n\t\t\t\t? YAML.stringify(dotSecPlainText)\n\t\t\t\t: JSON.stringify(dotSecPlainText, null, 2);\n\n\t\tinfo(`target: ${strong(secretsPath)}\\n`);\n\t\tinfo(prettyCode(converted));\n\t\tinfo(`\\n`);\n\n\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\tfilePath: secretsPath,\n\t\t\tskip: argv.yes,\n\t\t});\n\n\t\tif (\n\t\t\toverwriteResponse === undefined ||\n\t\t\toverwriteResponse.overwrite === true\n\t\t) {\n\t\t\tfs.writeFileSync(secretsPath, converted);\n\t\t}\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n", "import prompts from \"prompts\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport {\n\tdecryptedEncrypted,\n\tprettyPrintTasks,\n\tcreateStorePlaintextTasks,\n\texecuteStorePlainTextTasks,\n} from \"../lib/wtf/crypto\";\nimport { getDotSecEncrypted } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { getLogger } from \"../utils/logger\";\nexport const command = \"offload-plaintext-secrets\";\nexport const desc =\n\t\"Decrypts and pushes secret values to AWS SSM and SecretsManager\";\n\nexport const builder = {\n\t\"encrypted-secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file for writing encrypted secrets\",\n\t\tdefault: \"secrets.encrypted.json\",\n\t},\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\n\tconst { info, error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\targv: {\n\t\t\t\t\t...argv,\n\t\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t},\n\t\t\t\tenv: { ...process.env },\n\t\t\t});\n\n\t\tconst { fileType, dotSecEncrypted } = await getDotSecEncrypted({\n\t\t\tdefaultConfig: {\n\t\t\t\tconfig: {\n\t\t\t\t\taws: {\n\t\t\t\t\t\tkeyAlias: \"alias/dotsec\",\n\t\t\t\t\t\tregions: [regionAndOrigin.value],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\toptions: {},\n\t\t});\n\t\tif (!dotSecEncrypted.encrypted) {\n\t\t\tthrow new Error(`Expected 'encrypted' property, but got none`);\n\t\t}\n\t\t// const dotSecEncryptedFlattened = flattenEncrypted(dotSecEncrypted);\n\t\t// const expanded = expandEncrypted(dotSecEncryptedFlattened);\n\n\t\tconst dotSecPlainText = await decryptedEncrypted({\n\t\t\tdotSecEncrypted,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias,\n\t\t\tverbose: argv.verbose,\n\t\t});\n\t\tconst tasks = await createStorePlaintextTasks({\n\t\t\tdotSecPlainText,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias,\n\t\t\tverbose: argv.verbose,\n\t\t});\n\t\tif (tasks.total > 0) {\n\t\t\tprettyPrintTasks(tasks);\n\t\t\tlet proceed = argv.yes === true;\n\t\t\tif (proceed === false) {\n\t\t\t\tproceed = await prompts({\n\t\t\t\t\ttype: \"confirm\",\n\t\t\t\t\tname: \"proceed\",\n\t\t\t\t\tmessage: () => {\n\t\t\t\t\t\treturn `Proceed ?`;\n\t\t\t\t\t},\n\t\t\t\t}).then((r) => r.proceed as boolean);\n\t\t\t}\n\n\t\t\tif (proceed) {\n\t\t\t\tawait executeStorePlainTextTasks({\n\t\t\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\t\t\tregion: regionAndOrigin.value,\n\t\t\t\t\tverbose: argv.verbose,\n\t\t\t\t\ttasks,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tinfo(\"Nothing to do\");\n\t\t}\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n", "import fs from \"fs\";\nimport path from \"node:path\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport { toDotEnv, toDotEnvPerEnvironment } from \"../lib/wtf/dotenv\";\nimport { getDotSecPlainText } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { promptOverwriteIfFileExists } from \"../utils/io\";\nimport { emphasis, getLogger, prettyCode, strong } from \"../utils/logger\";\n\nexport const command = \"plaintext-secrets-to-dot-env\";\nexport const desc = `Creates .env file from a secrets file.\nIf '--use-top-levels-as-environments' is set, it will create a .env file for each top level key in the secrets file.`;\n\nexport const builder = {\n\t\"secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file reading secrets\",\n\t\tdefault: \"secrets.json\",\n\t},\n\t\"env-file\": commonCliOptions.envFile,\n\t\"search-path\": commonCliOptions.searchpath,\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\t\"use-top-levels-as-environments\": commonCliOptions.useTopLevelsAsEnvironments,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n\t\"dry-run\": commonCliOptions.dryRun,\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\tconst { info, error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { regionAndOrigin } = await handleCredentialsAndRegion({\n\t\t\targv: {\n\t\t\t\t...argv,\n\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t},\n\t\t\tenv: { ...process.env },\n\t\t});\n\n\t\tconst { dotSecPlainText } = await getDotSecPlainText({\n\t\t\tdefaultConfig: {\n\t\t\t\tconfig: {\n\t\t\t\t\taws: {\n\t\t\t\t\t\tkeyAlias: \"alias/dotsec\",\n\t\t\t\t\t\tregions: [regionAndOrigin.value],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tfilename: argv.secretsFile,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t},\n\t\t});\n\t\tif (!dotSecPlainText.plaintext) {\n\t\t\tthrow new Error(`Expected 'encrypted' property, but got none`);\n\t\t}\n\n\t\tif (\n\t\t\targv.useTopLevelsAsEnvironments ||\n\t\t\tdotSecPlainText.config?.useTopLevelsAsEnvironments\n\t\t) {\n\t\t\tconst dotEnvsPerEnvironment = toDotEnvPerEnvironment({\n\t\t\t\tdotSecPlainText,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t});\n\n\t\t\tfor (const [environment, dotEnv] of Object.entries(\n\t\t\t\tdotEnvsPerEnvironment,\n\t\t\t)) {\n\t\t\t\tconst fileName = `.env.${environment}`;\n\t\t\t\tconst dotEnvPath = path.resolve(process.cwd(), fileName);\n\t\t\t\tif (argv.dryRun) {\n\t\t\t\t\t// output filename, path and content\n\t\t\t\t\tinfo(strong(`// ${dotEnvPath}`));\n\t\t\t\t\tinfo(emphasis(dotEnv));\n\t\t\t\t} else {\n\t\t\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\t\tfilePath: dotEnvPath,\n\t\t\t\t\t\tskip: argv.yes,\n\t\t\t\t\t});\n\n\t\t\t\t\tif (\n\t\t\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t\t\t) {\n\t\t\t\t\t\tfs.writeFileSync(dotEnvPath, dotEnv);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// write to file, prompt if file exists\n\t\t\t}\n\t\t} else {\n\t\t\tconst dotEnv = toDotEnv({\n\t\t\t\tdotSecPlainText,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t\tsearchPath: argv.searchPath,\n\t\t\t});\n\n\t\t\tconst fileName = argv.envFile || `.env`;\n\t\t\tconst dotEnvPath = path.resolve(process.cwd(), fileName);\n\t\t\tinfo(`target: ${strong(dotEnvPath)}\\n`);\n\t\t\tinfo(prettyCode(dotEnv));\n\t\t\tinfo(`\\n`);\n\n\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\tfilePath: dotEnvPath,\n\t\t\t\tskip: argv.yes,\n\t\t\t});\n\n\t\t\tif (\n\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t) {\n\t\t\t\tfs.writeFileSync(dotEnvPath, dotEnv);\n\t\t\t}\n\t\t}\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n", "import fs from \"fs\";\nimport path from \"node:path\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport { encryptPlainText } from \"../lib/wtf/crypto\";\nimport { toDotSec, toDotSecPerEnvironment } from \"../lib/wtf/dotsec\";\nimport { getDotSecPlainText } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { promptOverwriteIfFileExists } from \"../utils/io\";\nimport { getLogger, prettyCode, strong } from \"../utils/logger\";\n\nexport const command = \"plaintext-secrets-to-dot-sec\";\nexport const desc = `Creates .sec file from an secrets file.\nIf '--use-top-levels-as-environments' is set, it will create a .sec file for each top level key in the ecrets file.`;\n\nexport const builder = {\n\t\"secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file reading secrets\",\n\t},\n\t\"sec-file\": commonCliOptions.secFile,\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\t\"use-top-levels-as-environments\": commonCliOptions.useTopLevelsAsEnvironments,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\tconst { info, error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\targv: {\n\t\t\t\t\t...argv,\n\t\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t},\n\t\t\t\tenv: { ...process.env },\n\t\t\t});\n\n\t\tconst { fileType, dotSecPlainText } = await getDotSecPlainText({\n\t\t\tdefaultConfig: {\n\t\t\t\tconfig: {\n\t\t\t\t\taws: {\n\t\t\t\t\t\tkeyAlias: \"alias/dotsec\",\n\t\t\t\t\t\tregions: [regionAndOrigin.value],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tfilename: argv.secretsFile,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t},\n\t\t});\n\n\t\tconsole.log(\"dotSecPlainText\", dotSecPlainText);\n\n\t\tconst dotSecEncrypted = await encryptPlainText({\n\t\t\tdotSecPlainText,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias,\n\t\t\tverbose: argv.verbose,\n\t\t});\n\t\tif (!dotSecPlainText.plaintext) {\n\t\t\tthrow new Error(`Expected 'encrypted' property, but got none`);\n\t\t}\n\t\tif (!dotSecEncrypted.encrypted) {\n\t\t\tthrow new Error(`Expected 'encrypted' property, but got none`);\n\t\t}\n\t\t// const dotSecEncryptedFlattened = flattenEncrypted(dotSecEncrypted);\n\t\t// const expanded = expandEncrypted(dotSecEncryptedFlattened);\n\n\t\tif (\n\t\t\targv.useTopLevelsAsEnvironments ||\n\t\t\tdotSecPlainText.config?.useTopLevelsAsEnvironments\n\t\t) {\n\t\t\tconst dotSecsPerEnvironment = toDotSecPerEnvironment({\n\t\t\t\tdotSecEncrypted,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t});\n\n\t\t\tfor (const [environment, dotSec] of Object.entries(\n\t\t\t\tdotSecsPerEnvironment,\n\t\t\t)) {\n\t\t\t\tconst fileName = `.sec.${environment}`;\n\t\t\t\tconst dotSecPath = path.resolve(process.cwd(), fileName);\n\t\t\t\tinfo(`target: ${strong(dotSecPath)}\\n`);\n\t\t\t\tinfo(prettyCode(dotSec));\n\t\t\t\tinfo(`\\n`);\n\t\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\t\tfilePath: dotSecPath,\n\t\t\t\t\tskip: argv.yes,\n\t\t\t\t});\n\n\t\t\t\tif (\n\t\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t\t) {\n\t\t\t\t\tfs.writeFileSync(dotSecPath, dotSec);\n\t\t\t\t}\n\n\t\t\t\t// write to file, prompt if file exists\n\t\t\t}\n\t\t} else {\n\t\t\tconst dotSec = toDotSec({\n\t\t\t\tdotSecEncrypted,\n\t\t\t\tverbose: argv.verbose,\n\t\t\t});\n\n\t\t\tconst fileName = argv.secFile || `.sec`;\n\t\t\tconst dotSecPath = path.resolve(process.cwd(), fileName);\n\t\t\tinfo(`target: ${strong(dotSecPath)}\\n`);\n\t\t\tinfo(prettyCode(dotSec));\n\t\t\tinfo(`\\n`);\n\t\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\t\tfilePath: dotSecPath,\n\t\t\t\tskip: argv.yes,\n\t\t\t});\n\n\t\t\tif (\n\t\t\t\toverwriteResponse === undefined ||\n\t\t\t\toverwriteResponse.overwrite === true\n\t\t\t) {\n\t\t\t\tfs.writeFileSync(dotSecPath, dotSec);\n\t\t\t}\n\t\t}\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n", "import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport YAML from \"yaml\";\n\nimport { commonCliOptions } from \"../commonCliOptions\";\nimport { getConfig } from \"../lib/config-old\";\nimport { handleCredentialsAndRegion } from \"../lib/partial-commands/handleCredentialsAndRegion\";\nimport { encryptPlainText } from \"../lib/wtf/crypto\";\nimport { getDotSecPlainText } from \"../lib/wtf/io\";\nimport { YargsHandlerParams } from \"../types\";\nimport { promptOverwriteIfFileExists } from \"../utils/io\";\nimport { getLogger, prettyCode, strong } from \"../utils/logger\";\n\nexport const command = \"plaintext-secrets-to-encrypted-secrets\";\nexport const desc = \"Encrypts an unencrypted secretsfile\";\n\nexport const builder = {\n\t\"secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file reading secrets\",\n\t},\n\t\"encrypted-secrets-file\": {\n\t\tstring: true,\n\t\tdescribe: \"filename of json file for writing encrypted secrets\",\n\t\tdefault: \"secrets.encrypted.json\",\n\t},\n\t\"aws-profile\": commonCliOptions.awsProfile,\n\t\"aws-region\": commonCliOptions.awsRegion,\n\t\"aws-key-alias\": commonCliOptions.awsKeyAlias,\n\t\"aws-assume-role-arn\": commonCliOptions.awsAssumeRoleArn,\n\t\"aws-assume-role-session-duration\":\n\t\tcommonCliOptions.awsAssumeRoleSessionDuration,\n\tverbose: commonCliOptions.verbose,\n\tyes: { ...commonCliOptions.yes },\n} as const;\n\nexport const handler = async (\n\targv: YargsHandlerParams<typeof builder>,\n): Promise<void> => {\n\tconst config = await getConfig();\n\n\tconst { info, error } = getLogger();\n\ttry {\n\t\tconst defaultRegion = config.aws.region || argv.awsRegion;\n\t\tconst { credentialsAndOrigin, regionAndOrigin } =\n\t\t\tawait handleCredentialsAndRegion({\n\t\t\t\targv: {\n\t\t\t\t\t...argv,\n\t\t\t\t\tawsRegion: defaultRegion,\n\t\t\t\t\tawsProfile: config.aws.profile || argv.awsProfile,\n\t\t\t\t\tawsAssumeRoleArn: config.aws.assumeRoleArn || argv.awsAssumeRoleArn,\n\t\t\t\t\tawsAssumeRoleSessionDuration:\n\t\t\t\t\t\tconfig.aws.assumeRoleSessionDuration ||\n\t\t\t\t\t\targv.awsAssumeRoleSessionDuration,\n\t\t\t\t},\n\t\t\t\tenv: { ...process.env },\n\t\t\t});\n\n\t\tconst { fileType, dotSecPlainText } = await getDotSecPlainText({\n\t\t\tdefaultConfig: {\n\t\t\t\tconfig: {\n\t\t\t\t\taws: {\n\t\t\t\t\t\tkeyAlias: \"alias/dotsec\",\n\t\t\t\t\t\tregions: [regionAndOrigin.value],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tfilename: argv.secretsFile,\n\t\t\t},\n\t\t});\n\t\tif (!dotSecPlainText.plaintext) {\n\t\t\tthrow new Error(`Expected 'plaintext' property, but got none`);\n\t\t}\n\n\t\tconst dotSecEncrypted = await encryptPlainText({\n\t\t\tdotSecPlainText,\n\t\t\tcredentials: credentialsAndOrigin.value,\n\t\t\tregion: regionAndOrigin.value,\n\t\t\tkeyAlias: argv.awsKeyAlias,\n\t\t\tverbose: argv.verbose,\n\t\t});\n\n\t\tconst encryptedSecretsPath = path.resolve(\n\t\t\tprocess.cwd(),\n\t\t\tpath.parse(argv.encryptedSecretsFile || `secrets.encrypted.json`).name +\n\t\t\t\t\".\" +\n\t\t\t\tfileType,\n\t\t);\n\t\tconst converted =\n\t\t\tfileType === \"yaml\" || fileType === \"yml\"\n\t\t\t\t? YAML.stringify(dotSecEncrypted)\n\t\t\t\t: JSON.stringify(dotSecEncrypted, null, 2);\n\n\t\tinfo(`target: ${strong(encryptedSecretsPath)}\\n`);\n\t\tinfo(prettyCode(converted));\n\t\tinfo(`\\n`);\n\t\tconst overwriteResponse = await promptOverwriteIfFileExists({\n\t\t\tfilePath: encryptedSecretsPath,\n\t\t\tskip: argv.yes,\n\t\t});\n\t\t// easy peasy, write json\n\n\t\tif (\n\t\t\toverwriteResponse === undefined ||\n\t\t\toverwriteResponse.overwrite === true\n\t\t) {\n\t\t\tfs.writeFileSync(encryptedSecretsPath, converted);\n\t\t}\n\t} catch (e) {\n\t\terror(e);\n\t}\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AACA;;;ACAO,IAAM,mBAAmB;AAAA,EAC5B,YAAY;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA;AAAA,EAEd,WAAW;AAAA,IACP,QAAQ;AAAA,IACR,UAAU;AAAA;AAAA,EAEd,aAAa;AAAA,IACT,QAAQ;AAAA,IACR,UAAU;AAAA;AAAA,EAEd,WAAW;AAAA,IACP,QAAQ;AAAA,IACR,UAAU;AAAA;AAAA,EAEd,QAAQ;AAAA,IACJ,QAAQ;AAAA,IACR,UAAU;AAAA;AAAA,EAEd,SAAS;AAAA,IACL,QAAQ;AAAA,IACR,UAAU;AAAA;AAAA,EAEd,sBAAsB;AAAA,IAClB,SAAS;AAAA,IACT,UAAU;AAAA;AAAA,EAEd,SAA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