@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,30 +1,454 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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("../../utils/tty.cjs");
|
|
4
|
+
const require_commands_aws_utils_exec_aws = require("../../utils/exec-aws.cjs");
|
|
5
|
+
let chalk = require("chalk");
|
|
6
|
+
chalk = require_rolldown_runtime.__toESM(chalk, 1);
|
|
7
|
+
//#region src/commands/aws/iam/users/utils.js
|
|
8
|
+
const KNOWN_ROLES = [
|
|
9
|
+
"read-only",
|
|
10
|
+
"iam-admin",
|
|
11
|
+
"power-user"
|
|
12
|
+
];
|
|
13
|
+
const REQUIRED_ACL_GROUPS = [
|
|
14
|
+
"acl-read-only",
|
|
15
|
+
"acl-iam-full-access",
|
|
16
|
+
"acl-power-users"
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Map a user role to its ACL group.
|
|
20
|
+
* @param {string} role
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function roleToGroup(role) {
|
|
24
|
+
switch (role) {
|
|
25
|
+
case "read-only": return "acl-read-only";
|
|
26
|
+
case "iam-admin": return "acl-iam-full-access";
|
|
27
|
+
case "power-user": return "acl-power-users";
|
|
28
|
+
default: throw new Error(`Unknown role: ${role}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lowercase and hyphenate a raw value into a slug.
|
|
33
|
+
* @param {string} value
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
function normalizeSlug(value) {
|
|
37
|
+
return value.toLowerCase().replace(/ /g, "-");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} value
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
function isValidSlug(value) {
|
|
44
|
+
return /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(value);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build the canonical IAM username.
|
|
48
|
+
* @param {{ identifier: string; accountName: string; role: string }} params
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
function buildUsername(params) {
|
|
52
|
+
const { identifier, accountName, role } = params;
|
|
53
|
+
return `md-${identifier}-${accountName}-${role}`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Strip md- prefix, role suffix, and account suffix from a raw identifier.
|
|
57
|
+
* @param {{ raw: string; accountName: string; role: string }} params
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
function normalizeIdentifier(params) {
|
|
61
|
+
const { raw, accountName, role } = params;
|
|
62
|
+
let identifier = normalizeSlug(raw);
|
|
63
|
+
if (identifier.startsWith("md-")) identifier = identifier.slice(3);
|
|
64
|
+
if (identifier.endsWith(`-${role}`)) identifier = identifier.slice(0, -(role.length + 1));
|
|
65
|
+
else for (const knownRole of KNOWN_ROLES) if (identifier.endsWith(`-${knownRole}`)) {
|
|
66
|
+
identifier = identifier.slice(0, -(knownRole.length + 1));
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (identifier.endsWith(`-${accountName}`)) identifier = identifier.slice(0, -(accountName.length + 1));
|
|
70
|
+
return identifier;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Parse an md-{identifier}-{account}-{role} username into parts.
|
|
74
|
+
* Identifier is the first segment; account is everything between it and the role
|
|
75
|
+
* (so multi-segment account slugs still work).
|
|
76
|
+
* @param {string} name - Profile name or IAM user name
|
|
77
|
+
* @returns {{ identifier: string; accountName: string; role: string } | null}
|
|
78
|
+
*/
|
|
79
|
+
function parseMdUsername(name) {
|
|
80
|
+
let value = normalizeSlug(name);
|
|
81
|
+
if (!value.startsWith("md-")) return null;
|
|
82
|
+
value = value.slice(3);
|
|
83
|
+
const rolesByLength = [...KNOWN_ROLES].sort((a, b) => b.length - a.length);
|
|
84
|
+
/** @type {string | null} */
|
|
85
|
+
let role = null;
|
|
86
|
+
for (const knownRole of rolesByLength) if (value.endsWith(`-${knownRole}`)) {
|
|
87
|
+
role = knownRole;
|
|
88
|
+
value = value.slice(0, -(knownRole.length + 1));
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if (!role) return null;
|
|
92
|
+
const dash = value.indexOf("-");
|
|
93
|
+
if (dash <= 0 || dash === value.length - 1) return null;
|
|
94
|
+
const identifier = value.slice(0, dash);
|
|
95
|
+
const accountName = value.slice(dash + 1);
|
|
96
|
+
if (!isValidSlug(identifier) || !isValidSlug(accountName)) return null;
|
|
97
|
+
return {
|
|
98
|
+
identifier,
|
|
99
|
+
accountName,
|
|
100
|
+
role
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Infer the AWS account slug from the caller IAM user / profile name.
|
|
105
|
+
* Prefers the ARN username, then the profile string.
|
|
106
|
+
* @param {{
|
|
107
|
+
* profile?: string;
|
|
108
|
+
* identity?: { Arn?: string };
|
|
109
|
+
* }} params
|
|
110
|
+
* @returns {string | null}
|
|
111
|
+
*/
|
|
112
|
+
function inferAccountName(params) {
|
|
113
|
+
const { profile, identity } = params;
|
|
114
|
+
const arn = identity?.Arn ?? "";
|
|
115
|
+
const username = arn.includes("/") ? arn.split("/").pop() ?? "" : "";
|
|
116
|
+
for (const candidate of [username, profile ?? ""]) {
|
|
117
|
+
if (!candidate) continue;
|
|
118
|
+
const parsed = parseMdUsername(candidate);
|
|
119
|
+
if (parsed) return parsed.accountName;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @param {{ username: string; profile?: string; verbose?: boolean }} params
|
|
125
|
+
* @returns {boolean}
|
|
126
|
+
*/
|
|
127
|
+
function userExists(params) {
|
|
128
|
+
const { username, profile, verbose } = params;
|
|
129
|
+
try {
|
|
130
|
+
require_commands_aws_utils_exec_aws.runAws({
|
|
131
|
+
profile,
|
|
132
|
+
args: [
|
|
133
|
+
"iam",
|
|
134
|
+
"get-user",
|
|
135
|
+
"--user-name",
|
|
136
|
+
username
|
|
137
|
+
],
|
|
138
|
+
verbose
|
|
139
|
+
});
|
|
140
|
+
return true;
|
|
141
|
+
} catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Create the IAM user if it does not exist.
|
|
147
|
+
* @param {{ username: string; profile?: string; verbose?: boolean }} params
|
|
148
|
+
*/
|
|
149
|
+
function ensureUser(params) {
|
|
150
|
+
const { username, profile, verbose } = params;
|
|
151
|
+
if (userExists({
|
|
152
|
+
username,
|
|
153
|
+
profile,
|
|
154
|
+
verbose
|
|
155
|
+
})) {
|
|
156
|
+
console.log(` User exists: ${username}`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
console.log(` Create user: ${username}`);
|
|
160
|
+
require_commands_aws_utils_exec_aws.runAws({
|
|
161
|
+
profile,
|
|
162
|
+
args: [
|
|
163
|
+
"iam",
|
|
164
|
+
"create-user",
|
|
165
|
+
"--user-name",
|
|
166
|
+
username,
|
|
167
|
+
"--path",
|
|
168
|
+
"/"
|
|
169
|
+
],
|
|
170
|
+
verbose
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Add the user to the group if not already a member.
|
|
175
|
+
* @param {{ username: string; group: string; profile?: string; verbose?: boolean }} params
|
|
176
|
+
*/
|
|
177
|
+
function ensureUserInGroup(params) {
|
|
178
|
+
const { username, group, profile, verbose } = params;
|
|
179
|
+
if (require_commands_aws_utils_exec_aws.runAws({
|
|
180
|
+
profile,
|
|
181
|
+
args: [
|
|
182
|
+
"iam",
|
|
183
|
+
"get-group",
|
|
184
|
+
"--group-name",
|
|
185
|
+
group,
|
|
186
|
+
"--query",
|
|
187
|
+
`Users[?UserName=='${username}'].UserName`,
|
|
188
|
+
"--output",
|
|
189
|
+
"text"
|
|
190
|
+
],
|
|
191
|
+
expectJson: false,
|
|
192
|
+
verbose
|
|
193
|
+
})) {
|
|
194
|
+
console.log(` Already in group: ${group}`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
console.log(` Add to group: ${group}`);
|
|
198
|
+
require_commands_aws_utils_exec_aws.runAws({
|
|
199
|
+
profile,
|
|
200
|
+
args: [
|
|
201
|
+
"iam",
|
|
202
|
+
"add-user-to-group",
|
|
203
|
+
"--user-name",
|
|
204
|
+
username,
|
|
205
|
+
"--group-name",
|
|
206
|
+
group
|
|
207
|
+
],
|
|
208
|
+
expectJson: false,
|
|
209
|
+
verbose
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Create a CLI access key for the user and print a one-line setup command.
|
|
214
|
+
* @param {{ username: string; profile?: string; verbose?: boolean }} params
|
|
215
|
+
* @returns {boolean} False when the user already has the maximum number of keys
|
|
216
|
+
*/
|
|
217
|
+
function createCliAccessKey(params) {
|
|
218
|
+
const { username, profile, verbose } = params;
|
|
219
|
+
const keyCountRaw = require_commands_aws_utils_exec_aws.runAws({
|
|
220
|
+
profile,
|
|
221
|
+
args: [
|
|
222
|
+
"iam",
|
|
223
|
+
"list-access-keys",
|
|
224
|
+
"--user-name",
|
|
225
|
+
username,
|
|
226
|
+
"--query",
|
|
227
|
+
"length(AccessKeyMetadata)",
|
|
228
|
+
"--output",
|
|
229
|
+
"text"
|
|
230
|
+
],
|
|
231
|
+
expectJson: false,
|
|
232
|
+
verbose
|
|
233
|
+
});
|
|
234
|
+
if ((Number.parseInt(keyCountRaw, 10) || 0) >= 2) {
|
|
235
|
+
console.log(chalk.default.yellow(` WARNING: ${username} already has 2 access keys (AWS max).`));
|
|
236
|
+
console.log(chalk.default.yellow(" Delete an existing key before creating a new one."));
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
const [accessKeyId, secretAccessKey] = require_commands_aws_utils_exec_aws.runAws({
|
|
240
|
+
profile,
|
|
241
|
+
args: [
|
|
242
|
+
"iam",
|
|
243
|
+
"create-access-key",
|
|
244
|
+
"--user-name",
|
|
245
|
+
username,
|
|
246
|
+
"--query",
|
|
247
|
+
"AccessKey.[AccessKeyId,SecretAccessKey]",
|
|
248
|
+
"--output",
|
|
249
|
+
"text"
|
|
250
|
+
],
|
|
251
|
+
expectJson: false,
|
|
252
|
+
verbose
|
|
253
|
+
}).split(/\s+/);
|
|
254
|
+
if (!accessKeyId || !secretAccessKey) throw new Error("Failed to parse the newly created access key");
|
|
255
|
+
const setupCmd = ` export AWS_ACCESS_KEY_ID='${accessKeyId}' AWS_SECRET_ACCESS_KEY='${secretAccessKey}' && aws-vault add ${username} --env --add-config && aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" --profile ${username} && aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" --profile ${username} && aws configure set region us-east-1 --profile ${username}`;
|
|
256
|
+
console.log("");
|
|
257
|
+
console.log(` CLI credentials for ${username} (secret shown once — copy now):`);
|
|
258
|
+
console.log(" ────────────────────────────────────────────────────────────────");
|
|
259
|
+
console.log(" YOU MUST run the command below with a LEADING SPACE so it is not saved");
|
|
260
|
+
console.log(" to shell history — same idea as: TEST=\"a\" && echo $TEST");
|
|
261
|
+
console.log("");
|
|
262
|
+
console.log(setupCmd);
|
|
263
|
+
console.log(" ────────────────────────────────────────────────────────────────");
|
|
264
|
+
console.log("");
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Verify the required ACL groups exist before creating users.
|
|
269
|
+
* @param {{ profile?: string; verbose?: boolean }} params
|
|
270
|
+
* @returns {boolean}
|
|
271
|
+
*/
|
|
272
|
+
function ensureAclGroupsExist(params) {
|
|
273
|
+
const { profile, verbose } = params;
|
|
274
|
+
const missing = REQUIRED_ACL_GROUPS.filter((group) => {
|
|
275
|
+
try {
|
|
276
|
+
require_commands_aws_utils_exec_aws.runAws({
|
|
277
|
+
profile,
|
|
278
|
+
args: [
|
|
279
|
+
"iam",
|
|
280
|
+
"get-group",
|
|
281
|
+
"--group-name",
|
|
282
|
+
group
|
|
283
|
+
],
|
|
284
|
+
verbose
|
|
285
|
+
});
|
|
286
|
+
return false;
|
|
287
|
+
} catch {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
if (missing.length > 0) {
|
|
292
|
+
missing.forEach((group) => console.log(` Missing group: ${group}`));
|
|
293
|
+
console.log("");
|
|
294
|
+
console.log(" Run `mtn aws iam setup-acl` first to create ACL groups and policies.");
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* @param {{ accountName?: string; inferredAccountName?: string | null }} params
|
|
301
|
+
* @returns {Promise<string>}
|
|
302
|
+
*/
|
|
303
|
+
async function promptAccountName(params) {
|
|
304
|
+
const { accountName, inferredAccountName } = params;
|
|
305
|
+
if (accountName) {
|
|
306
|
+
const slug = normalizeSlug(accountName);
|
|
307
|
+
if (isValidSlug(slug)) {
|
|
308
|
+
console.log(` Account name: ${slug}`);
|
|
309
|
+
return slug;
|
|
310
|
+
}
|
|
311
|
+
console.log(" Invalid account name option — falling back to prompt.");
|
|
312
|
+
}
|
|
313
|
+
const defaultSlug = inferredAccountName && isValidSlug(normalizeSlug(inferredAccountName)) ? normalizeSlug(inferredAccountName) : null;
|
|
314
|
+
for (;;) {
|
|
315
|
+
const hint = defaultSlug ? ` [default: ${defaultSlug}]` : " (e.g. vincent)";
|
|
316
|
+
const raw = await require_commands_aws_utils_tty.prompt(` AWS account name${hint} — used in md-{identifier}-{account}-{role}: `);
|
|
317
|
+
if (raw === "" && defaultSlug) {
|
|
318
|
+
console.log(` → account name: ${defaultSlug}`);
|
|
319
|
+
return defaultSlug;
|
|
320
|
+
}
|
|
321
|
+
const slug = normalizeSlug(raw);
|
|
322
|
+
if (isValidSlug(slug)) {
|
|
323
|
+
if (raw !== slug) console.log(` → account name: ${slug}`);
|
|
324
|
+
return slug;
|
|
325
|
+
}
|
|
326
|
+
console.log(" Invalid account name — use lowercase letters, numbers, and hyphens" + (defaultSlug ? ", or press Enter to accept the default." : "."));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* @returns {Promise<string>}
|
|
331
|
+
*/
|
|
332
|
+
async function promptRole() {
|
|
333
|
+
for (;;) {
|
|
334
|
+
console.log(" Role (username will be md-{identifier}-{account}-{role}):");
|
|
335
|
+
console.log(" 1) read-only → acl-read-only");
|
|
336
|
+
console.log(" 2) iam-admin → acl-iam-full-access");
|
|
337
|
+
console.log(" 3) power-user → acl-power-users");
|
|
338
|
+
switch (await require_commands_aws_utils_tty.prompt(" Choice [1-3]: ")) {
|
|
339
|
+
case "1":
|
|
340
|
+
case "read-only": return "read-only";
|
|
341
|
+
case "2":
|
|
342
|
+
case "iam-admin": return "iam-admin";
|
|
343
|
+
case "3":
|
|
344
|
+
case "power-user": return "power-user";
|
|
345
|
+
default: console.log(" Invalid choice — enter 1, 2, 3, or the role name.");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* @param {{ accountName: string; role: string }} params
|
|
351
|
+
* @returns {Promise<string>}
|
|
352
|
+
*/
|
|
353
|
+
async function promptIdentifier(params) {
|
|
354
|
+
const { accountName, role } = params;
|
|
355
|
+
const exampleUser = buildUsername({
|
|
356
|
+
identifier: "declan",
|
|
357
|
+
accountName,
|
|
358
|
+
role
|
|
359
|
+
});
|
|
360
|
+
for (;;) {
|
|
361
|
+
const raw = await require_commands_aws_utils_tty.prompt(` Identifier (e.g. declan, or full ${exampleUser}): `);
|
|
362
|
+
const lowerRaw = normalizeSlug(raw);
|
|
363
|
+
const identifier = normalizeIdentifier({
|
|
364
|
+
raw,
|
|
365
|
+
accountName,
|
|
366
|
+
role
|
|
367
|
+
});
|
|
368
|
+
if (isValidSlug(identifier)) {
|
|
369
|
+
if (lowerRaw !== identifier) console.log(` → parsed identifier: ${identifier}`);
|
|
370
|
+
return identifier;
|
|
371
|
+
}
|
|
372
|
+
console.log(" Invalid identifier — use lowercase letters, numbers, and hyphens.");
|
|
373
|
+
console.log(" Tip: enter just the short name (e.g. declan).");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Interactively create IAM users, assign ACL groups, and print CLI credentials.
|
|
378
|
+
* @param {{
|
|
379
|
+
* accountName?: string;
|
|
380
|
+
* profile?: string;
|
|
381
|
+
* identity?: { Arn?: string };
|
|
382
|
+
* verbose?: boolean;
|
|
383
|
+
* }} params
|
|
384
|
+
*/
|
|
385
|
+
async function createUsersInteractive(params) {
|
|
386
|
+
const { accountName: accountNameOption, profile, identity, verbose } = params;
|
|
387
|
+
if (!ensureAclGroupsExist({
|
|
388
|
+
profile,
|
|
389
|
+
verbose
|
|
390
|
+
})) return;
|
|
391
|
+
console.log("");
|
|
392
|
+
const accountName = await promptAccountName({
|
|
393
|
+
accountName: accountNameOption,
|
|
394
|
+
inferredAccountName: inferAccountName({
|
|
395
|
+
profile,
|
|
396
|
+
identity
|
|
397
|
+
})
|
|
398
|
+
});
|
|
399
|
+
console.log("");
|
|
400
|
+
while (await require_commands_aws_utils_tty.promptYesNo({
|
|
401
|
+
message: " Create another user?",
|
|
402
|
+
defaultYes: false
|
|
403
|
+
})) {
|
|
404
|
+
console.log("");
|
|
405
|
+
const role = await promptRole();
|
|
406
|
+
const username = buildUsername({
|
|
407
|
+
identifier: await promptIdentifier({
|
|
408
|
+
accountName,
|
|
409
|
+
role
|
|
410
|
+
}),
|
|
411
|
+
accountName,
|
|
412
|
+
role
|
|
413
|
+
});
|
|
414
|
+
const group = roleToGroup(role);
|
|
415
|
+
console.log("");
|
|
416
|
+
console.log(` → user: ${username}`);
|
|
417
|
+
console.log(` → group: ${group}`);
|
|
418
|
+
console.log("");
|
|
419
|
+
ensureUser({
|
|
420
|
+
username,
|
|
421
|
+
profile,
|
|
422
|
+
verbose
|
|
423
|
+
});
|
|
424
|
+
ensureUserInGroup({
|
|
425
|
+
username,
|
|
426
|
+
group,
|
|
427
|
+
profile,
|
|
428
|
+
verbose
|
|
429
|
+
});
|
|
430
|
+
try {
|
|
431
|
+
createCliAccessKey({
|
|
432
|
+
username,
|
|
433
|
+
profile,
|
|
434
|
+
verbose
|
|
435
|
+
});
|
|
436
|
+
} catch (error) {
|
|
437
|
+
console.log(chalk.default.yellow(` Could not create access key: ${error instanceof Error ? error.message : String(error)}`));
|
|
438
|
+
}
|
|
439
|
+
console.log("");
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
//#endregion
|
|
443
|
+
exports.buildUsername = buildUsername;
|
|
444
|
+
exports.createCliAccessKey = createCliAccessKey;
|
|
445
|
+
exports.createUsersInteractive = createUsersInteractive;
|
|
446
|
+
exports.ensureAclGroupsExist = ensureAclGroupsExist;
|
|
447
|
+
exports.ensureUser = ensureUser;
|
|
448
|
+
exports.ensureUserInGroup = ensureUserInGroup;
|
|
449
|
+
exports.inferAccountName = inferAccountName;
|
|
450
|
+
exports.isValidSlug = isValidSlug;
|
|
451
|
+
exports.normalizeIdentifier = normalizeIdentifier;
|
|
452
|
+
exports.normalizeSlug = normalizeSlug;
|
|
453
|
+
exports.parseMdUsername = parseMdUsername;
|
|
454
|
+
exports.roleToGroup = roleToGroup;
|