withfig / autocomplete

IDE-style autocomplete for your existing terminal & shell
https://fig.io
MIT License
24.38k stars 5.4k forks source link

[aws] Update list of AWS regions, and move to centralized file #2266

Closed yaronuliel closed 5 months ago

withfig-bot commented 5 months ago

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

yaronuliel commented 5 months ago

I have read the CLA Document and I hereby sign the CLA

withfig-bot commented 5 months ago

Overview

## src/aws/regions.ts: ### Info: ## src/aws/s3.ts: ### Info: ### Single Functions: **postProcess:** ```typescript function (out, context) { try { return out.split("\n").map((line) => { const parts = line.split(/\s+/); // sub prefix if (!parts.length) { return []; } return { name: _prefixS3 + parts[parts.length - 1], }; }) as Fig.Suggestion[]; } catch (error) { console.error(error); } return []; } ``` **postProcess:** ```typescript function (out) { try { const list = JSON.parse(out)["Keys"]; return list.map((item) => ({ name: item["KeyId"], })); } catch (error) { console.error(error); } return []; } ``` ### URLs: - `http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html` - `http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html` - `http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html` - `http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html` - `http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html` ## src/aws/secretsmanager.ts: ### Info: ### Single Functions: **postProcess:** ```typescript function (out) { try { const list = JSON.parse(out)["SecretList"]; return list.map((item) => ({ name: item["Name"], })); } catch (error) { console.error(error); } return []; } ``` **postProcess:** ```typescript function (out) { try { const list = JSON.parse(out)["Keys"]; return list.map((item) => ({ name: item["KeyId"], })); } catch (error) { console.error(error); } return []; } ``` **postProcess:** ```typescript function (out, tokens) { try { const list = JSON.parse(out)["Keys"]; return list.flatMap((secret) => { return awsRegions.flatMap((region) => { return { name: `Region=${region},KmsKeyId=${secret.KeyId}`, }; }); }); } catch (e) { console.log(e); } return []; } ``` **postProcess:** ```typescript function (out, tokens) { try { const list = JSON.parse(out)["Functions"]; return list.map((item) => ({ name: item["FunctionArn"], })); } catch (e) { console.log(e); } return []; } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { try { // secret-id value const idx = tokens.indexOf("--secret-id"); if (idx < 0) { return []; } const secretId = tokens[idx + 1]; const { stdout } = await executeShellCommand({ command: "aws", args: ["secretsmanager", "describe-secret", "--secret-id", secretId], }); const versions = JSON.parse(stdout)["VersionIdsToStages"]; return Object.keys(versions).map((elm) => ({ name: elm })); } catch (e) { console.log(e); } return []; } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { try { // secret-id value const idx = tokens.indexOf("--secret-id"); if (idx < 0) { return []; } const secretId = tokens[idx + 1]; const { stdout } = await executeShellCommand({ command: "aws", args: ["secretsmanager", "describe-secret", "--secret-id", secretId], }); const versions = JSON.parse(stdout)["VersionIdsToStages"]; return Object.keys(versions).map((elm) => ({ name: versions[elm][0] })); } catch (e) { console.log(e); } return []; } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { try { // secret-id value const idx = tokens.indexOf("--secret-id"); if (idx < 0) { return []; } const secretId = tokens[idx + 1]; const { stdout } = await executeShellCommand({ command: "aws", args: ["secretsmanager", "describe-secret", "--secret-id", secretId], }); const versions = JSON.parse(stdout)["Tags"]; return versions.map((elm) => ({ name: elm["Key"] })); } catch (e) { console.log(e); } return []; } ``` ## src/aws/lambda.ts: ### Info: ### Single Functions: **custom:** ```typescript async function (tokens, executeShellCommand) { return listCustomGenerator( tokens, executeShellCommand, "list-layer-versions", ["--layer-name"], "LayerVersions", "Version" ); } ``` **postProcess:** ```typescript function (out, tokens) { try { const accountId = JSON.parse(out)["Account"]; return [{ name: accountId }, { name: "*" }]; } catch (error) { console.error(error); } return []; } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { return listCustomGenerator( tokens, executeShellCommand, "get-layer-version-policy", ["--layer-name", "--version-number"], "RevisionId" ); } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { return listCustomGenerator( tokens, executeShellCommand, "get-policy", ["--function-name"], "RevisionId" ); } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { return listCustomGenerator( tokens, executeShellCommand, "get-function", ["--function-name"], "Configuration", "RevisionId" ); } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { return listCustomGenerator( tokens, executeShellCommand, "list-aliases", ["--function-name"], "Aliases", "Name" ); } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { try { const idx = tokens.indexOf("--function-name"); const args = [ "lambda", "list-versions-by-function", "--function-name", tokens[idx + 1], ]; const { stdout } = await executeShellCommand({ command: "aws", args, }); const list = JSON.parse(stdout)["Versions"]; return list .filter((elm) => elm.Version !== "$LATEST") .map((elm) => { const version = elm["Version"]; return { insertValue: version, name: version, displayName: `version: ${version}`, icon: "fig://icon?type=aws", }; }); } catch (e) { console.log(e); } return []; } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { return listCustomSIDGenerator(tokens, executeShellCommand, "get-policy", [ "--function-name", ]); } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { return listCustomSIDGenerator( tokens, executeShellCommand, "get-layer-version-policy", ["--layer-name", "--version-number"] ); } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { // Getting sqs queues is implemented, although it has a huge performance toll. // It seems Fig rejects long-running promises after a time. // I am currently investigating if this is the case. // const result = await Promise.all([ // getResultList(tokens, executeShellCommand, "aws sqs list-queues", "QueueUrls"), // getResultList(tokens, executeShellCommand, "aws kinesis list-streams", "StreamNames") // ]); // const objects = result.flat().map((elm) => { // if (elm.includes("sqs")) { // return ({ // command: `aws sqs get-queue-attributes --queue-url ${elm} --attribute-names QueueArn`, // parentKey: "Attributes", // childKey: "QueueArn", // }) // } // return ({ // command: `aws kinesis describe-stream --stream-name ${elm}`, // parentKey: "StreamDescription", // childKey: "StreamARN", // }) // }); return MultiSuggestionsGenerator(tokens, executeShellCommand, [ { command: ["dynamodbstreams", "list-streams"], parentKey: "Streams", childKey: "StreamArn", }, { command: ["kafka", "list-clusters"], parentKey: "ClusterInfoList", childKey: "ClusterArn", }, //...objects, ]); } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { // Getting sqs queues is implemented, although it has a huge performance toll. // It seems Fig rejects long-running promises after a time. // I am currently investigating if this is the case. // const out = await executeShellCommand("aws sqs list-queues"); // const list = JSON.parse(out)["QueueUrls"]; // const sqsObjects = list.map((url) => ({ // command: `aws sqs get-queue-attributes --queue-url ${url} --attribute-names QueueArn`, // parentKey: "Attributes", // childKey: "QueueArn", // })); return MultiSuggestionsGenerator(tokens, executeShellCommand, [ { command: ["sns", "list-topics"], parentKey: "Topics", childKey: "TopicArn", }, { command: ["events", "list-event-buses"], parentKey: "EventBuses", childKey: "Arn", }, { command: ["lambda", "list-functions"], parentKey: "Functions", childKey: "FunctionArn", }, // ...sqsObjects, ]); } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "Roles", "RoleName"); } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "Keys", "KeyArn"); } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "Layers", "LayerArn"); } ``` **postProcess:** ```typescript function (out) { try { const list = JSON.parse(out)["Layers"]; return list.map((elm) => { return { name: elm["LatestMatchingVersion"]["LayerVersionArn"], icon: "fig://icon?type=aws", }; }); } catch (e) { console.log(e); } return []; } ``` **postProcess:** ```typescript function (out) { try { const list = JSON.parse(out)["FileSystems"]; return list.map((elm) => { const name = ("FileSystemArn" ? elm["FileSystemArn"] : elm) as string; return { name: `Arn=${name},LocalMountPath=/mnt/`, icon: "fig://icon?type=aws", }; }); } catch (e) { console.log(e); } return []; } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator( out, "CodeSigningConfigs", "CodeSigningConfigArn" ); } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "EventSourceMappings", "UUID"); } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "Functions", "CodeSha256"); } ``` **postProcess:** ```typescript function (out, tokens) { try { return out.split("\n").map((line) => { const parts = line.split(/\s+/); // sub prefix if (!parts.length) { return []; } return { name: parts[parts.length - 1], }; }) as Fig.Suggestion[]; } catch (error) { console.error(error); } return []; } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { try { const idx = tokens.indexOf("--s3-bucket"); const args = [ "s3", "ls", `${_prefixS3}${tokens[idx + 1]}`, "--recursive", "--page-size", "1000", ]; const { stdout } = await executeShellCommand({ command: "aws", args, }); if (stdout == "") { return []; } if (stdout.trim() === _prefixS3) { return [ { name: _prefixS3, insertValue: _prefixS3, }, ]; } return stdout.split("\n").map((line) => { const parts = line.split(/\s+/); // sub prefix if (!parts.length) { return []; } return { name: parts[parts.length - 1], }; }) as Fig.Suggestion[]; } catch (error) { console.error(error); } return []; } ``` **custom:** ```typescript async function (tokens, executeShellCommand) { try { const bucketIdx = tokens.indexOf("--s3-bucket"); const objectIdx = tokens.indexOf("--s3-key"); const args = [ "s3api", "list-object-versions", "--bucket", tokens[bucketIdx + 1], "--prefix", tokens[objectIdx + 1], ]; const { stdout } = await executeShellCommand({ command: "aws", args, }); if (stdout == "") { return []; } if (stdout.trim() === _prefixS3) { return [ { name: _prefixS3, insertValue: _prefixS3, }, ]; } const list = JSON.parse(stdout)["Versions"]; return list .filter((elm) => elm["VersionId"] !== "null") .map((elm) => { return { name: elm["VersionId"], icon: "fig://icon?type=aws", }; }); } catch (e) { console.log(e); } return []; } ``` ### URLs: - `https://opensource.org/licenses/MIT.` ## src/aws/cloudformation.ts: ### Info: ### Single Functions: **postProcess:** ```typescript function (out) { try { const accountId = JSON.parse(out)["Account"]; return [{ name: accountId }]; } catch (error) { console.error(error); } return []; } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "TypeSummaries", "TypeArn"); } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "Exports", "Name"); } ``` **postProcess:** ```typescript function (out, tokens) { try { return out.split("\n").map((line) => { const parts = line.split(/\s+/); // sub prefix if (!parts.length) { return []; } return { name: _prefixS3 + parts[parts.length - 1], }; }) as Fig.Suggestion[]; } catch (error) { console.error(error); } return []; } ``` **postProcess:** ```typescript function (out) { return postPrecessGenerator(out, "Keys", "KeyId"); } ```
withfig-bot commented 5 months ago

Hello @yaronuliel, thank you very much for creating a Pull Request! Here is a small checklist to get this PR merged as quickly as possible:

Please add a 👍 as a reaction to this comment to show that you read this.

yaronuliel commented 5 months ago

recheck