passport-bridge 0.32.1 → 0.35.0
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/README.md +73 -27
- package/dist/awsCommands.d.ts +47 -0
- package/dist/awsCommands.js +371 -0
- package/dist/awsConfig.d.ts +34 -0
- package/dist/awsConfig.js +115 -0
- package/dist/azureCommands.d.ts +54 -0
- package/dist/azureCommands.js +333 -0
- package/dist/cli.js +9 -8
- package/dist/cliActions.d.ts +4 -1
- package/dist/cliActions.js +132 -8
- package/dist/cliActionsLocal.d.ts +38 -0
- package/dist/cliActionsLocal.js +186 -0
- package/dist/cliAllowances.d.ts +3 -3
- package/dist/cliAllowances.js +2 -2
- package/dist/cliAnswered.d.ts +29 -9
- package/dist/cliAnswered.js +59 -19
- package/dist/cliArgs.d.ts +1 -1
- package/dist/cliArgs.js +20 -9
- package/dist/cliAutopilot.d.ts +3 -1
- package/dist/cliAutopilot.js +77 -14
- package/dist/cliAutopilotPolicy.d.ts +41 -6
- package/dist/cliAutopilotPolicy.js +65 -29
- package/dist/cliDescribe.d.ts +2 -2
- package/dist/cliDescribe.js +2 -2
- package/dist/cliExec.d.ts +6 -14
- package/dist/cliExec.js +110 -80
- package/dist/cliGitCredential.d.ts +36 -0
- package/dist/cliGitCredential.js +432 -0
- package/dist/cliGuardHealth.js +3 -1
- package/dist/cliGuardState.d.ts +13 -2
- package/dist/cliGuardState.js +36 -1
- package/dist/cliHook.js +46 -46
- package/dist/cliHookAfter.d.ts +5 -0
- package/dist/cliHookAfter.js +14 -1
- package/dist/cliHookClassify.d.ts +12 -0
- package/dist/cliHookClassify.js +145 -44
- package/dist/cliHookCoverage.d.ts +20 -0
- package/dist/cliHookCoverage.js +139 -0
- package/dist/cliHookCreates.js +128 -3
- package/dist/cliHookDecide.d.ts +14 -53
- package/dist/cliHookDecide.js +187 -168
- package/dist/cliHookDecideRequest.d.ts +48 -0
- package/dist/cliHookDecideRequest.js +69 -0
- package/dist/cliHookDeliver.d.ts +21 -1
- package/dist/cliHookDeliver.js +38 -7
- package/dist/cliHookEarly.d.ts +10 -0
- package/dist/cliHookEarly.js +8 -0
- package/dist/cliHookEnvironment.js +23 -6
- package/dist/cliHookGuard.d.ts +3 -3
- package/dist/cliHookGuard.js +16 -9
- package/dist/cliHookIac.d.ts +32 -0
- package/dist/cliHookIac.js +53 -0
- package/dist/cliHookInput.d.ts +10 -0
- package/dist/cliHookInput.js +12 -0
- package/dist/cliHookInstall.d.ts +12 -4
- package/dist/cliHookInstall.js +54 -75
- package/dist/cliHookLease.js +10 -2
- package/dist/cliHookLinks.d.ts +6 -1
- package/dist/cliHookLinks.js +194 -7
- package/dist/cliHookLocal.d.ts +5 -12
- package/dist/cliHookLocal.js +73 -48
- package/dist/cliHookLocalCode.d.ts +8 -1
- package/dist/cliHookLocalCode.js +14 -0
- package/dist/cliHookLocalFs.d.ts +4 -0
- package/dist/cliHookLocalFs.js +32 -1
- package/dist/cliHookMode.d.ts +3 -0
- package/dist/cliHookMode.js +7 -0
- package/dist/cliHookParse.js +122 -31
- package/dist/cliHookPlace.d.ts +25 -0
- package/dist/cliHookPlace.js +39 -0
- package/dist/cliHookPlan.d.ts +35 -0
- package/dist/cliHookPlan.js +34 -0
- package/dist/cliHookProject.d.ts +13 -2
- package/dist/cliHookProject.js +48 -20
- package/dist/cliHookReach.d.ts +31 -0
- package/dist/cliHookReach.js +84 -0
- package/dist/cliHookRepo.js +29 -8
- package/dist/cliHookRewrite.d.ts +31 -5
- package/dist/cliHookRewrite.js +57 -15
- package/dist/cliHookScripts.d.ts +13 -3
- package/dist/cliHookScripts.js +146 -25
- package/dist/cliHookServerDecision.d.ts +30 -0
- package/dist/cliHookServerDecision.js +85 -0
- package/dist/cliHookSessionEnd.d.ts +29 -1
- package/dist/cliHookSessionEnd.js +79 -10
- package/dist/cliHookSessionState.d.ts +2 -0
- package/dist/cliHookSessionState.js +2 -2
- package/dist/cliHookSettings.d.ts +17 -0
- package/dist/cliHookSettings.js +80 -0
- package/dist/cliHookSpawn.d.ts +6 -6
- package/dist/cliHookSpawn.js +3 -21
- package/dist/cliHookStatus.d.ts +7 -2
- package/dist/cliHookStatus.js +17 -5
- package/dist/cliHookStop.d.ts +37 -0
- package/dist/cliHookStop.js +59 -0
- package/dist/cliHookUncheckedName.d.ts +2 -1
- package/dist/cliHookUncheckedName.js +4 -1
- package/dist/cliHookVendors.js +86 -63
- package/dist/cliHookVendorsGitlab.d.ts +15 -0
- package/dist/cliHookVendorsGitlab.js +95 -0
- package/dist/cliHookVendorsMore.js +117 -1
- package/dist/cliInit.d.ts +5 -1
- package/dist/cliInit.js +18 -11
- package/dist/cliKeys.js +43 -19
- package/dist/cliKeysBack.js +2 -1
- package/dist/cliKeysKeep.js +6 -5
- package/dist/cliKeysRotate.js +16 -4
- package/dist/cliKeysShim.d.ts +1 -1
- package/dist/cliKeysShim.js +3 -2
- package/dist/cliKubeCredential.d.ts +53 -0
- package/dist/cliKubeCredential.js +291 -0
- package/dist/cliLoosening.d.ts +9 -1
- package/dist/cliLoosening.js +36 -10
- package/dist/cliMain.js +41 -65
- package/dist/cliOutput.d.ts +2 -0
- package/dist/cliOutput.js +122 -57
- package/dist/cliPolicy.d.ts +9 -0
- package/dist/cliPolicy.js +24 -3
- package/dist/cliPolicyV2.js +85 -9
- package/dist/cliReady.js +2 -2
- package/dist/cliReceipt.d.ts +18 -0
- package/dist/cliReceipt.js +75 -0
- package/dist/cliRequestTask.d.ts +2 -2
- package/dist/cliRequestTask.js +4 -4
- package/dist/cliScan.d.ts +12 -14
- package/dist/cliScan.js +52 -11
- package/dist/cliScriptRead.js +1 -1
- package/dist/cliScriptText.d.ts +8 -0
- package/dist/cliScriptText.js +32 -4
- package/dist/cliSessions.d.ts +8 -22
- package/dist/cliSessions.js +26 -167
- package/dist/cliSessionsJson.d.ts +8 -199
- package/dist/cliSessionsJson.js +5 -186
- package/dist/cliSessionsRender.d.ts +2 -28
- package/dist/cliSessionsRender.js +9 -196
- package/dist/cliSetupOrg.d.ts +7 -0
- package/dist/cliSetupOrg.js +29 -2
- package/dist/cliSpeed.d.ts +4 -3
- package/dist/cliSpeed.js +7 -6
- package/dist/cliStatus.d.ts +5 -2
- package/dist/cliStatus.js +81 -17
- package/dist/cliStatusGuard.d.ts +14 -2
- package/dist/cliStatusGuard.js +29 -6
- package/dist/cliSupport.d.ts +4 -0
- package/dist/cliSupport.js +5 -1
- package/dist/cliWhere.d.ts +50 -0
- package/dist/cliWhere.js +120 -0
- package/dist/cliWork.d.ts +123 -0
- package/dist/cliWork.js +584 -0
- package/dist/cliWorkWords.d.ts +122 -0
- package/dist/cliWorkWords.js +361 -0
- package/dist/completion.js +12 -5
- package/dist/controlPlane.generated.d.ts +434 -0
- package/dist/controlPlane.generated.js +134 -0
- package/dist/controlPlaneExec.d.ts +68 -0
- package/dist/controlPlaneExec.js +135 -0
- package/dist/controlPlaneGithub.generated.d.ts +45 -0
- package/dist/controlPlaneGithub.generated.js +94 -0
- package/dist/controlPlaneGithubApi.generated.d.ts +15 -0
- package/dist/controlPlaneGithubApi.generated.js +117 -0
- package/dist/controlPlaneGithubCatalog.generated.d.ts +127 -0
- package/dist/controlPlaneGithubCatalog.generated.js +253 -0
- package/dist/controlPlaneGithubCli.generated.d.ts +94 -0
- package/dist/controlPlaneGithubCli.generated.js +287 -0
- package/dist/controlPlaneGithubWebhook.generated.d.ts +30 -0
- package/dist/controlPlaneGithubWebhook.generated.js +105 -0
- package/dist/controlPlaneGuard.d.ts +147 -0
- package/dist/controlPlaneGuard.js +277 -0
- package/dist/controlPlaneLate.d.ts +30 -0
- package/dist/controlPlaneLate.js +72 -0
- package/dist/controlPlaneLateHold.d.ts +20 -0
- package/dist/controlPlaneLateHold.js +101 -0
- package/dist/controlPlaneRailway.generated.d.ts +30 -0
- package/dist/controlPlaneRailway.generated.js +217 -0
- package/dist/controlPlaneRailwayCli.generated.d.ts +11 -0
- package/dist/controlPlaneRailwayCli.generated.js +436 -0
- package/dist/controlPlaneRailwayGuard.d.ts +172 -0
- package/dist/controlPlaneRailwayGuard.js +527 -0
- package/dist/controlPlaneRailwayModel.generated.d.ts +189 -0
- package/dist/controlPlaneRailwayModel.generated.js +355 -0
- package/dist/controlPlaneRailwayReach.d.ts +43 -0
- package/dist/controlPlaneRailwayReach.js +163 -0
- package/dist/credentialStorage.d.ts +3 -0
- package/dist/credentialStorage.js +13 -2
- package/dist/credentials.js +60 -6
- package/dist/designTokens.generated.d.ts +16 -0
- package/dist/designTokens.generated.js +11 -0
- package/dist/doctor.d.ts +4 -0
- package/dist/doctor.js +25 -9
- package/dist/envLinkFs.d.ts +1 -0
- package/dist/envLinkFs.js +7 -1
- package/dist/envLinksAzure.d.ts +34 -0
- package/dist/envLinksAzure.js +179 -0
- package/dist/envLinksCloud.d.ts +19 -6
- package/dist/envLinksCloud.js +84 -74
- package/dist/envLinksGitlab.d.ts +66 -0
- package/dist/envLinksGitlab.js +352 -0
- package/dist/envLinksHosting.d.ts +26 -4
- package/dist/envLinksHosting.js +92 -27
- package/dist/envLinksIac.d.ts +62 -0
- package/dist/envLinksIac.js +267 -0
- package/dist/envResolve.d.ts +12 -1
- package/dist/envResolve.js +57 -9
- package/dist/envTarget.js +10 -1
- package/dist/execAzure.d.ts +79 -0
- package/dist/execAzure.js +280 -0
- package/dist/execBackupAzure.d.ts +14 -0
- package/dist/execBackupAzure.js +49 -0
- package/dist/execBackupGoogle.d.ts +24 -0
- package/dist/execBackupGoogle.js +141 -0
- package/dist/execBackupTarget.d.ts +18 -4
- package/dist/execBackupTarget.js +61 -0
- package/dist/execGit.d.ts +16 -0
- package/dist/execGit.js +31 -0
- package/dist/execGoogle.d.ts +17 -0
- package/dist/execGoogle.js +52 -0
- package/dist/execPlan.d.ts +20 -0
- package/dist/execPlan.js +38 -0
- package/dist/execShims.d.ts +12 -1
- package/dist/execShims.js +87 -6
- package/dist/execSpawn.d.ts +16 -0
- package/dist/execSpawn.js +47 -0
- package/dist/execTarget.d.ts +3 -1
- package/dist/execTarget.js +9 -3
- package/dist/execVendors.d.ts +13 -1
- package/dist/execVendors.js +131 -6
- package/dist/externalLinks.d.ts +1 -1
- package/dist/externalLinks.js +213 -1
- package/dist/firstRun.d.ts +18 -0
- package/dist/firstRun.js +49 -0
- package/dist/gitCredentialSetup.d.ts +91 -0
- package/dist/gitCredentialSetup.js +338 -0
- package/dist/gitInvocation.d.ts +41 -0
- package/dist/gitInvocation.js +207 -0
- package/dist/gitPush.d.ts +27 -0
- package/dist/gitPush.js +172 -0
- package/dist/gitPushDecisions.d.ts +6 -0
- package/dist/gitPushDecisions.js +69 -0
- package/dist/gitReadOnly.d.ts +10 -0
- package/dist/gitReadOnly.js +57 -0
- package/dist/gitRemote.d.ts +15 -0
- package/dist/gitRemote.js +51 -0
- package/dist/hookFastPath.d.ts +4 -1
- package/dist/hookFastPath.js +9 -6
- package/dist/hookMain.js +1 -1
- package/dist/hookOutbox.d.ts +2 -0
- package/dist/hookOutbox.js +6 -2
- package/dist/hookPromptFast.d.ts +3 -2
- package/dist/hookPromptFast.js +16 -4
- package/dist/hookRepair.d.ts +34 -0
- package/dist/hookRepair.js +69 -0
- package/dist/iacPlan.d.ts +75 -0
- package/dist/iacPlan.js +384 -0
- package/dist/iacPlanRead.d.ts +88 -0
- package/dist/iacPlanRead.js +341 -0
- package/dist/iacPlanStore.d.ts +43 -0
- package/dist/iacPlanStore.js +139 -0
- package/dist/initAutopilotStep.d.ts +2 -1
- package/dist/initAutopilotStep.js +23 -11
- package/dist/initInstall.js +5 -5
- package/dist/initKeysStep.d.ts +6 -0
- package/dist/initKeysStep.js +43 -3
- package/dist/initLocalSteps.d.ts +6 -0
- package/dist/initLocalSteps.js +23 -1
- package/dist/initPlan.js +7 -0
- package/dist/initUi.d.ts +1 -1
- package/dist/initUi.js +1 -1
- package/dist/keysAzure.d.ts +14 -0
- package/dist/keysAzure.js +23 -0
- package/dist/keysHere.d.ts +35 -0
- package/dist/keysHere.js +89 -0
- package/dist/keysLocal.d.ts +12 -1
- package/dist/keysLocal.js +10 -1
- package/dist/keysLocalGoogle.d.ts +83 -0
- package/dist/keysLocalGoogle.js +354 -0
- package/dist/keysReport.d.ts +16 -3
- package/dist/keysReport.js +19 -10
- package/dist/kubeBackup.d.ts +78 -0
- package/dist/kubeBackup.js +261 -0
- package/dist/kubeCommand.d.ts +54 -0
- package/dist/kubeCommand.js +529 -0
- package/dist/kubeRollout.d.ts +18 -0
- package/dist/kubeRollout.js +2 -0
- package/dist/kubeWatch.d.ts +138 -0
- package/dist/kubeWatch.js +513 -0
- package/dist/kubeconfig.d.ts +59 -0
- package/dist/kubeconfig.js +304 -0
- package/dist/launcherFastPath.d.ts +3 -2
- package/dist/launcherFastPath.js +10 -3
- package/dist/leaseCommands.d.ts +1 -1
- package/dist/leaseCommands.js +141 -8
- package/dist/localBackups.d.ts +10 -0
- package/dist/localBackups.js +46 -6
- package/dist/localBackupsGate.d.ts +22 -4
- package/dist/localBackupsGate.js +32 -4
- package/dist/localCommands.d.ts +6 -4
- package/dist/localCommands.js +46 -7
- package/dist/localGit.d.ts +4 -3
- package/dist/localGit.js +7 -4
- package/dist/localReach.d.ts +17 -4
- package/dist/localReach.js +123 -4
- package/dist/localRestore.d.ts +1 -1
- package/dist/localRestore.js +13 -0
- package/dist/localTools.js +29 -2
- package/dist/nativeSync.js +1 -1
- package/dist/nodeVersion.d.ts +13 -6
- package/dist/nodeVersion.js +15 -8
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/railwayDecisions.d.ts +12 -0
- package/dist/railwayDecisions.js +112 -0
- package/dist/recommendedPolicy.d.ts +13 -0
- package/dist/recommendedPolicy.generated.d.ts +1 -0
- package/dist/recommendedPolicy.generated.js +1589 -0
- package/dist/recommendedPolicy.js +6 -0
- package/dist/regenerable.d.ts +37 -13
- package/dist/regenerable.js +133 -40
- package/dist/repoCheckouts.d.ts +40 -0
- package/dist/repoCheckouts.js +113 -0
- package/dist/scanSignedIn.d.ts +39 -0
- package/dist/scanSignedIn.js +85 -0
- package/dist/sessionBrief.d.ts +2 -1
- package/dist/sessionBrief.js +6 -3
- package/dist/sessionCreated.d.ts +24 -0
- package/dist/sessionCreated.js +80 -0
- package/dist/signInFailure.js +6 -1
- package/dist/statusKeys.d.ts +31 -0
- package/dist/statusKeys.js +48 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/waitingLine.d.ts +2 -2
- package/dist/waitingLine.js +2 -2
- package/dist/watchNotice.d.ts +5 -1
- package/dist/watchNotice.js +19 -6
- package/npm-shrinkwrap.json +3 -3
- package/package.json +2 -2
- package/dist/cliChanges.d.ts +0 -97
- package/dist/cliChanges.js +0 -382
- package/dist/cliProjectSummary.d.ts +0 -9
- package/dist/cliProjectSummary.js +0 -145
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AWS pack's reading of an `aws` command (docs/design/production-map.md,
|
|
3
|
+
* AWS): which service and operation it is once the CLI's own options are set
|
|
4
|
+
* aside, the resource it names, what it does in plain words ("delete RDS
|
|
5
|
+
* database acme-db in us-east-1"), and the console page for that resource.
|
|
6
|
+
*
|
|
7
|
+
* Pure and dependency-free: bridge/src/awsCommands.ts is a word-for-word copy
|
|
8
|
+
* (the CLI is published on its own), and a bridge test holds them equal.
|
|
9
|
+
* Names and ids only; a value after any other flag is never read.
|
|
10
|
+
*/
|
|
11
|
+
/** The AWS CLI's own options that take a value, wherever they sit. */
|
|
12
|
+
const GLOBAL_VALUE_OPTIONS = new Set([
|
|
13
|
+
"--profile",
|
|
14
|
+
"--region",
|
|
15
|
+
"--output",
|
|
16
|
+
"--query",
|
|
17
|
+
"--endpoint-url",
|
|
18
|
+
"--cli-read-timeout",
|
|
19
|
+
"--cli-connect-timeout",
|
|
20
|
+
"--ca-bundle",
|
|
21
|
+
"--color",
|
|
22
|
+
"--cli-binary-format"
|
|
23
|
+
]);
|
|
24
|
+
function optionValue(args, index) {
|
|
25
|
+
const arg = args[index];
|
|
26
|
+
const eq = arg.indexOf("=");
|
|
27
|
+
if (eq > 0)
|
|
28
|
+
return { name: arg.slice(0, eq), value: arg.slice(eq + 1), width: 1 };
|
|
29
|
+
const next = args[index + 1];
|
|
30
|
+
return { name: arg, ...(next !== undefined && !next.startsWith("--") ? { value: next } : {}), width: 2 };
|
|
31
|
+
}
|
|
32
|
+
/** `aws --profile prod rds delete-db-instance …` → rds, delete-db-instance. */
|
|
33
|
+
export function parseAwsCommand(args) {
|
|
34
|
+
const words = [];
|
|
35
|
+
const rest = [];
|
|
36
|
+
let profile;
|
|
37
|
+
let region;
|
|
38
|
+
for (let index = 0; index < args.length; index++) {
|
|
39
|
+
const arg = args[index];
|
|
40
|
+
if (arg.startsWith("--") && GLOBAL_VALUE_OPTIONS.has(arg.split("=")[0])) {
|
|
41
|
+
const option = optionValue(args, index);
|
|
42
|
+
if (option.name === "--profile" && option.value)
|
|
43
|
+
profile = option.value;
|
|
44
|
+
if (option.name === "--region" && option.value)
|
|
45
|
+
region = option.value;
|
|
46
|
+
index += option.value !== undefined ? option.width - 1 : 0;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (words.length < 2) {
|
|
50
|
+
if (!arg.startsWith("-"))
|
|
51
|
+
words.push(arg.toLowerCase());
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
rest.push(arg);
|
|
55
|
+
}
|
|
56
|
+
if (!words[0])
|
|
57
|
+
return undefined;
|
|
58
|
+
return {
|
|
59
|
+
service: words[0],
|
|
60
|
+
operation: words[1] ?? "",
|
|
61
|
+
rest,
|
|
62
|
+
...(profile ? { profile } : {}),
|
|
63
|
+
...(region && /^[a-z]{2}(?:-gov)?-[a-z]+-\d$/.test(region) ? { region } : {})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The value of one of the operation's own flags (`--table-name orders`). */
|
|
67
|
+
export function awsFlag(rest, names) {
|
|
68
|
+
for (let index = 0; index < rest.length; index++) {
|
|
69
|
+
const arg = rest[index];
|
|
70
|
+
for (const name of names) {
|
|
71
|
+
if (arg === name) {
|
|
72
|
+
const next = rest[index + 1];
|
|
73
|
+
if (next !== undefined && !next.startsWith("--"))
|
|
74
|
+
return next;
|
|
75
|
+
}
|
|
76
|
+
if (arg.startsWith(`${name}=`))
|
|
77
|
+
return arg.slice(name.length + 1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
/** Whether one of the operation's own switches is on (`--skip-final-snapshot`). */
|
|
83
|
+
export function awsSwitch(rest, name) {
|
|
84
|
+
return rest.includes(name);
|
|
85
|
+
}
|
|
86
|
+
/** A name or id a person reads: no paths beyond a bucket key, no quotes, short. */
|
|
87
|
+
const SAFE_NAME = /^[A-Za-z0-9][A-Za-z0-9._:/@+=-]{0,199}$/;
|
|
88
|
+
function safeName(value) {
|
|
89
|
+
if (!value)
|
|
90
|
+
return undefined;
|
|
91
|
+
// An ARN or queue URL names the thing in its last part.
|
|
92
|
+
const last = /^(?:arn:|https:\/\/)/.test(value) ? value.split(/[:/]/).filter(Boolean).pop() : value;
|
|
93
|
+
return last && SAFE_NAME.test(last) && !/^(?:AKIA|ASIA)[A-Z0-9]{12,}$/.test(last) ? last : undefined;
|
|
94
|
+
}
|
|
95
|
+
/** `s3://bucket/prefix` → bucket and key. */
|
|
96
|
+
export function s3Path(rest) {
|
|
97
|
+
const path = rest.find((arg) => arg.startsWith("s3://"));
|
|
98
|
+
const match = path ? /^s3:\/\/([a-z0-9][a-z0-9.-]{1,61}[a-z0-9])(?:\/(.*))?$/.exec(path) : null;
|
|
99
|
+
return match ? { bucket: match[1], key: match[2] ?? "" } : undefined;
|
|
100
|
+
}
|
|
101
|
+
/** What a service is called in plain words. */
|
|
102
|
+
export const AWS_SERVICE_NAMES = {
|
|
103
|
+
rds: "RDS",
|
|
104
|
+
s3: "S3",
|
|
105
|
+
s3api: "S3",
|
|
106
|
+
ec2: "EC2",
|
|
107
|
+
ecs: "ECS",
|
|
108
|
+
eks: "EKS",
|
|
109
|
+
lambda: "Lambda",
|
|
110
|
+
cloudformation: "CloudFormation",
|
|
111
|
+
dynamodb: "DynamoDB",
|
|
112
|
+
iam: "IAM",
|
|
113
|
+
route53: "Route 53",
|
|
114
|
+
secretsmanager: "Secrets Manager",
|
|
115
|
+
elasticache: "ElastiCache",
|
|
116
|
+
sqs: "SQS",
|
|
117
|
+
sns: "SNS",
|
|
118
|
+
sts: "STS",
|
|
119
|
+
logs: "CloudWatch Logs",
|
|
120
|
+
cloudwatch: "CloudWatch",
|
|
121
|
+
ssm: "Systems Manager",
|
|
122
|
+
elbv2: "Load Balancing",
|
|
123
|
+
ecr: "ECR"
|
|
124
|
+
};
|
|
125
|
+
const PHRASES = {
|
|
126
|
+
"rds delete-db-instance": ["delete RDS database {}", ["--db-instance-identifier"]],
|
|
127
|
+
"rds delete-db-cluster": ["delete Aurora cluster {}", ["--db-cluster-identifier"]],
|
|
128
|
+
"rds create-db-instance": ["create RDS database {}", ["--db-instance-identifier"]],
|
|
129
|
+
"rds modify-db-instance": ["change RDS database {}", ["--db-instance-identifier"]],
|
|
130
|
+
"rds reboot-db-instance": ["restart RDS database {}", ["--db-instance-identifier"]],
|
|
131
|
+
"rds stop-db-instance": ["stop RDS database {}", ["--db-instance-identifier"]],
|
|
132
|
+
"rds start-db-instance": ["start RDS database {}", ["--db-instance-identifier"]],
|
|
133
|
+
"rds create-db-snapshot": ["snapshot RDS database {}", ["--db-instance-identifier"]],
|
|
134
|
+
"rds delete-db-snapshot": ["delete RDS snapshot {}", ["--db-snapshot-identifier"]],
|
|
135
|
+
"rds restore-db-instance-from-db-snapshot": ["restore RDS database {}", ["--db-instance-identifier"]],
|
|
136
|
+
"rds describe-db-instances": ["list RDS databases", []],
|
|
137
|
+
"s3api delete-bucket": ["delete S3 bucket {}", ["--bucket"]],
|
|
138
|
+
"s3api create-bucket": ["create S3 bucket {}", ["--bucket"]],
|
|
139
|
+
"s3api delete-object": ["delete an object in S3 bucket {}", ["--bucket"]],
|
|
140
|
+
"s3api put-bucket-policy": ["change who can reach S3 bucket {}", ["--bucket"]],
|
|
141
|
+
"s3api put-public-access-block": ["change public access to S3 bucket {}", ["--bucket"]],
|
|
142
|
+
"ec2 terminate-instances": ["terminate EC2 instance {}", ["--instance-ids"]],
|
|
143
|
+
"ec2 run-instances": ["launch an EC2 instance", []],
|
|
144
|
+
"ec2 stop-instances": ["stop EC2 instance {}", ["--instance-ids"]],
|
|
145
|
+
"ec2 start-instances": ["start EC2 instance {}", ["--instance-ids"]],
|
|
146
|
+
"ec2 reboot-instances": ["restart EC2 instance {}", ["--instance-ids"]],
|
|
147
|
+
"ec2 delete-volume": ["delete EBS volume {}", ["--volume-id"]],
|
|
148
|
+
"ec2 create-volume": ["create an EBS volume", []],
|
|
149
|
+
"ec2 delete-snapshot": ["delete EBS snapshot {}", ["--snapshot-id"]],
|
|
150
|
+
"ec2 create-nat-gateway": ["create a NAT gateway", []],
|
|
151
|
+
"ec2 delete-nat-gateway": ["delete NAT gateway {}", ["--nat-gateway-id"]],
|
|
152
|
+
"ec2 allocate-address": ["reserve an Elastic IP", []],
|
|
153
|
+
"ec2 release-address": ["release Elastic IP {}", ["--allocation-id"]],
|
|
154
|
+
"ec2 delete-security-group": ["delete security group {}", ["--group-id", "--group-name"]],
|
|
155
|
+
"ec2 authorize-security-group-ingress": ["open a port on security group {}", ["--group-id", "--group-name"]],
|
|
156
|
+
"ec2 describe-instances": ["list EC2 instances", []],
|
|
157
|
+
"ecs update-service": ["deploy ECS service {}", ["--service"]],
|
|
158
|
+
"ecs create-service": ["create ECS service {}", ["--service-name"]],
|
|
159
|
+
"ecs delete-service": ["delete ECS service {}", ["--service"]],
|
|
160
|
+
"ecs delete-cluster": ["delete ECS cluster {}", ["--cluster"]],
|
|
161
|
+
"ecs run-task": ["run an ECS task on {}", ["--cluster"]],
|
|
162
|
+
"eks delete-cluster": ["delete EKS cluster {}", ["--name"]],
|
|
163
|
+
"eks create-cluster": ["create EKS cluster {}", ["--name"]],
|
|
164
|
+
"eks update-cluster-version": ["upgrade EKS cluster {}", ["--name"]],
|
|
165
|
+
"eks delete-nodegroup": ["delete EKS node group {}", ["--nodegroup-name"]],
|
|
166
|
+
"eks update-kubeconfig": ["add EKS cluster {} to kubeconfig", ["--name"]],
|
|
167
|
+
"lambda update-function-code": ["deploy Lambda function {}", ["--function-name"]],
|
|
168
|
+
"lambda update-function-configuration": ["change Lambda function {}", ["--function-name"]],
|
|
169
|
+
"lambda create-function": ["create Lambda function {}", ["--function-name"]],
|
|
170
|
+
"lambda delete-function": ["delete Lambda function {}", ["--function-name"]],
|
|
171
|
+
"lambda invoke": ["invoke Lambda function {}", ["--function-name"]],
|
|
172
|
+
"lambda list-functions": ["list Lambda functions", []],
|
|
173
|
+
"cloudformation deploy": ["deploy CloudFormation stack {}", ["--stack-name"]],
|
|
174
|
+
"cloudformation create-stack": ["create CloudFormation stack {}", ["--stack-name"]],
|
|
175
|
+
"cloudformation update-stack": ["update CloudFormation stack {}", ["--stack-name"]],
|
|
176
|
+
"cloudformation delete-stack": ["delete CloudFormation stack {}", ["--stack-name"]],
|
|
177
|
+
"cloudformation execute-change-set": ["apply a change set to stack {}", ["--stack-name"]],
|
|
178
|
+
"cloudformation describe-stacks": ["read CloudFormation stack {}", ["--stack-name"]],
|
|
179
|
+
"dynamodb delete-table": ["delete DynamoDB table {}", ["--table-name"]],
|
|
180
|
+
"dynamodb create-table": ["create DynamoDB table {}", ["--table-name"]],
|
|
181
|
+
"dynamodb update-table": ["change DynamoDB table {}", ["--table-name"]],
|
|
182
|
+
"dynamodb put-item": ["write an item to DynamoDB table {}", ["--table-name"]],
|
|
183
|
+
"dynamodb delete-item": ["delete an item from DynamoDB table {}", ["--table-name"]],
|
|
184
|
+
"dynamodb batch-write-item": ["write items to DynamoDB", []],
|
|
185
|
+
"dynamodb create-backup": ["back up DynamoDB table {}", ["--table-name"]],
|
|
186
|
+
"dynamodb scan": ["read every item in DynamoDB table {}", ["--table-name"]],
|
|
187
|
+
"dynamodb query": ["query DynamoDB table {}", ["--table-name"]],
|
|
188
|
+
"iam delete-role": ["delete IAM role {}", ["--role-name"]],
|
|
189
|
+
"iam delete-user": ["delete IAM user {}", ["--user-name"]],
|
|
190
|
+
"iam delete-policy": ["delete IAM policy {}", ["--policy-arn"]],
|
|
191
|
+
"iam delete-access-key": ["delete an access key of {}", ["--user-name"]],
|
|
192
|
+
"iam create-access-key": ["create an access key for {}", ["--user-name"]],
|
|
193
|
+
"iam attach-role-policy": ["grant IAM role {} a policy", ["--role-name"]],
|
|
194
|
+
"iam put-role-policy": ["grant IAM role {} a policy", ["--role-name"]],
|
|
195
|
+
"iam detach-role-policy": ["take a policy from IAM role {}", ["--role-name"]],
|
|
196
|
+
"iam update-assume-role-policy": ["change who can use IAM role {}", ["--role-name"]],
|
|
197
|
+
"iam create-role": ["create IAM role {}", ["--role-name"]],
|
|
198
|
+
"iam create-user": ["create IAM user {}", ["--user-name"]],
|
|
199
|
+
"route53 change-resource-record-sets": ["change DNS records in hosted zone {}", ["--hosted-zone-id"]],
|
|
200
|
+
"route53 delete-hosted-zone": ["delete hosted zone {}", ["--id"]],
|
|
201
|
+
"secretsmanager get-secret-value": ["read secret {}", ["--secret-id"]],
|
|
202
|
+
"secretsmanager put-secret-value": ["change secret {}", ["--secret-id"]],
|
|
203
|
+
"secretsmanager update-secret": ["change secret {}", ["--secret-id"]],
|
|
204
|
+
"secretsmanager delete-secret": ["delete secret {}", ["--secret-id"]],
|
|
205
|
+
"secretsmanager create-secret": ["create secret {}", ["--name"]],
|
|
206
|
+
"elasticache delete-cache-cluster": ["delete ElastiCache cluster {}", ["--cache-cluster-id"]],
|
|
207
|
+
"elasticache delete-replication-group": ["delete ElastiCache cluster {}", ["--replication-group-id"]],
|
|
208
|
+
"elasticache create-cache-cluster": ["create ElastiCache cluster {}", ["--cache-cluster-id"]],
|
|
209
|
+
"elasticache create-replication-group": ["create ElastiCache cluster {}", ["--replication-group-id"]],
|
|
210
|
+
"sqs delete-queue": ["delete SQS queue {}", ["--queue-url"]],
|
|
211
|
+
"sqs purge-queue": ["empty SQS queue {}", ["--queue-url"]],
|
|
212
|
+
"sqs send-message": ["send a message to SQS queue {}", ["--queue-url"]],
|
|
213
|
+
"sns delete-topic": ["delete SNS topic {}", ["--topic-arn"]],
|
|
214
|
+
"sns publish": ["publish to SNS topic {}", ["--topic-arn"]],
|
|
215
|
+
"elbv2 create-load-balancer": ["create load balancer {}", ["--name"]],
|
|
216
|
+
"elbv2 delete-load-balancer": ["delete a load balancer", []],
|
|
217
|
+
"logs delete-log-group": ["delete log group {}", ["--log-group-name"]],
|
|
218
|
+
"sts get-caller-identity": ["check which AWS account this is", []]
|
|
219
|
+
};
|
|
220
|
+
function s3Phrase(command) {
|
|
221
|
+
const path = s3Path(command.rest);
|
|
222
|
+
const bucket = path?.bucket;
|
|
223
|
+
const recursive = awsSwitch(command.rest, "--recursive");
|
|
224
|
+
switch (command.operation) {
|
|
225
|
+
case "rb":
|
|
226
|
+
return bucket
|
|
227
|
+
? `delete S3 bucket ${bucket}${awsSwitch(command.rest, "--force") ? " and everything in it" : ""}`
|
|
228
|
+
: "delete an S3 bucket";
|
|
229
|
+
case "mb":
|
|
230
|
+
return bucket ? `create S3 bucket ${bucket}` : "create an S3 bucket";
|
|
231
|
+
case "rm":
|
|
232
|
+
if (!path)
|
|
233
|
+
return "delete files in S3";
|
|
234
|
+
if (recursive)
|
|
235
|
+
return path.key
|
|
236
|
+
? `delete everything under ${path.key} in S3 bucket ${bucket}`
|
|
237
|
+
: `delete everything in S3 bucket ${bucket}`;
|
|
238
|
+
return `delete a file in S3 bucket ${bucket}`;
|
|
239
|
+
case "cp":
|
|
240
|
+
case "mv":
|
|
241
|
+
case "sync": {
|
|
242
|
+
const verb = command.operation === "cp" ? "copy" : command.operation === "mv" ? "move" : "sync";
|
|
243
|
+
// The S3 path last means files go up to the bucket.
|
|
244
|
+
const last = command.rest.filter((arg) => !arg.startsWith("-")).pop();
|
|
245
|
+
const up = last?.startsWith("s3://");
|
|
246
|
+
return bucket ? `${verb} files ${up ? "to" : "from"} S3 bucket ${bucket}` : `${verb} files in S3`;
|
|
247
|
+
}
|
|
248
|
+
case "ls":
|
|
249
|
+
return bucket ? `list S3 bucket ${bucket}` : "list S3 buckets";
|
|
250
|
+
case "presign":
|
|
251
|
+
return bucket ? `share a link to a file in S3 bucket ${bucket}` : "share a link to an S3 file";
|
|
252
|
+
default:
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/** `ec2 terminate-instances --instance-ids i-1 i-2`: every id it names. */
|
|
257
|
+
export function instanceIds(command) {
|
|
258
|
+
if (command.service !== "ec2")
|
|
259
|
+
return [];
|
|
260
|
+
const start = command.rest.indexOf("--instance-ids");
|
|
261
|
+
if (start < 0)
|
|
262
|
+
return [];
|
|
263
|
+
const ids = [];
|
|
264
|
+
for (const arg of command.rest.slice(start + 1)) {
|
|
265
|
+
if (arg.startsWith("--"))
|
|
266
|
+
break;
|
|
267
|
+
ids.push(...arg.split(",").filter((id) => /^i-[0-9a-f]{8,17}$/.test(id)));
|
|
268
|
+
}
|
|
269
|
+
return ids;
|
|
270
|
+
}
|
|
271
|
+
/** The resource a command names, by its service's own words: an RDS
|
|
272
|
+
* database id, a table name, a stack name, a bucket. */
|
|
273
|
+
export function awsResource(command) {
|
|
274
|
+
if (command.service === "s3")
|
|
275
|
+
return s3Path(command.rest)?.bucket;
|
|
276
|
+
const phrase = PHRASES[`${command.service} ${command.operation}`];
|
|
277
|
+
if (!phrase)
|
|
278
|
+
return undefined;
|
|
279
|
+
const raw = awsFlag(command.rest, phrase[1]);
|
|
280
|
+
// `--instance-ids i-1 i-2`: the first; the phrase says how many.
|
|
281
|
+
return safeName(raw);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* What an `aws` command does, from the person's side: "delete RDS database
|
|
285
|
+
* acme-db in us-east-1". Undefined when the pack has no words for it; the
|
|
286
|
+
* caller says it the generic way.
|
|
287
|
+
*/
|
|
288
|
+
export function awsActionPhrase(args) {
|
|
289
|
+
const command = parseAwsCommand(args);
|
|
290
|
+
if (!command)
|
|
291
|
+
return undefined;
|
|
292
|
+
let phrase;
|
|
293
|
+
if (command.service === "s3")
|
|
294
|
+
phrase = s3Phrase(command);
|
|
295
|
+
else {
|
|
296
|
+
const entry = PHRASES[`${command.service} ${command.operation}`];
|
|
297
|
+
if (entry) {
|
|
298
|
+
const name = awsResource(command);
|
|
299
|
+
phrase = name
|
|
300
|
+
? entry[0].replace("{}", name)
|
|
301
|
+
: entry[0].replace(/\s(?:on |of |for |to |in hosted zone )?\{\}/, "");
|
|
302
|
+
const ids = instanceIds(command);
|
|
303
|
+
if (ids.length > 1)
|
|
304
|
+
phrase = phrase.replace(/EC2 instance(?: \S+)?/, `${ids.length} EC2 instances`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (!phrase) {
|
|
308
|
+
const service = AWS_SERVICE_NAMES[command.service];
|
|
309
|
+
if (!service || !command.operation)
|
|
310
|
+
return undefined;
|
|
311
|
+
phrase = `${command.operation.replace(/-/g, " ")} in ${service}`;
|
|
312
|
+
}
|
|
313
|
+
return command.region ? `${phrase} in ${command.region}` : phrase;
|
|
314
|
+
}
|
|
315
|
+
/** Commands whose floor is the flag that removes the safety net. */
|
|
316
|
+
export function awsVerbKey(args) {
|
|
317
|
+
const command = parseAwsCommand(args);
|
|
318
|
+
if (!command)
|
|
319
|
+
return undefined;
|
|
320
|
+
const verb = `${command.service} ${command.operation}`;
|
|
321
|
+
if ((verb === "rds delete-db-instance" || verb === "rds delete-db-cluster") &&
|
|
322
|
+
awsSwitch(command.rest, "--skip-final-snapshot")) {
|
|
323
|
+
return `${verb} --skip-final-snapshot`;
|
|
324
|
+
}
|
|
325
|
+
if (verb === "s3 rb" && awsSwitch(command.rest, "--force"))
|
|
326
|
+
return "s3 rb --force";
|
|
327
|
+
if (verb === "s3 rm" && awsSwitch(command.rest, "--recursive"))
|
|
328
|
+
return "s3 rm --recursive";
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
const REGION = /^[a-z]{2}(?:-gov)?-[a-z]+-\d$/;
|
|
332
|
+
const CONSOLE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
333
|
+
/** The console page for what a command acts on, when the pack knows one.
|
|
334
|
+
* Built only from names that pass CONSOLE_NAME; externalLinks.ts checks it again. */
|
|
335
|
+
export function awsConsoleUrl(args, fallbackRegion) {
|
|
336
|
+
const command = parseAwsCommand(args);
|
|
337
|
+
if (!command)
|
|
338
|
+
return undefined;
|
|
339
|
+
const region = command.region ?? (fallbackRegion && REGION.test(fallbackRegion) ? fallbackRegion : undefined);
|
|
340
|
+
const name = awsResource(command);
|
|
341
|
+
const host = region ? `https://${region}.console.aws.amazon.com` : undefined;
|
|
342
|
+
const q = region ? `?region=${region}` : "";
|
|
343
|
+
if (command.service === "s3" || command.service === "s3api") {
|
|
344
|
+
const bucket = command.service === "s3" ? name : safeName(awsFlag(command.rest, ["--bucket"]));
|
|
345
|
+
return bucket && CONSOLE_NAME.test(bucket)
|
|
346
|
+
? `https://s3.console.aws.amazon.com/s3/buckets/${bucket}${q}`
|
|
347
|
+
: undefined;
|
|
348
|
+
}
|
|
349
|
+
if (!host || !name || !CONSOLE_NAME.test(name))
|
|
350
|
+
return undefined;
|
|
351
|
+
switch (command.service) {
|
|
352
|
+
case "rds":
|
|
353
|
+
return /db-instance/.test(command.operation) ? `${host}/rds/home${q}#database:id=${name}` : undefined;
|
|
354
|
+
case "dynamodb":
|
|
355
|
+
return `${host}/dynamodbv2/home${q}#table?name=${name}`;
|
|
356
|
+
case "lambda":
|
|
357
|
+
return `${host}/lambda/home${q}#/functions/${name}`;
|
|
358
|
+
case "cloudformation":
|
|
359
|
+
return `${host}/cloudformation/home${q}#/stacks/stackinfo?stackId=${name}`;
|
|
360
|
+
case "ecs": {
|
|
361
|
+
const cluster = safeName(awsFlag(command.rest, ["--cluster"]));
|
|
362
|
+
return cluster && CONSOLE_NAME.test(cluster) && command.operation.endsWith("-service")
|
|
363
|
+
? `${host}/ecs/v2/clusters/${cluster}/services/${name}${q}`
|
|
364
|
+
: undefined;
|
|
365
|
+
}
|
|
366
|
+
case "ec2":
|
|
367
|
+
return /^i-[0-9a-f]{8,17}$/.test(name) ? `${host}/ec2/home${q}#InstanceDetails:instanceId=${name}` : undefined;
|
|
368
|
+
default:
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AWS CLI's profiles (production map, AWS pack): which account and region
|
|
3
|
+
* a profile reaches, read from `~/.aws/config` the way the CLI reads it
|
|
4
|
+
* (`AWS_CONFIG_FILE` first). Only `sso_account_id`, the account in
|
|
5
|
+
* `role_arn` (following `source_profile` for neither), `region`, and the
|
|
6
|
+
* profile's name are kept; keys, session names, role names and every other
|
|
7
|
+
* line are never read past their name.
|
|
8
|
+
*
|
|
9
|
+
* Read only for AWS commands, bounded, and kept for this process while the
|
|
10
|
+
* file's size and modification time stay the same, so a chain of `aws`
|
|
11
|
+
* commands reads it once.
|
|
12
|
+
*/
|
|
13
|
+
import { type LinkFs } from "./envLinkFs.js";
|
|
14
|
+
export type AwsProfile = {
|
|
15
|
+
name: string;
|
|
16
|
+
/** The 12-digit account the profile acts in, when the file says. */
|
|
17
|
+
account?: string;
|
|
18
|
+
region?: string;
|
|
19
|
+
};
|
|
20
|
+
type Section = {
|
|
21
|
+
account?: string;
|
|
22
|
+
region?: string;
|
|
23
|
+
sourceProfile?: string;
|
|
24
|
+
ssoSession?: string;
|
|
25
|
+
};
|
|
26
|
+
/** `[default]`, `[profile name]`, `[sso-session name]`, keyed by kind and name. */
|
|
27
|
+
export declare function parseAwsConfig(text: string): Map<string, Section>;
|
|
28
|
+
/** Test seam. */
|
|
29
|
+
export declare function clearAwsConfigCache(): void;
|
|
30
|
+
/** Where the CLI reads its config: `AWS_CONFIG_FILE`, else ~/.aws/config. */
|
|
31
|
+
export declare function awsConfigPath(home: string, env: Record<string, string | undefined>): string;
|
|
32
|
+
/** One profile's account and region; just its name when the file says nothing. */
|
|
33
|
+
export declare function awsProfile(fs: LinkFs, home: string, env: Record<string, string | undefined>, name: string): AwsProfile | "unreadable";
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AWS CLI's profiles (production map, AWS pack): which account and region
|
|
3
|
+
* a profile reaches, read from `~/.aws/config` the way the CLI reads it
|
|
4
|
+
* (`AWS_CONFIG_FILE` first). Only `sso_account_id`, the account in
|
|
5
|
+
* `role_arn` (following `source_profile` for neither), `region`, and the
|
|
6
|
+
* profile's name are kept; keys, session names, role names and every other
|
|
7
|
+
* line are never read past their name.
|
|
8
|
+
*
|
|
9
|
+
* Read only for AWS commands, bounded, and kept for this process while the
|
|
10
|
+
* file's size and modification time stay the same, so a chain of `aws`
|
|
11
|
+
* commands reads it once.
|
|
12
|
+
*/
|
|
13
|
+
import { posix } from "node:path";
|
|
14
|
+
import { GLOBAL_FILE_MAX, readLinkFile } from "./envLinkFs.js";
|
|
15
|
+
const ACCOUNT = /^\d{12}$/;
|
|
16
|
+
const REGION = /^[a-z]{2}(?:-gov)?-[a-z]+-\d$/;
|
|
17
|
+
const ROLE_ACCOUNT = /^arn:aws[a-z-]*:iam::(\d{12}):role\//;
|
|
18
|
+
const NAME = /^[A-Za-z0-9._@+=,-]{1,64}$/;
|
|
19
|
+
/** `[default]`, `[profile name]`, `[sso-session name]`, keyed by kind and name. */
|
|
20
|
+
export function parseAwsConfig(text) {
|
|
21
|
+
const sections = new Map();
|
|
22
|
+
let current;
|
|
23
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
24
|
+
const line = raw.trim();
|
|
25
|
+
if (!line || line.startsWith("#") || line.startsWith(";"))
|
|
26
|
+
continue;
|
|
27
|
+
const header = /^\[\s*([^\]]+?)\s*\]$/.exec(line);
|
|
28
|
+
if (header) {
|
|
29
|
+
const parts = header[1].split(/\s+/);
|
|
30
|
+
const key = parts[0] === "default" && parts.length === 1
|
|
31
|
+
? "profile default"
|
|
32
|
+
: parts.length === 2 && (parts[0] === "profile" || parts[0] === "sso-session") && NAME.test(parts[1])
|
|
33
|
+
? `${parts[0]} ${parts[1]}`
|
|
34
|
+
: undefined;
|
|
35
|
+
current = key ? (sections.get(key) ?? {}) : undefined;
|
|
36
|
+
if (key && current)
|
|
37
|
+
sections.set(key, current);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// Indented lines belong to a nested setting (`s3 =`); never ours.
|
|
41
|
+
if (!current || /^\s/.test(raw))
|
|
42
|
+
continue;
|
|
43
|
+
const pair = /^([a-z_]+)\s*=\s*(.*)$/.exec(line);
|
|
44
|
+
if (!pair)
|
|
45
|
+
continue;
|
|
46
|
+
const [, name, value] = pair;
|
|
47
|
+
const clean = value.trim();
|
|
48
|
+
if (name === "sso_account_id" && ACCOUNT.test(clean))
|
|
49
|
+
current.account = clean;
|
|
50
|
+
else if (name === "role_arn") {
|
|
51
|
+
const account = ROLE_ACCOUNT.exec(clean)?.[1];
|
|
52
|
+
if (account)
|
|
53
|
+
current.account = account;
|
|
54
|
+
}
|
|
55
|
+
else if (name === "region" && REGION.test(clean))
|
|
56
|
+
current.region = clean;
|
|
57
|
+
else if (name === "source_profile" && NAME.test(clean))
|
|
58
|
+
current.sourceProfile = clean;
|
|
59
|
+
else if (name === "sso_session" && NAME.test(clean))
|
|
60
|
+
current.ssoSession = clean;
|
|
61
|
+
}
|
|
62
|
+
return sections;
|
|
63
|
+
}
|
|
64
|
+
function profileOf(sections, name) {
|
|
65
|
+
const own = sections.get(`profile ${name}`);
|
|
66
|
+
let account = own?.account;
|
|
67
|
+
let region = own?.region;
|
|
68
|
+
// A profile without its own account or region takes its source's, a few hops at most.
|
|
69
|
+
let source = own?.sourceProfile;
|
|
70
|
+
for (let hop = 0; hop < 4 && source && (!account || !region); hop++) {
|
|
71
|
+
const next = sections.get(`profile ${source}`);
|
|
72
|
+
account ??= next?.account;
|
|
73
|
+
region ??= next?.region;
|
|
74
|
+
source = next?.sourceProfile;
|
|
75
|
+
}
|
|
76
|
+
if (!region && own?.ssoSession)
|
|
77
|
+
region = sections.get(`sso-session ${own.ssoSession}`)?.region;
|
|
78
|
+
return { name, ...(account ? { account } : {}), ...(region ? { region } : {}) };
|
|
79
|
+
}
|
|
80
|
+
const cache = new Map();
|
|
81
|
+
/** Test seam. */
|
|
82
|
+
export function clearAwsConfigCache() {
|
|
83
|
+
cache.clear();
|
|
84
|
+
}
|
|
85
|
+
/** Where the CLI reads its config: `AWS_CONFIG_FILE`, else ~/.aws/config. */
|
|
86
|
+
export function awsConfigPath(home, env) {
|
|
87
|
+
const set = env.AWS_CONFIG_FILE;
|
|
88
|
+
return set && set.startsWith("/") ? set : posix.join(home, ".aws", "config");
|
|
89
|
+
}
|
|
90
|
+
/** The file's sections, from this process's cache while it hasn't changed. */
|
|
91
|
+
function sectionsOf(fs, path) {
|
|
92
|
+
const stat = fs.lstat(path);
|
|
93
|
+
if (!stat || stat.dir)
|
|
94
|
+
return undefined;
|
|
95
|
+
const known = cache.get(path);
|
|
96
|
+
if (known && known.size === stat.size && known.mtimeMs === stat.mtimeMs)
|
|
97
|
+
return known.sections;
|
|
98
|
+
const read = readLinkFile(fs, path, { max: GLOBAL_FILE_MAX });
|
|
99
|
+
if ("missing" in read)
|
|
100
|
+
return undefined;
|
|
101
|
+
if ("unreadable" in read)
|
|
102
|
+
return "unreadable";
|
|
103
|
+
const sections = parseAwsConfig(read.text);
|
|
104
|
+
if (cache.size > 8)
|
|
105
|
+
cache.clear();
|
|
106
|
+
cache.set(path, { size: stat.size, ...(stat.mtimeMs !== undefined ? { mtimeMs: stat.mtimeMs } : {}), sections });
|
|
107
|
+
return sections;
|
|
108
|
+
}
|
|
109
|
+
/** One profile's account and region; just its name when the file says nothing. */
|
|
110
|
+
export function awsProfile(fs, home, env, name) {
|
|
111
|
+
const sections = sectionsOf(fs, awsConfigPath(home, env));
|
|
112
|
+
if (sections === "unreadable")
|
|
113
|
+
return "unreadable";
|
|
114
|
+
return sections ? profileOf(sections, name) : { name };
|
|
115
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Azure pack's reading of an `az` command (docs/design/production-map.md,
|
|
3
|
+
* Azure): its command words once the options are set aside, how risky it is,
|
|
4
|
+
* the resource it names, what it does in plain words ("delete resource group
|
|
5
|
+
* acme-prod-rg"), and the portal page for that resource.
|
|
6
|
+
*
|
|
7
|
+
* `az` always puts its command words first (`az sql db delete --name x`), so
|
|
8
|
+
* the words are the leading arguments up to the first option, and an option's
|
|
9
|
+
* value is never read as a command word.
|
|
10
|
+
*
|
|
11
|
+
* Pure and dependency-free: bridge/src/azureCommands.ts is a word-for-word
|
|
12
|
+
* copy (the CLI is published on its own), and a bridge test holds them equal.
|
|
13
|
+
* Names and ids only; a value after any other option is never read.
|
|
14
|
+
*/
|
|
15
|
+
export type AzRisk = "read" | "write" | "destructive" | "local" | "api";
|
|
16
|
+
export type AzCommand = {
|
|
17
|
+
/** The command words, lowercased: `["sql", "db", "delete"]`. */
|
|
18
|
+
words: string[];
|
|
19
|
+
/** Everything after the command words, options and all. */
|
|
20
|
+
rest: string[];
|
|
21
|
+
/** `--subscription` (a name or an id), as typed. */
|
|
22
|
+
subscription?: string;
|
|
23
|
+
/** `-g/--resource-group`. */
|
|
24
|
+
resourceGroup?: string;
|
|
25
|
+
};
|
|
26
|
+
/** The value of one of the command's options (`--name acme`, `-n acme`, `--name=acme`). */
|
|
27
|
+
export declare function azOption(rest: readonly string[], names: readonly string[]): string | undefined;
|
|
28
|
+
/** `az --subscription acme-prod group delete -n acme-rg` → group, delete. */
|
|
29
|
+
export declare function parseAzCommand(args: readonly string[]): AzCommand | undefined;
|
|
30
|
+
/** How risky an `az` command is, by its words. */
|
|
31
|
+
export declare function azRisk(command: AzCommand): AzRisk;
|
|
32
|
+
/** `az rest --method delete --url …`: the HTTP method, GET when absent. */
|
|
33
|
+
export declare function azRestMethod(rest: readonly string[]): string;
|
|
34
|
+
/** The verb the hook reports: the command words (`sql db delete`); `az rest`
|
|
35
|
+
* carries its method (`rest DELETE`). */
|
|
36
|
+
export declare function azVerb(command: AzCommand): string;
|
|
37
|
+
/** The resource a command names, by its own options: a database, an app, a group. */
|
|
38
|
+
export declare function azResource(command: AzCommand): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* What an `az` command does, from the person's side: "delete SQL database
|
|
41
|
+
* orders". Undefined when the pack has no words for it; the caller says it
|
|
42
|
+
* the generic way.
|
|
43
|
+
*/
|
|
44
|
+
export declare function azActionPhrase(args: readonly string[]): string | undefined;
|
|
45
|
+
/** Commands whose floor is a switch that removes the safety net. */
|
|
46
|
+
export declare function azVerbKey(args: readonly string[]): string | undefined;
|
|
47
|
+
/** Whether a value is a subscription id (not a subscription name). */
|
|
48
|
+
export declare function isSubscriptionId(value: string | undefined): value is string;
|
|
49
|
+
/** The ARM resource a command acts on, when the pack knows its type:
|
|
50
|
+
* `/subscriptions/<id>/resourceGroups/<rg>/providers/<type>/<name>`. */
|
|
51
|
+
export declare function azResourceId(args: readonly string[], subscription?: string): string | undefined;
|
|
52
|
+
/** The portal page for what a command acts on, when the pack knows one.
|
|
53
|
+
* Built only from names that pass SAFE_NAME; externalLinks.ts checks it again. */
|
|
54
|
+
export declare function azPortalUrl(args: readonly string[], subscription?: string): string | undefined;
|