@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,258 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import "
|
|
7
|
-
import "
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
1
|
+
import { promptChoice } from "../../utils/tty.js";
|
|
2
|
+
import { AwsCliError, getCallerIdentity, requireCommands } from "../../utils/exec-aws.js";
|
|
3
|
+
import { resolveProfile } from "../../utils/resolve-profile.js";
|
|
4
|
+
import { DEFAULT_REGION, allowIpOptionsSchema } from "./schema.js";
|
|
5
|
+
import { authorizeRule, describeSecurityGroups, extractRoamingFirstName, getCurrentPublicIp, getSecurityGroupDetails, instanceLabel, listEnabledRegions, listInstances, listSshIngressRules, printSshRules, resolveRoamingRule, revokeRule, roamingRuleDescription, ruleAlreadyAllowsIp, securityGroupLabel } from "./utils.js";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { ZodError } from "zod";
|
|
8
|
+
//#region src/commands/aws/ec2/allow-ip/handler.js
|
|
9
|
+
/**
|
|
10
|
+
* Resolve which region to operate in: explicit, else default if it has instances,
|
|
11
|
+
* else prompt from the enabled regions.
|
|
12
|
+
* @param {{ profile?: string; region?: string; verbose: boolean }} params
|
|
13
|
+
* @returns {Promise<string>}
|
|
14
|
+
*/
|
|
15
|
+
async function resolveRegion(params) {
|
|
16
|
+
const { profile, region, verbose } = params;
|
|
17
|
+
if (region) return region;
|
|
18
|
+
if (listInstances({
|
|
19
|
+
profile,
|
|
20
|
+
region: "us-east-1",
|
|
21
|
+
verbose
|
|
22
|
+
}).length > 0) return DEFAULT_REGION;
|
|
23
|
+
const regions = listEnabledRegions({
|
|
24
|
+
profile,
|
|
25
|
+
region: DEFAULT_REGION,
|
|
26
|
+
verbose
|
|
27
|
+
});
|
|
28
|
+
if (regions.length === 0) throw new Error("No enabled AWS regions found for this profile");
|
|
29
|
+
console.log(`No EC2 instances found in ${DEFAULT_REGION}.`);
|
|
30
|
+
const chosen = regions[await promptChoice({
|
|
31
|
+
message: "Choose a region:",
|
|
32
|
+
options: regions
|
|
33
|
+
})];
|
|
34
|
+
if (!chosen) throw new Error("No region selected");
|
|
35
|
+
return chosen;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Handle errors from authorize/revoke with the same UX as the original script.
|
|
39
|
+
* Returns when the situation is benign (duplicate); exits the process on a
|
|
40
|
+
* permissions failure; rethrows anything else.
|
|
41
|
+
* @param {AwsCliError} error
|
|
42
|
+
* @param {{
|
|
43
|
+
* securityGroup: import("./utils.js").SecurityGroup;
|
|
44
|
+
* sshRules: import("./utils.js").SshIngressRule[];
|
|
45
|
+
* newCidr: string;
|
|
46
|
+
* ruleDescription: string;
|
|
47
|
+
* action: "create" | "update";
|
|
48
|
+
* }} ctx
|
|
49
|
+
*/
|
|
50
|
+
function handleRuleChangeError(error, ctx) {
|
|
51
|
+
const { securityGroup, sshRules, newCidr, ruleDescription, action } = ctx;
|
|
52
|
+
if (error.code === "InvalidPermission.Duplicate") {
|
|
53
|
+
const matching = ruleAlreadyAllowsIp(sshRules, newCidr);
|
|
54
|
+
const label = matching ? matching.description : ruleDescription;
|
|
55
|
+
console.log(`Security group ${securityGroup.groupId} already allows SSH from ${newCidr} (${label}). Nothing to do.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (error.code === "UnauthorizedOperation") {
|
|
59
|
+
console.error(`Could not ${action} the SSH rule: your AWS profile does not have ec2:AuthorizeSecurityGroupIngress or ec2:RevokeSecurityGroupIngress on ${securityGroup.groupName} (${securityGroup.groupId}).`);
|
|
60
|
+
console.error("");
|
|
61
|
+
console.error("Current single-host SSH rules on port 22:");
|
|
62
|
+
printSshRules(sshRules, (message) => console.error(message));
|
|
63
|
+
if (action === "create" && sshRules.length > 0) {
|
|
64
|
+
console.error("");
|
|
65
|
+
console.error("A rule may already exist. Re-run to update your named roaming rule, or ask an admin to grant security group ingress permissions.");
|
|
66
|
+
}
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `aws ec2 allow-ip` handler: update or create a named roaming SSH rule for the
|
|
73
|
+
* caller's current public IP on a chosen EC2 instance's security group.
|
|
74
|
+
* @param {unknown} options
|
|
75
|
+
*/
|
|
76
|
+
async function allowIpCommand(options) {
|
|
77
|
+
try {
|
|
78
|
+
const { profile: profileOption, region: regionOption, ruleName, verbose } = allowIpOptionsSchema.parse(options);
|
|
79
|
+
const profile = await resolveProfile({ profile: profileOption });
|
|
80
|
+
if (!profile) {
|
|
81
|
+
console.error(chalk.red("Error: pass --profile or set AWS_PROFILE."));
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
requireCommands(["aws"]);
|
|
85
|
+
const identity = getCallerIdentity({
|
|
86
|
+
profile,
|
|
87
|
+
region: DEFAULT_REGION,
|
|
88
|
+
verbose
|
|
89
|
+
});
|
|
90
|
+
const firstName = extractRoamingFirstName({
|
|
91
|
+
profile,
|
|
92
|
+
identity
|
|
93
|
+
});
|
|
94
|
+
const ruleDescription = ruleName ?? roamingRuleDescription(firstName);
|
|
95
|
+
console.log("Caller:");
|
|
96
|
+
console.log(` Account: ${identity.Account}`);
|
|
97
|
+
console.log(` Arn: ${identity.Arn}`);
|
|
98
|
+
console.log(` Roaming rule: ${ruleDescription}`);
|
|
99
|
+
console.log("");
|
|
100
|
+
const region = await resolveRegion({
|
|
101
|
+
profile,
|
|
102
|
+
region: regionOption,
|
|
103
|
+
verbose
|
|
104
|
+
});
|
|
105
|
+
console.log(`Region: ${region}`);
|
|
106
|
+
console.log("");
|
|
107
|
+
const instances = listInstances({
|
|
108
|
+
profile,
|
|
109
|
+
region,
|
|
110
|
+
verbose
|
|
111
|
+
});
|
|
112
|
+
if (instances.length === 0) {
|
|
113
|
+
console.log(`No EC2 instances found in ${region}.`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
const instance = instances[await promptChoice({
|
|
117
|
+
message: "Choose an EC2 instance:",
|
|
118
|
+
options: instances.map((instance) => instanceLabel(instance))
|
|
119
|
+
})];
|
|
120
|
+
if (!instance) throw new Error("No instance selected");
|
|
121
|
+
console.log("");
|
|
122
|
+
const securityGroups = describeSecurityGroups({
|
|
123
|
+
profile,
|
|
124
|
+
region,
|
|
125
|
+
groupIds: instance.securityGroupIds,
|
|
126
|
+
verbose
|
|
127
|
+
});
|
|
128
|
+
if (securityGroups.length === 0) {
|
|
129
|
+
console.log("No security groups found on the selected instance.");
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
let securityGroup;
|
|
133
|
+
if (securityGroups.length === 1) {
|
|
134
|
+
const onlyGroup = securityGroups[0];
|
|
135
|
+
if (!onlyGroup) throw new Error("No security group found on the selected instance");
|
|
136
|
+
securityGroup = onlyGroup;
|
|
137
|
+
console.log(`Security group: ${securityGroupLabel(securityGroup)}`);
|
|
138
|
+
} else securityGroup = securityGroups[await promptChoice({
|
|
139
|
+
message: "Choose a security group:",
|
|
140
|
+
options: securityGroups.map((group) => securityGroupLabel(group))
|
|
141
|
+
})];
|
|
142
|
+
if (!securityGroup) throw new Error("No security group selected");
|
|
143
|
+
console.log("");
|
|
144
|
+
const currentIp = await getCurrentPublicIp();
|
|
145
|
+
const newCidr = `${currentIp}/32`;
|
|
146
|
+
console.log(`Current public IP: ${currentIp}`);
|
|
147
|
+
console.log("");
|
|
148
|
+
const sgDetails = getSecurityGroupDetails({
|
|
149
|
+
profile,
|
|
150
|
+
region,
|
|
151
|
+
groupId: securityGroup.groupId,
|
|
152
|
+
verbose
|
|
153
|
+
});
|
|
154
|
+
if (!sgDetails) {
|
|
155
|
+
console.log("Could not load security group details.");
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
const sshRules = listSshIngressRules(sgDetails);
|
|
159
|
+
const roamingRule = resolveRoamingRule(sshRules, ruleDescription);
|
|
160
|
+
if (roamingRule && roamingRule.cidrIp === newCidr) {
|
|
161
|
+
console.log(`Security group ${securityGroup.groupId} already allows SSH from ${newCidr} (${ruleDescription}). Nothing to do.`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const otherRuleAtIp = ruleAlreadyAllowsIp(sshRules, newCidr);
|
|
165
|
+
if (otherRuleAtIp && (!roamingRule || otherRuleAtIp.cidrIp !== roamingRule.cidrIp)) {
|
|
166
|
+
const label = otherRuleAtIp.description || "(no description)";
|
|
167
|
+
console.log(`Security group ${securityGroup.groupId} already allows SSH from ${newCidr} (${label}). Nothing to do.`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (roamingRule) {
|
|
171
|
+
console.log(`Updating SSH rule (${ruleDescription}): ${roamingRule.cidrIp} -> ${newCidr}`);
|
|
172
|
+
try {
|
|
173
|
+
revokeRule({
|
|
174
|
+
profile,
|
|
175
|
+
region,
|
|
176
|
+
groupId: securityGroup.groupId,
|
|
177
|
+
rule: roamingRule,
|
|
178
|
+
verbose
|
|
179
|
+
});
|
|
180
|
+
authorizeRule({
|
|
181
|
+
profile,
|
|
182
|
+
region,
|
|
183
|
+
groupId: securityGroup.groupId,
|
|
184
|
+
cidrIp: newCidr,
|
|
185
|
+
description: ruleDescription,
|
|
186
|
+
fromPort: roamingRule.fromPort,
|
|
187
|
+
toPort: roamingRule.toPort,
|
|
188
|
+
ipProtocol: roamingRule.ipProtocol,
|
|
189
|
+
verbose
|
|
190
|
+
});
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (error instanceof AwsCliError) {
|
|
193
|
+
handleRuleChangeError(error, {
|
|
194
|
+
securityGroup,
|
|
195
|
+
sshRules,
|
|
196
|
+
newCidr,
|
|
197
|
+
ruleDescription,
|
|
198
|
+
action: "update"
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
if (sshRules.length > 0) {
|
|
206
|
+
console.log("Existing single-host SSH rules (unchanged):");
|
|
207
|
+
printSshRules(sshRules);
|
|
208
|
+
console.log("");
|
|
209
|
+
}
|
|
210
|
+
console.log(`Creating new "${ruleDescription}" SSH rule for ${newCidr}`);
|
|
211
|
+
try {
|
|
212
|
+
authorizeRule({
|
|
213
|
+
profile,
|
|
214
|
+
region,
|
|
215
|
+
groupId: securityGroup.groupId,
|
|
216
|
+
cidrIp: newCidr,
|
|
217
|
+
description: ruleDescription,
|
|
218
|
+
verbose
|
|
219
|
+
});
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (error instanceof AwsCliError) {
|
|
222
|
+
handleRuleChangeError(error, {
|
|
223
|
+
securityGroup,
|
|
224
|
+
sshRules,
|
|
225
|
+
newCidr,
|
|
226
|
+
ruleDescription,
|
|
227
|
+
action: "create"
|
|
228
|
+
});
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
console.log("");
|
|
235
|
+
console.log(`Done. ${securityGroup.groupName} (${securityGroup.groupId}) now allows SSH from ${newCidr} (${ruleDescription}).`);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error instanceof ZodError) {
|
|
238
|
+
console.error(chalk.red("\n❌ Invalid command options:"));
|
|
239
|
+
error.errors.forEach((err) => {
|
|
240
|
+
console.error(chalk.red(` ${err.path.join(".")}: ${err.message}`));
|
|
241
|
+
});
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
const verbose = options?.verbose || false;
|
|
245
|
+
console.error(chalk.red("\n❌ allow-ip failed:"));
|
|
246
|
+
if (error instanceof Error) {
|
|
247
|
+
console.error(chalk.red(` ${error.message}`));
|
|
248
|
+
if (verbose && error.stack) {
|
|
249
|
+
console.error(chalk.gray("\nStack trace:"));
|
|
250
|
+
console.error(chalk.gray(error.stack));
|
|
251
|
+
}
|
|
252
|
+
} else console.error(chalk.red(` ${String(error)}`));
|
|
253
|
+
console.error(chalk.yellow("\n💡 Use --verbose for detailed error information\n"));
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
export { allowIpCommand };
|
|
@@ -1,55 +1,4 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
authorizeRule,
|
|
7
|
-
describeSecurityGroups,
|
|
8
|
-
extractRoamingFirstName,
|
|
9
|
-
getCurrentPublicIp,
|
|
10
|
-
getSecurityGroupDetails,
|
|
11
|
-
instanceLabel,
|
|
12
|
-
listEnabledRegions,
|
|
13
|
-
listInstances,
|
|
14
|
-
listSshIngressRules,
|
|
15
|
-
printSshRules,
|
|
16
|
-
resolveRoamingRule,
|
|
17
|
-
revokeRule,
|
|
18
|
-
roamingRuleDescription,
|
|
19
|
-
ruleAlreadyAllowsIp,
|
|
20
|
-
securityGroupLabel,
|
|
21
|
-
sshRuleLabel
|
|
22
|
-
} from "../../../../__chunks/U7HAE2RF.js";
|
|
23
|
-
import {
|
|
24
|
-
DEFAULT_REGION,
|
|
25
|
-
DEFAULT_ROAMING_NAME,
|
|
26
|
-
SSH_PORT,
|
|
27
|
-
allowIpOptionsSchema
|
|
28
|
-
} from "../../../../__chunks/J34UVKLA.js";
|
|
29
|
-
import "../../../../__chunks/FNXUONAV.js";
|
|
30
|
-
import "../../../../__chunks/5GIUAFXL.js";
|
|
31
|
-
import "../../../../__chunks/73BJG53F.js";
|
|
32
|
-
import "../../../../__chunks/ZHKVJO2U.js";
|
|
33
|
-
export {
|
|
34
|
-
DEFAULT_REGION,
|
|
35
|
-
DEFAULT_ROAMING_NAME,
|
|
36
|
-
SSH_PORT,
|
|
37
|
-
allowIpCommand,
|
|
38
|
-
allowIpOptionsSchema,
|
|
39
|
-
authorizeRule,
|
|
40
|
-
describeSecurityGroups,
|
|
41
|
-
extractRoamingFirstName,
|
|
42
|
-
getCurrentPublicIp,
|
|
43
|
-
getSecurityGroupDetails,
|
|
44
|
-
instanceLabel,
|
|
45
|
-
listEnabledRegions,
|
|
46
|
-
listInstances,
|
|
47
|
-
listSshIngressRules,
|
|
48
|
-
printSshRules,
|
|
49
|
-
resolveRoamingRule,
|
|
50
|
-
revokeRule,
|
|
51
|
-
roamingRuleDescription,
|
|
52
|
-
ruleAlreadyAllowsIp,
|
|
53
|
-
securityGroupLabel,
|
|
54
|
-
sshRuleLabel
|
|
55
|
-
};
|
|
1
|
+
import { DEFAULT_REGION, DEFAULT_ROAMING_NAME, SSH_PORT, allowIpOptionsSchema } from "./schema.js";
|
|
2
|
+
import { authorizeRule, describeSecurityGroups, extractRoamingFirstName, getCurrentPublicIp, getSecurityGroupDetails, instanceLabel, listEnabledRegions, listInstances, listSshIngressRules, printSshRules, resolveRoamingRule, revokeRule, roamingRuleDescription, ruleAlreadyAllowsIp, securityGroupLabel, sshRuleLabel } from "./utils.js";
|
|
3
|
+
import { allowIpCommand } from "./handler.js";
|
|
4
|
+
export { DEFAULT_REGION, DEFAULT_ROAMING_NAME, SSH_PORT, allowIpCommand, allowIpOptionsSchema, authorizeRule, describeSecurityGroups, extractRoamingFirstName, getCurrentPublicIp, getSecurityGroupDetails, instanceLabel, listEnabledRegions, listInstances, listSshIngressRules, printSshRules, resolveRoamingRule, revokeRule, roamingRuleDescription, ruleAlreadyAllowsIp, securityGroupLabel, sshRuleLabel };
|
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { profileField, regionField, verboseField } from "../../schema.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/commands/aws/ec2/allow-ip/schema.js
|
|
4
|
+
/**
|
|
5
|
+
* Default region checked first before prompting.
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_REGION = "us-east-1";
|
|
8
|
+
/**
|
|
9
|
+
* SSH port managed by this command.
|
|
10
|
+
*/
|
|
11
|
+
const SSH_PORT = 22;
|
|
12
|
+
/**
|
|
13
|
+
* Fallback first name when one cannot be derived from the profile/IAM user.
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_ROAMING_NAME = "Declan";
|
|
16
|
+
/**
|
|
17
|
+
* Zod schema for `aws ec2 allow-ip` options.
|
|
18
|
+
*/
|
|
19
|
+
const allowIpOptionsSchema = z.object({
|
|
20
|
+
profile: profileField,
|
|
21
|
+
region: regionField,
|
|
22
|
+
ruleName: z.string().optional().describe("SSH rule description to update or create (default: \"{FirstName} Roaming\" derived from the profile/IAM user)"),
|
|
23
|
+
verbose: verboseField
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {z.infer<typeof allowIpOptionsSchema>} AllowIpOptions
|
|
27
|
+
*/
|
|
28
|
+
//#endregion
|
|
29
|
+
export { DEFAULT_REGION, DEFAULT_ROAMING_NAME, SSH_PORT, allowIpOptionsSchema };
|