@mtndev/cli 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/cjs/__chunks/VH7oDXx4.cjs +28 -0
- package/cjs/commands/aws/ec2/allow-ip/handler.cjs +261 -12
- package/cjs/commands/aws/ec2/allow-ip/index.cjs +25 -55
- package/cjs/commands/aws/ec2/allow-ip/schema.cjs +33 -13
- package/cjs/commands/aws/ec2/allow-ip/utils.cjs +379 -39
- package/cjs/commands/aws/iam/admin-group.cjs +111 -15
- package/cjs/commands/aws/iam/break-glass/handler.cjs +127 -12
- package/cjs/commands/aws/iam/break-glass/index.cjs +7 -19
- package/cjs/commands/aws/iam/break-glass/schema.cjs +21 -12
- package/cjs/commands/aws/iam/check-admin/handler.cjs +89 -10
- package/cjs/commands/aws/iam/check-admin/index.cjs +7 -17
- package/cjs/commands/aws/iam/check-admin/schema.cjs +19 -12
- package/cjs/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.json +20 -0
- package/cjs/commands/aws/iam/policies/sts-federation.json +11 -0
- package/cjs/commands/aws/iam/policies/user-admins-deny-list.json +175 -0
- package/cjs/commands/aws/iam/policies/user-admins-deny-regions-list.json +41 -0
- package/cjs/commands/aws/iam/policies/user-admins-self-service-iam.json +56 -0
- package/cjs/commands/aws/iam/policies/user-admins-write-list.json +117 -0
- package/cjs/commands/aws/iam/remove-admin/handler.cjs +120 -11
- package/cjs/commands/aws/iam/remove-admin/index.cjs +7 -18
- package/cjs/commands/aws/iam/remove-admin/schema.cjs +22 -12
- package/cjs/commands/aws/iam/setup-acl/handler.cjs +227 -14
- package/cjs/commands/aws/iam/setup-acl/index.cjs +13 -33
- package/cjs/commands/aws/iam/setup-acl/schema.cjs +19 -7
- package/cjs/commands/aws/iam/setup-acl/utils.cjs +305 -20
- package/cjs/commands/aws/iam/users/handler.cjs +59 -12
- package/cjs/commands/aws/iam/users/index.cjs +18 -41
- package/cjs/commands/aws/iam/users/schema.cjs +17 -7
- package/cjs/commands/aws/iam/users/utils.cjs +454 -30
- package/cjs/commands/aws/index.cjs +223 -229
- package/cjs/commands/aws/route53/add-record/handler.cjs +264 -18
- package/cjs/commands/aws/route53/add-record/index.cjs +26 -57
- package/cjs/commands/aws/route53/add-record/schema.cjs +43 -11
- package/cjs/commands/aws/route53/add-record/utils.cjs +404 -37
- package/cjs/commands/aws/route53/remove-record/handler.cjs +114 -14
- package/cjs/commands/aws/route53/remove-record/index.cjs +5 -18
- package/cjs/commands/aws/route53/remove-record/schema.cjs +22 -8
- package/cjs/commands/aws/schema.cjs +19 -10
- package/cjs/commands/aws/ses/send-email/handler.cjs +73 -12
- package/cjs/commands/aws/ses/send-email/index.cjs +9 -23
- package/cjs/commands/aws/ses/send-email/schema.cjs +24 -7
- package/cjs/commands/aws/ses/send-email/utils.cjs +87 -11
- package/cjs/commands/aws/ses/smtp-password.cjs +72 -10
- package/cjs/commands/aws/utils/exec-aws.cjs +145 -16
- package/cjs/commands/aws/utils/resolve-policy-path.cjs +15 -6
- package/cjs/commands/aws/utils/resolve-profile.cjs +93 -11
- package/cjs/commands/aws/utils/tty.cjs +54 -10
- package/cjs/commands/db/create-readonly-user/handler.cjs +254 -11
- package/cjs/commands/db/create-readonly-user/index.cjs +18 -40
- package/cjs/commands/db/create-readonly-user/mysql.cjs +102 -9
- package/cjs/commands/db/create-readonly-user/postgres.cjs +209 -9
- package/cjs/commands/db/create-readonly-user/schema.cjs +39 -12
- package/cjs/commands/db/create-readonly-user/utils.cjs +160 -22
- package/cjs/commands/db/index.cjs +46 -44
- package/cjs/commands/doppler/handler.cjs +95 -11
- package/cjs/commands/doppler/index.cjs +33 -68
- package/cjs/commands/doppler/schema.cjs +130 -14
- package/cjs/commands/doppler/set-secret.cjs +378 -19
- package/cjs/commands/doppler/utils/exec.cjs +106 -12
- package/cjs/commands/doppler/utils.cjs +412 -34
- package/cjs/commands/icons/handler.cjs +82 -8
- package/cjs/commands/icons/index.cjs +15 -31
- package/cjs/commands/icons/schema.cjs +101 -13
- package/cjs/commands/icons/utils.cjs +131 -13
- package/cjs/commands/index.cjs +54 -161
- package/cjs/commands/schema.cjs +25 -8
- package/cjs/index.cjs +3 -4
- package/esm/commands/aws/ec2/allow-ip/handler.js +258 -12
- package/esm/commands/aws/ec2/allow-ip/index.js +4 -55
- package/esm/commands/aws/ec2/allow-ip/schema.js +29 -13
- package/esm/commands/aws/ec2/allow-ip/utils.js +363 -39
- package/esm/commands/aws/iam/admin-group.js +104 -15
- package/esm/commands/aws/iam/break-glass/handler.js +124 -12
- package/esm/commands/aws/iam/break-glass/index.js +4 -19
- package/esm/commands/aws/iam/break-glass/schema.js +19 -12
- package/esm/commands/aws/iam/check-admin/handler.js +86 -10
- package/esm/commands/aws/iam/check-admin/index.js +4 -17
- package/esm/commands/aws/iam/check-admin/schema.js +17 -12
- package/esm/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.json +20 -0
- package/esm/commands/aws/iam/policies/sts-federation.json +11 -0
- package/esm/commands/aws/iam/policies/user-admins-deny-list.json +175 -0
- package/esm/commands/aws/iam/policies/user-admins-deny-regions-list.json +41 -0
- package/esm/commands/aws/iam/policies/user-admins-self-service-iam.json +56 -0
- package/esm/commands/aws/iam/policies/user-admins-write-list.json +117 -0
- package/esm/commands/aws/iam/remove-admin/handler.js +117 -11
- package/esm/commands/aws/iam/remove-admin/index.js +4 -18
- package/esm/commands/aws/iam/remove-admin/schema.js +20 -12
- package/esm/commands/aws/iam/setup-acl/handler.js +224 -14
- package/esm/commands/aws/iam/setup-acl/index.js +4 -33
- package/esm/commands/aws/iam/setup-acl/schema.js +18 -7
- package/esm/commands/aws/iam/setup-acl/utils.js +298 -20
- package/esm/commands/aws/iam/users/handler.js +56 -12
- package/esm/commands/aws/iam/users/index.js +4 -41
- package/esm/commands/aws/iam/users/schema.js +16 -7
- package/esm/commands/aws/iam/users/utils.js +440 -30
- package/esm/commands/aws/index.js +142 -229
- package/esm/commands/aws/route53/add-record/handler.js +258 -18
- package/esm/commands/aws/route53/add-record/index.js +4 -57
- package/esm/commands/aws/route53/add-record/schema.js +40 -11
- package/esm/commands/aws/route53/add-record/utils.js +389 -37
- package/esm/commands/aws/route53/remove-record/handler.js +111 -14
- package/esm/commands/aws/route53/remove-record/index.js +3 -18
- package/esm/commands/aws/route53/remove-record/schema.js +21 -8
- package/esm/commands/aws/schema.js +16 -10
- package/esm/commands/aws/ses/send-email/handler.js +70 -12
- package/esm/commands/aws/ses/send-email/index.js +4 -23
- package/esm/commands/aws/ses/send-email/schema.js +23 -7
- package/esm/commands/aws/ses/send-email/utils.js +84 -11
- package/esm/commands/aws/ses/smtp-password.js +69 -10
- package/esm/commands/aws/utils/exec-aws.js +136 -15
- package/esm/commands/aws/utils/resolve-policy-path.js +14 -6
- package/esm/commands/aws/utils/resolve-profile.js +88 -11
- package/esm/commands/aws/utils/tty.js +51 -10
- package/esm/commands/db/create-readonly-user/handler.js +251 -11
- package/esm/commands/db/create-readonly-user/index.js +4 -40
- package/esm/commands/db/create-readonly-user/mysql.js +98 -9
- package/esm/commands/db/create-readonly-user/postgres.js +205 -9
- package/esm/commands/db/create-readonly-user/schema.js +35 -12
- package/esm/commands/db/create-readonly-user/utils.js +151 -22
- package/esm/commands/db/index.js +31 -44
- package/esm/commands/doppler/handler.js +92 -11
- package/esm/commands/doppler/index.js +6 -68
- package/esm/commands/doppler/schema.js +125 -15
- package/esm/commands/doppler/set-secret.js +370 -19
- package/esm/commands/doppler/utils/exec.js +100 -12
- package/esm/commands/doppler/utils.js +396 -34
- package/esm/commands/icons/handler.js +79 -8
- package/esm/commands/icons/index.js +4 -31
- package/esm/commands/icons/schema.js +97 -15
- package/esm/commands/icons/utils.js +125 -13
- package/esm/commands/index.js +47 -155
- package/esm/commands/schema.js +22 -7
- package/esm/index.js +3 -4
- package/package.json +5 -2
- package/vitest.config.ts +11 -0
- package/cjs/__chunks/2FSYDFUV.cjs +0 -146
- package/cjs/__chunks/3A5ZYU5M.cjs +0 -105
- package/cjs/__chunks/3BY5Y4W7.cjs +0 -1
- package/cjs/__chunks/3NOHGUCF.cjs +0 -9
- package/cjs/__chunks/3T2LXW7J.cjs +0 -387
- package/cjs/__chunks/4SFWHCB3.cjs +0 -133
- package/cjs/__chunks/4XT5JEAS.cjs +0 -1
- package/cjs/__chunks/AZEB4H4I.cjs +0 -208
- package/cjs/__chunks/B2KFW7T7.cjs +0 -1
- package/cjs/__chunks/B5ENMOCD.cjs +0 -288
- package/cjs/__chunks/B6XM5KSF.cjs +0 -338
- package/cjs/__chunks/BDU2UCE5.cjs +0 -1
- package/cjs/__chunks/BLMSMR5E.cjs +0 -46
- package/cjs/__chunks/CMUD7LLN.cjs +0 -47
- package/cjs/__chunks/DTQ2LB3I.cjs +0 -49
- package/cjs/__chunks/FM5MVRQF.cjs +0 -23
- package/cjs/__chunks/FRHST54J.cjs +0 -135
- package/cjs/__chunks/FU4VP2LN.cjs +0 -1
- package/cjs/__chunks/G5K4PVIL.cjs +0 -26
- package/cjs/__chunks/GU3R54MK.cjs +0 -127
- package/cjs/__chunks/GUL36IFZ.cjs +0 -61
- package/cjs/__chunks/GZMTNK5N.cjs +0 -1
- package/cjs/__chunks/H74JSDBU.cjs +0 -30
- package/cjs/__chunks/INFOPAHN.cjs +0 -117
- package/cjs/__chunks/J36P6UNE.cjs +0 -75
- package/cjs/__chunks/JB7T7PKQ.cjs +0 -538
- package/cjs/__chunks/JSL2JDMW.cjs +0 -1
- package/cjs/__chunks/K4QNHRTP.cjs +0 -163
- package/cjs/__chunks/KU76LC42.cjs +0 -192
- package/cjs/__chunks/LFDSHANP.cjs +0 -34
- package/cjs/__chunks/LHE24ECK.cjs +0 -192
- package/cjs/__chunks/LIKQ3SI4.cjs +0 -1
- package/cjs/__chunks/LXDF5QVZ.cjs +0 -313
- package/cjs/__chunks/LXOOJR2R.cjs +0 -74
- package/cjs/__chunks/N5MXFOQZ.cjs +0 -167
- package/cjs/__chunks/N7D56LPP.cjs +0 -25
- package/cjs/__chunks/NFXQNOQH.cjs +0 -393
- package/cjs/__chunks/NIMXXHJQ.cjs +0 -92
- package/cjs/__chunks/NLKJIUEX.cjs +0 -126
- package/cjs/__chunks/NT2XXAI6.cjs +0 -89
- package/cjs/__chunks/NWZGFHKH.cjs +0 -121
- package/cjs/__chunks/R3GUC7O7.cjs +0 -110
- package/cjs/__chunks/RPVAXPJ4.cjs +0 -1
- package/cjs/__chunks/S3LVCWPN.cjs +0 -23
- package/cjs/__chunks/SBBNW2BF.cjs +0 -249
- package/cjs/__chunks/T2A7TN4F.cjs +0 -81
- package/cjs/__chunks/TKNNDDIB.cjs +0 -97
- package/cjs/__chunks/TNSRDJPR.cjs +0 -1
- package/cjs/__chunks/UWHPE2GI.cjs +0 -20
- package/cjs/__chunks/W6K7BV74.cjs +0 -1
- package/cjs/__chunks/WBOQ6AUN.cjs +0 -320
- package/cjs/__chunks/WHGN5PZI.cjs +0 -299
- package/cjs/__chunks/WOYF2L6T.cjs +0 -11
- package/cjs/__chunks/X26XY2N6.cjs +0 -18
- package/cjs/__chunks/XMKOKRXZ.cjs +0 -16
- package/cjs/__chunks/XTJPQ3EX.cjs +0 -1
- package/cjs/__chunks/YRHFKTW2.cjs +0 -63
- package/cjs/__chunks/ZMDIOZPT.cjs +0 -22
- package/cjs/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.cjs +0 -28
- package/cjs/commands/aws/iam/policies/sts-federation.cjs +0 -19
- package/cjs/commands/aws/iam/policies/user-admins-deny-list.cjs +0 -183
- package/cjs/commands/aws/iam/policies/user-admins-deny-regions-list.cjs +0 -49
- package/cjs/commands/aws/iam/policies/user-admins-self-service-iam.cjs +0 -64
- package/cjs/commands/aws/iam/policies/user-admins-write-list.cjs +0 -125
- package/esm/__chunks/2FTTEFEK.js +0 -97
- package/esm/__chunks/33UYMUQD.js +0 -338
- package/esm/__chunks/3BKWTHLJ.js +0 -25
- package/esm/__chunks/3HE4BEJX.js +0 -105
- package/esm/__chunks/3QLI5BDL.js +0 -387
- package/esm/__chunks/5GIUAFXL.js +0 -89
- package/esm/__chunks/5ZBVGSOK.js +0 -0
- package/esm/__chunks/6G4PXXKF.js +0 -75
- package/esm/__chunks/73BJG53F.js +0 -11
- package/esm/__chunks/7VF4Q43Q.js +0 -0
- package/esm/__chunks/AEDEAYF5.js +0 -0
- package/esm/__chunks/AZCP3SFJ.js +0 -0
- package/esm/__chunks/B2DVQ2UL.js +0 -61
- package/esm/__chunks/CVQVHLW5.js +0 -0
- package/esm/__chunks/D62SPZXC.js +0 -0
- package/esm/__chunks/DLEJ25GZ.js +0 -121
- package/esm/__chunks/DMYFNF54.js +0 -192
- package/esm/__chunks/DNFTUMGD.js +0 -23
- package/esm/__chunks/DVKD6YSR.js +0 -49
- package/esm/__chunks/EMSH4P76.js +0 -20
- package/esm/__chunks/FFKFVMIE.js +0 -167
- package/esm/__chunks/FL7AILGH.js +0 -133
- package/esm/__chunks/FNXUONAV.js +0 -110
- package/esm/__chunks/G4NJHFFU.js +0 -320
- package/esm/__chunks/HJSXC6HP.js +0 -117
- package/esm/__chunks/IEOGAQYI.js +0 -46
- package/esm/__chunks/IZFGBYGE.js +0 -34
- package/esm/__chunks/J34UVKLA.js +0 -26
- package/esm/__chunks/JZPBBBIG.js +0 -74
- package/esm/__chunks/KWUJP5MG.js +0 -135
- package/esm/__chunks/M35URMT4.js +0 -313
- package/esm/__chunks/NF3M2L6C.js +0 -81
- package/esm/__chunks/O3CCA76Q.js +0 -22
- package/esm/__chunks/PNPPDYKC.js +0 -299
- package/esm/__chunks/QFXN4EHM.js +0 -393
- package/esm/__chunks/QKDDLIWD.js +0 -146
- package/esm/__chunks/QSE66AKY.js +0 -208
- package/esm/__chunks/QUF7PS4R.js +0 -18
- package/esm/__chunks/S7IJPJ4R.js +0 -126
- package/esm/__chunks/SD3E3EPH.js +0 -163
- package/esm/__chunks/SJXQJ7RS.js +0 -92
- package/esm/__chunks/SNCKIAOR.js +0 -0
- package/esm/__chunks/T3TTUHTW.js +0 -30
- package/esm/__chunks/TIOVE6HR.js +0 -0
- package/esm/__chunks/TXKMEIDQ.js +0 -0
- package/esm/__chunks/U7HAE2RF.js +0 -288
- package/esm/__chunks/UXWY7BYE.js +0 -63
- package/esm/__chunks/VKAKISRG.js +0 -192
- package/esm/__chunks/WD2YR6I7.js +0 -0
- package/esm/__chunks/WOZFZKFY.js +0 -0
- package/esm/__chunks/XI7GZDE2.js +0 -0
- package/esm/__chunks/XOUWDB3T.js +0 -249
- package/esm/__chunks/XQN2TA4S.js +0 -23
- package/esm/__chunks/XXK32TIM.js +0 -16
- package/esm/__chunks/YGWTVPZE.js +0 -538
- package/esm/__chunks/YRG7PT33.js +0 -127
- package/esm/__chunks/ZHKVJO2U.js +0 -47
- package/esm/__chunks/ZO55YUSY.js +0 -9
- package/esm/commands/aws/iam/policies/s3-restrictions-deny-non-s3-services.js +0 -28
- package/esm/commands/aws/iam/policies/sts-federation.js +0 -19
- package/esm/commands/aws/iam/policies/user-admins-deny-list.js +0 -183
- package/esm/commands/aws/iam/policies/user-admins-deny-regions-list.js +0 -49
- package/esm/commands/aws/iam/policies/user-admins-self-service-iam.js +0 -64
- package/esm/commands/aws/iam/policies/user-admins-write-list.js +0 -125
|
@@ -1,12 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require(
|
|
5
|
-
require(
|
|
6
|
-
require(
|
|
7
|
-
|
|
8
|
-
require(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("../../../../__chunks/VH7oDXx4.cjs");
|
|
3
|
+
const require_commands_aws_utils_resolve_profile = require("../../utils/resolve-profile.cjs");
|
|
4
|
+
const require_commands_aws_ses_send_email_schema = require("./schema.cjs");
|
|
5
|
+
const require_commands_aws_ses_send_email_utils = require("./utils.cjs");
|
|
6
|
+
let chalk = require("chalk");
|
|
7
|
+
chalk = require_rolldown_runtime.__toESM(chalk, 1);
|
|
8
|
+
let zod = require("zod");
|
|
9
|
+
//#region src/commands/aws/ses/send-email/handler.js
|
|
10
|
+
/**
|
|
11
|
+
* `aws ses send-email` handler: send a single test email via the SES API or SMTP.
|
|
12
|
+
* @param {unknown} options
|
|
13
|
+
*/
|
|
14
|
+
async function sendEmailCommand(options) {
|
|
15
|
+
try {
|
|
16
|
+
const parsed = require_commands_aws_ses_send_email_schema.sendEmailOptionsSchema.parse(options);
|
|
17
|
+
const { to, from, subject, transport, region, profile: profileOption, accessKeyId, dryRun, verbose } = parsed;
|
|
18
|
+
const body = parsed.body ?? require_commands_aws_ses_send_email_utils.defaultBody();
|
|
19
|
+
const profile = transport === "api" ? await require_commands_aws_utils_resolve_profile.resolveProfile({ profile: profileOption }) : profileOption;
|
|
20
|
+
console.log(chalk.default.blue("\n📧 SES send-email"));
|
|
21
|
+
console.log(chalk.default.gray(` transport: ${transport}`));
|
|
22
|
+
console.log(chalk.default.gray(` region: ${region}`));
|
|
23
|
+
console.log(chalk.default.gray(` from: ${from}`));
|
|
24
|
+
console.log(chalk.default.gray(` to: ${to}`));
|
|
25
|
+
console.log(chalk.default.gray(` subject: ${subject}`));
|
|
26
|
+
if (verbose) console.log(chalk.default.gray(` body: ${body}`));
|
|
27
|
+
if (dryRun) {
|
|
28
|
+
console.log(chalk.default.yellow("\n[dry-run] No email sent."));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const messageId = transport === "api" ? await require_commands_aws_ses_send_email_utils.sendViaApi({
|
|
32
|
+
to,
|
|
33
|
+
from,
|
|
34
|
+
subject,
|
|
35
|
+
body,
|
|
36
|
+
region,
|
|
37
|
+
profile
|
|
38
|
+
}) : await require_commands_aws_ses_send_email_utils.sendViaSmtp({
|
|
39
|
+
to,
|
|
40
|
+
from,
|
|
41
|
+
subject,
|
|
42
|
+
body,
|
|
43
|
+
region,
|
|
44
|
+
accessKeyId
|
|
45
|
+
});
|
|
46
|
+
console.log(chalk.default.green(`\n✅ Email sent${messageId ? ` (messageId: ${messageId})` : ""}.`));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (error instanceof zod.ZodError) {
|
|
49
|
+
console.error(chalk.default.red("\n❌ Invalid command options:"));
|
|
50
|
+
error.errors.forEach((err) => {
|
|
51
|
+
console.error(chalk.default.red(` ${err.path.join(".")}: ${err.message}`));
|
|
52
|
+
});
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
const verbose = options?.verbose || false;
|
|
56
|
+
console.error(chalk.default.red("\n❌ send-email failed:"));
|
|
57
|
+
if (error instanceof Error) {
|
|
58
|
+
console.error(chalk.default.red(` ${error.message}`));
|
|
59
|
+
if (verbose && error.stack) {
|
|
60
|
+
console.error(chalk.default.gray("\nStack trace:"));
|
|
61
|
+
console.error(chalk.default.gray(error.stack));
|
|
62
|
+
}
|
|
63
|
+
} else console.error(chalk.default.red(` ${String(error)}`));
|
|
64
|
+
console.error(chalk.default.yellow("\n💡 Troubleshooting tips:"));
|
|
65
|
+
console.error(chalk.default.yellow(" • The sender address must be verified in SES"));
|
|
66
|
+
console.error(chalk.default.yellow(" • New SES accounts are sandboxed — recipients must also be verified"));
|
|
67
|
+
console.error(chalk.default.yellow(" • For smtp transport, set SES_SMTP_USER and SES_SMTP_PASSWORD"));
|
|
68
|
+
console.error(chalk.default.yellow(" • Use --verbose for detailed error information\n"));
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.sendEmailCommand = sendEmailCommand;
|
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
require('../../../../__chunks/GUL36IFZ.cjs');
|
|
11
|
-
require('../../../../__chunks/NT2XXAI6.cjs');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _N7D56LPPcjs = require('../../../../__chunks/N7D56LPP.cjs');
|
|
15
|
-
require('../../../../__chunks/WOYF2L6T.cjs');
|
|
16
|
-
require('../../../../__chunks/CMUD7LLN.cjs');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
exports.defaultBody = _YRHFKTW2cjs.defaultBody; exports.sendEmailCommand = _TKNNDDIBcjs.sendEmailCommand; exports.sendEmailOptionsSchema = _N7D56LPPcjs.sendEmailOptionsSchema; exports.sendViaApi = _YRHFKTW2cjs.sendViaApi; exports.sendViaSmtp = _YRHFKTW2cjs.sendViaSmtp;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_commands_aws_ses_send_email_schema = require("./schema.cjs");
|
|
3
|
+
const require_commands_aws_ses_send_email_utils = require("./utils.cjs");
|
|
4
|
+
const require_commands_aws_ses_send_email_handler = require("./handler.cjs");
|
|
5
|
+
exports.defaultBody = require_commands_aws_ses_send_email_utils.defaultBody;
|
|
6
|
+
exports.sendEmailCommand = require_commands_aws_ses_send_email_handler.sendEmailCommand;
|
|
7
|
+
exports.sendEmailOptionsSchema = require_commands_aws_ses_send_email_schema.sendEmailOptionsSchema;
|
|
8
|
+
exports.sendViaApi = require_commands_aws_ses_send_email_utils.sendViaApi;
|
|
9
|
+
exports.sendViaSmtp = require_commands_aws_ses_send_email_utils.sendViaSmtp;
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_commands_aws_schema = require("../../schema.cjs");
|
|
3
|
+
let zod = require("zod");
|
|
4
|
+
//#region src/commands/aws/ses/send-email/schema.js
|
|
5
|
+
/**
|
|
6
|
+
* Zod schema for `aws ses send-email` options.
|
|
7
|
+
*/
|
|
8
|
+
const sendEmailOptionsSchema = zod.z.object({
|
|
9
|
+
to: zod.z.string({ required_error: "--to <address> is required" }).describe("Recipient email address"),
|
|
10
|
+
from: zod.z.string({ required_error: "--from <address> is required" }).describe("Verified SES sender email address"),
|
|
11
|
+
subject: zod.z.string().optional().default("MTN CLI test email").describe("Email subject line"),
|
|
12
|
+
body: zod.z.string().optional().describe("Email body (defaults to a timestamp and random token)"),
|
|
13
|
+
transport: zod.z.enum(["api", "smtp"]).optional().default("api").describe("Send via the SES API (default) or SES SMTP"),
|
|
14
|
+
region: zod.z.string().optional().default("us-east-1").describe("AWS region for the SES endpoint"),
|
|
15
|
+
profile: require_commands_aws_schema.profileField,
|
|
16
|
+
accessKeyId: zod.z.string().optional().describe("IAM access key ID used as the SMTP username (smtp transport only)"),
|
|
17
|
+
dryRun: zod.z.boolean().optional().default(false).describe("Print the email payload without sending"),
|
|
18
|
+
verbose: require_commands_aws_schema.verboseField
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {z.infer<typeof sendEmailOptionsSchema>} SendEmailOptions
|
|
22
|
+
*/
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.sendEmailOptionsSchema = sendEmailOptionsSchema;
|
|
@@ -1,11 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_commands_aws_ses_smtp_password = require("../smtp-password.cjs");
|
|
3
|
+
let crypto = require("crypto");
|
|
4
|
+
//#region src/commands/aws/ses/send-email/utils.js
|
|
5
|
+
/**
|
|
6
|
+
* Build a default test-email body with a timestamp and random token.
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
function defaultBody() {
|
|
10
|
+
return `MTN CLI test email — random token: ${(0, crypto.randomBytes)(16).toString("hex")} — sent at ${(/* @__PURE__ */ new Date()).toISOString()}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Send an email through the SES API using the AWS SDK.
|
|
14
|
+
* @param {{
|
|
15
|
+
* to: string;
|
|
16
|
+
* from: string;
|
|
17
|
+
* subject: string;
|
|
18
|
+
* body: string;
|
|
19
|
+
* region: string;
|
|
20
|
+
* profile?: string;
|
|
21
|
+
* }} params
|
|
22
|
+
* @returns {Promise<string | undefined>} The SES message id
|
|
23
|
+
*/
|
|
24
|
+
async function sendViaApi(params) {
|
|
25
|
+
const { to, from, subject, body, region, profile } = params;
|
|
26
|
+
const { SESClient, SendEmailCommand } = await import("@aws-sdk/client-ses");
|
|
27
|
+
const { fromNodeProviderChain } = await import("@aws-sdk/credential-providers");
|
|
28
|
+
const client = new SESClient({
|
|
29
|
+
region,
|
|
30
|
+
credentials: fromNodeProviderChain(profile ? { profile } : {})
|
|
31
|
+
});
|
|
32
|
+
const command = new SendEmailCommand({
|
|
33
|
+
Source: from,
|
|
34
|
+
Destination: { ToAddresses: [to] },
|
|
35
|
+
Message: {
|
|
36
|
+
Subject: { Data: subject },
|
|
37
|
+
Body: { Text: { Data: body } }
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return (await client.send(command)).MessageId;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Send an email through the SES SMTP endpoint using nodemailer.
|
|
44
|
+
* Credentials come from SES_SMTP_USER/SES_SMTP_PASSWORD, or the password is
|
|
45
|
+
* derived from AWS_SECRET_ACCESS_KEY when only that is available.
|
|
46
|
+
* @param {{
|
|
47
|
+
* to: string;
|
|
48
|
+
* from: string;
|
|
49
|
+
* subject: string;
|
|
50
|
+
* body: string;
|
|
51
|
+
* region: string;
|
|
52
|
+
* accessKeyId?: string;
|
|
53
|
+
* }} params
|
|
54
|
+
* @returns {Promise<string | undefined>} The SMTP message id
|
|
55
|
+
*/
|
|
56
|
+
async function sendViaSmtp(params) {
|
|
57
|
+
const { to, from, subject, body, region, accessKeyId } = params;
|
|
58
|
+
const user = process.env.SES_SMTP_USER ?? accessKeyId;
|
|
59
|
+
let pass = process.env.SES_SMTP_PASSWORD;
|
|
60
|
+
if (!pass) {
|
|
61
|
+
const secret = process.env.AWS_SECRET_ACCESS_KEY;
|
|
62
|
+
if (secret) pass = require_commands_aws_ses_smtp_password.calculateSmtpPassword({
|
|
63
|
+
secretAccessKey: secret,
|
|
64
|
+
region
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (!user || !pass) throw new Error("SMTP transport requires SES_SMTP_USER and SES_SMTP_PASSWORD, or AWS_SECRET_ACCESS_KEY (plus --access-key-id) to derive the SMTP password.");
|
|
68
|
+
const nodemailerModule = await import("nodemailer");
|
|
69
|
+
return (await (nodemailerModule.default ?? nodemailerModule).createTransport({
|
|
70
|
+
host: require_commands_aws_ses_smtp_password.smtpEndpoint(region),
|
|
71
|
+
port: 587,
|
|
72
|
+
secure: false,
|
|
73
|
+
auth: {
|
|
74
|
+
user,
|
|
75
|
+
pass
|
|
76
|
+
}
|
|
77
|
+
}).sendMail({
|
|
78
|
+
from,
|
|
79
|
+
to,
|
|
80
|
+
subject,
|
|
81
|
+
text: body
|
|
82
|
+
})).messageId;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.defaultBody = defaultBody;
|
|
86
|
+
exports.sendViaApi = sendViaApi;
|
|
87
|
+
exports.sendViaSmtp = sendViaSmtp;
|
|
@@ -1,10 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let crypto = require("crypto");
|
|
3
|
+
//#region src/commands/aws/ses/smtp-password.js
|
|
4
|
+
/**
|
|
5
|
+
* AWS regions that expose an SES SMTP endpoint.
|
|
6
|
+
*/
|
|
7
|
+
const SMTP_REGIONS = /* @__PURE__ */ new Set([
|
|
8
|
+
"us-east-2",
|
|
9
|
+
"us-east-1",
|
|
10
|
+
"us-west-1",
|
|
11
|
+
"us-west-2",
|
|
12
|
+
"ap-south-1",
|
|
13
|
+
"ap-northeast-2",
|
|
14
|
+
"ap-southeast-1",
|
|
15
|
+
"ap-southeast-2",
|
|
16
|
+
"ap-northeast-1",
|
|
17
|
+
"ca-central-1",
|
|
18
|
+
"eu-central-1",
|
|
19
|
+
"eu-west-1",
|
|
20
|
+
"eu-west-2",
|
|
21
|
+
"eu-west-3",
|
|
22
|
+
"eu-south-1",
|
|
23
|
+
"eu-north-1",
|
|
24
|
+
"sa-east-1",
|
|
25
|
+
"us-gov-west-1",
|
|
26
|
+
"us-gov-east-1",
|
|
27
|
+
"me-south-1",
|
|
28
|
+
"af-south-1",
|
|
29
|
+
"il-central-1"
|
|
30
|
+
]);
|
|
31
|
+
const DATE = "11111111";
|
|
32
|
+
const SERVICE = "ses";
|
|
33
|
+
const MESSAGE = "SendRawEmail";
|
|
34
|
+
const TERMINAL = "aws4_request";
|
|
35
|
+
const VERSION = 4;
|
|
36
|
+
/**
|
|
37
|
+
* @param {Buffer} key
|
|
38
|
+
* @param {string} message
|
|
39
|
+
* @returns {Buffer}
|
|
40
|
+
*/
|
|
41
|
+
function sign(key, message) {
|
|
42
|
+
return (0, crypto.createHmac)("sha256", key).update(message, "utf8").digest();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Derive an SES SMTP password from an IAM secret access key, following the
|
|
46
|
+
* AWS Signature V4 algorithm with SES-specific constants.
|
|
47
|
+
* @see https://docs.aws.amazon.com/ses/latest/dg/smtp-credentials.html#smtp-credentials-convert
|
|
48
|
+
* @param {{ secretAccessKey: string; region: string }} params
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
function calculateSmtpPassword(params) {
|
|
52
|
+
const { secretAccessKey, region } = params;
|
|
53
|
+
if (!SMTP_REGIONS.has(region)) throw new Error(`calculateSmtpPassword: region "${region}" has no SES SMTP endpoint`);
|
|
54
|
+
let signature = sign(Buffer.from(`AWS4${secretAccessKey}`, "utf8"), DATE);
|
|
55
|
+
signature = sign(signature, region);
|
|
56
|
+
signature = sign(signature, SERVICE);
|
|
57
|
+
signature = sign(signature, TERMINAL);
|
|
58
|
+
signature = sign(signature, MESSAGE);
|
|
59
|
+
return Buffer.concat([Buffer.from([VERSION]), signature]).toString("base64");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* SES SMTP endpoint host for a region.
|
|
63
|
+
* @param {string} region
|
|
64
|
+
* @returns {string}
|
|
65
|
+
*/
|
|
66
|
+
function smtpEndpoint(region) {
|
|
67
|
+
return `email-smtp.${region}.amazonaws.com`;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
exports.SMTP_REGIONS = SMTP_REGIONS;
|
|
71
|
+
exports.calculateSmtpPassword = calculateSmtpPassword;
|
|
72
|
+
exports.smtpEndpoint = smtpEndpoint;
|
|
@@ -1,16 +1,145 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("../../../__chunks/VH7oDXx4.cjs");
|
|
3
|
+
let chalk = require("chalk");
|
|
4
|
+
chalk = require_rolldown_runtime.__toESM(chalk, 1);
|
|
5
|
+
let child_process = require("child_process");
|
|
6
|
+
//#region src/commands/aws/utils/exec-aws.js
|
|
7
|
+
/**
|
|
8
|
+
* Error raised when the AWS CLI (or aws-vault) exits non-zero.
|
|
9
|
+
* The `code` is the AWS service error code parsed from stderr (e.g. "UnauthorizedOperation").
|
|
10
|
+
*/
|
|
11
|
+
var AwsCliError = class extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} message
|
|
14
|
+
* @param {string | null} [code]
|
|
15
|
+
*/
|
|
16
|
+
constructor(message, code = null) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "AwsCliError";
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Extract the AWS service error code from a CLI stderr string.
|
|
24
|
+
* AWS prints codes in parentheses, e.g. "...(UnauthorizedOperation) when calling...".
|
|
25
|
+
* @param {string} stderr
|
|
26
|
+
* @returns {string | null}
|
|
27
|
+
*/
|
|
28
|
+
function parseAwsErrorCode(stderr) {
|
|
29
|
+
return /\(([A-Za-z.]+)\)/.exec(stderr)?.[1] ?? null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Verify that the given executables are available on PATH.
|
|
33
|
+
* @param {string[]} commands
|
|
34
|
+
* @throws {Error} If any command is missing
|
|
35
|
+
*/
|
|
36
|
+
function requireCommands(commands) {
|
|
37
|
+
const missing = commands.filter((command) => {
|
|
38
|
+
return (0, child_process.spawnSync)("which", [command], { stdio: "pipe" }).status !== 0;
|
|
39
|
+
});
|
|
40
|
+
if (missing.length > 0) throw new Error(`Required command(s) not found on PATH: ${missing.join(", ")}`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Run an AWS CLI command using a credential profile.
|
|
44
|
+
* Uses an argument array (no shell) so JSON arguments need no escaping.
|
|
45
|
+
* @param {{
|
|
46
|
+
* profile?: string;
|
|
47
|
+
* region?: string;
|
|
48
|
+
* args: string[];
|
|
49
|
+
* expectJson?: boolean;
|
|
50
|
+
* verbose?: boolean;
|
|
51
|
+
* env?: Record<string, string>;
|
|
52
|
+
* }} params
|
|
53
|
+
* @returns {any} Parsed JSON when expectJson is true, otherwise trimmed stdout string
|
|
54
|
+
*/
|
|
55
|
+
function runAws(params) {
|
|
56
|
+
const { profile, region, args, expectJson = true, verbose = false, env } = params;
|
|
57
|
+
/** @type {string[]} */
|
|
58
|
+
const finalArgs = [];
|
|
59
|
+
if (profile) finalArgs.push("--profile", profile);
|
|
60
|
+
if (region) finalArgs.push("--region", region);
|
|
61
|
+
finalArgs.push("--no-cli-pager", ...args);
|
|
62
|
+
if (expectJson) finalArgs.push("--output", "json");
|
|
63
|
+
return spawnAws("aws", finalArgs, {
|
|
64
|
+
expectJson,
|
|
65
|
+
verbose,
|
|
66
|
+
env
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Run an AWS CLI command through `aws-vault exec` for profiles whose credentials
|
|
71
|
+
* are stored in the OS keychain rather than ~/.aws/credentials.
|
|
72
|
+
* @param {{
|
|
73
|
+
* profile: string;
|
|
74
|
+
* args: string[];
|
|
75
|
+
* duration?: string;
|
|
76
|
+
* expectJson?: boolean;
|
|
77
|
+
* verbose?: boolean;
|
|
78
|
+
* }} params
|
|
79
|
+
* @returns {any}
|
|
80
|
+
*/
|
|
81
|
+
function runAwsVault(params) {
|
|
82
|
+
const { profile, args, duration = "15m", expectJson = true, verbose = false } = params;
|
|
83
|
+
/** @type {string[]} */
|
|
84
|
+
const awsArgs = ["--no-cli-pager", ...args];
|
|
85
|
+
if (expectJson) awsArgs.push("--output", "json");
|
|
86
|
+
return spawnAws("aws-vault", [
|
|
87
|
+
"exec",
|
|
88
|
+
profile,
|
|
89
|
+
"--duration",
|
|
90
|
+
duration,
|
|
91
|
+
"--",
|
|
92
|
+
"aws",
|
|
93
|
+
...awsArgs
|
|
94
|
+
], {
|
|
95
|
+
expectJson,
|
|
96
|
+
verbose
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @param {string} command
|
|
101
|
+
* @param {string[]} args
|
|
102
|
+
* @param {{ expectJson: boolean; verbose: boolean; env?: Record<string, string> }} options
|
|
103
|
+
* @returns {any}
|
|
104
|
+
*/
|
|
105
|
+
function spawnAws(command, args, options) {
|
|
106
|
+
const { expectJson, verbose, env } = options;
|
|
107
|
+
if (verbose) console.log(chalk.default.gray(` Executing: ${command} ${args.join(" ")}`));
|
|
108
|
+
const result = (0, child_process.spawnSync)(command, args, {
|
|
109
|
+
encoding: "utf-8",
|
|
110
|
+
env: env ? {
|
|
111
|
+
...process.env,
|
|
112
|
+
...env
|
|
113
|
+
} : process.env
|
|
114
|
+
});
|
|
115
|
+
if (result.error) throw new AwsCliError(result.error.message);
|
|
116
|
+
if (result.status !== 0) {
|
|
117
|
+
const stderr = (result.stderr || result.stdout || "").trim();
|
|
118
|
+
throw new AwsCliError(stderr || `Command failed: ${command} ${args.join(" ")}`, parseAwsErrorCode(stderr));
|
|
119
|
+
}
|
|
120
|
+
const stdout = (result.stdout ?? "").trim();
|
|
121
|
+
if (!expectJson) return stdout;
|
|
122
|
+
if (!stdout) return {};
|
|
123
|
+
return JSON.parse(stdout);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fetch the caller identity for a profile (account id and ARN).
|
|
127
|
+
* @param {{ profile?: string; region?: string; verbose?: boolean }} params
|
|
128
|
+
* @returns {{ Account: string; Arn: string; UserId: string }}
|
|
129
|
+
*/
|
|
130
|
+
function getCallerIdentity(params) {
|
|
131
|
+
const { profile, region, verbose } = params;
|
|
132
|
+
return runAws({
|
|
133
|
+
profile,
|
|
134
|
+
region,
|
|
135
|
+
args: ["sts", "get-caller-identity"],
|
|
136
|
+
verbose
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
exports.AwsCliError = AwsCliError;
|
|
141
|
+
exports.getCallerIdentity = getCallerIdentity;
|
|
142
|
+
exports.parseAwsErrorCode = parseAwsErrorCode;
|
|
143
|
+
exports.requireCommands = requireCommands;
|
|
144
|
+
exports.runAws = runAws;
|
|
145
|
+
exports.runAwsVault = runAwsVault;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let url = require("url");
|
|
3
|
+
//#region src/commands/aws/utils/resolve-policy-path.js
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the absolute path to a bundled IAM policy document.
|
|
6
|
+
* Policies live alongside the source in `iam/policies/`, and the CLI runs from
|
|
7
|
+
* source, so this path is valid at runtime.
|
|
8
|
+
* @param {string} fileName - Policy JSON file name (e.g. "user-admins-write-list.json")
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
function resolvePolicyPath(fileName) {
|
|
12
|
+
return (0, url.fileURLToPath)(new URL(`../iam/policies/${fileName}`, require("url").pathToFileURL(__filename).href));
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.resolvePolicyPath = resolvePolicyPath;
|
|
@@ -1,11 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
require(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("../../../__chunks/VH7oDXx4.cjs");
|
|
3
|
+
const require_commands_aws_utils_tty = require("./tty.cjs");
|
|
4
|
+
let chalk = require("chalk");
|
|
5
|
+
chalk = require_rolldown_runtime.__toESM(chalk, 1);
|
|
6
|
+
let fs = require("fs");
|
|
7
|
+
let path = require("path");
|
|
8
|
+
let os = require("os");
|
|
9
|
+
//#region src/commands/aws/utils/resolve-profile.js
|
|
10
|
+
/**
|
|
11
|
+
* Above this many matches we ask the user to narrow the filter rather than
|
|
12
|
+
* printing an unusable wall of numbered options.
|
|
13
|
+
*/
|
|
14
|
+
const MAX_LISTED = 30;
|
|
15
|
+
/**
|
|
16
|
+
* Read profile names from ~/.aws/config (honoring AWS_CONFIG_FILE).
|
|
17
|
+
* Handles both `[profile NAME]` entries and a bare `[default]` section.
|
|
18
|
+
* @returns {string[]}
|
|
19
|
+
*/
|
|
20
|
+
function listConfigProfiles() {
|
|
21
|
+
const configPath = process.env.AWS_CONFIG_FILE ?? (0, path.join)((0, os.homedir)(), ".aws", "config");
|
|
22
|
+
let contents;
|
|
23
|
+
try {
|
|
24
|
+
contents = (0, fs.readFileSync)(configPath, "utf-8");
|
|
25
|
+
} catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
/** @type {string[]} */
|
|
29
|
+
const profiles = [];
|
|
30
|
+
const profileRe = /^\[profile\s+(.+?)\]$/;
|
|
31
|
+
for (const rawLine of contents.split("\n")) {
|
|
32
|
+
const line = rawLine.trim();
|
|
33
|
+
const match = profileRe.exec(line);
|
|
34
|
+
if (match?.[1]) profiles.push(match[1].trim());
|
|
35
|
+
else if (line === "[default]") profiles.push("default");
|
|
36
|
+
}
|
|
37
|
+
return profiles;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Interactively narrow a profile list by substring, then pick one.
|
|
41
|
+
* A single match auto-selects; too many matches asks the user to narrow.
|
|
42
|
+
* @param {string[]} profiles
|
|
43
|
+
* @returns {Promise<string>}
|
|
44
|
+
*/
|
|
45
|
+
async function pickProfileInteractive(profiles) {
|
|
46
|
+
for (;;) {
|
|
47
|
+
const filter = (await require_commands_aws_utils_tty.prompt(chalk.default.cyan("Filter profiles (substring, Enter for all): "))).trim().toLowerCase();
|
|
48
|
+
const matches = filter ? profiles.filter((name) => name.toLowerCase().includes(filter)) : profiles;
|
|
49
|
+
if (matches.length === 0) {
|
|
50
|
+
console.log(chalk.default.yellow(` No profiles match "${filter}". Try again.`));
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (matches.length === 1) {
|
|
54
|
+
const only = matches[0] ?? "";
|
|
55
|
+
console.log(chalk.default.green(` → ${only}`));
|
|
56
|
+
return only;
|
|
57
|
+
}
|
|
58
|
+
if (matches.length > MAX_LISTED) {
|
|
59
|
+
console.log(chalk.default.yellow(` ${matches.length} profiles match — narrow the filter (over ${MAX_LISTED} to list).`));
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
return matches[await require_commands_aws_utils_tty.promptChoice({
|
|
63
|
+
message: chalk.default.cyan("Select a profile:"),
|
|
64
|
+
options: matches
|
|
65
|
+
})] ?? "";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve the AWS profile for a single-profile command.
|
|
70
|
+
*
|
|
71
|
+
* Precedence: explicit `--profile`, then `AWS_PROFILE`, then — only when stdin
|
|
72
|
+
* is a TTY — an interactive filter-and-pick over `~/.aws/config` profiles.
|
|
73
|
+
* Returns `undefined` when nothing is set and we cannot prompt (non-interactive
|
|
74
|
+
* shell, or no config profiles), leaving each command's existing "no profile"
|
|
75
|
+
* handling in place.
|
|
76
|
+
* @param {{ profile?: string; interactive?: boolean }} params
|
|
77
|
+
* @returns {Promise<string | undefined>}
|
|
78
|
+
*/
|
|
79
|
+
async function resolveProfile(params) {
|
|
80
|
+
const explicit = params.profile ?? process.env.AWS_PROFILE;
|
|
81
|
+
if (explicit) return explicit;
|
|
82
|
+
if (!(params.interactive ?? Boolean(process.stdin.isTTY))) return;
|
|
83
|
+
const profiles = listConfigProfiles();
|
|
84
|
+
if (profiles.length === 0) return;
|
|
85
|
+
console.log(chalk.default.yellow("\nNo AWS profile selected (--profile and AWS_PROFILE are unset)."));
|
|
86
|
+
const chosen = await pickProfileInteractive(profiles);
|
|
87
|
+
console.log(chalk.default.gray(`Using profile "${chosen}" for this command.\n`));
|
|
88
|
+
return chosen;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
exports.listConfigProfiles = listConfigProfiles;
|
|
92
|
+
exports.pickProfileInteractive = pickProfileInteractive;
|
|
93
|
+
exports.resolveProfile = resolveProfile;
|