Skip to content

Commit 87538d9

Browse files
author
ljacobsson
committed
Upgrade aws-sdk-v2->aws-sdk-v3 + support for wildcard filters
1 parent 9779ab4 commit 87538d9

34 files changed

+11926
-5078
lines changed

index.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
process.env.AWS_SDK_LOAD_CONFIG = 1;
33
const program = require("commander");
44
const package = require("./package.json");
5-
require("@mhlabs/aws-sdk-sso");
65
require("./src/commands/pattern");
76
require("./src/commands/input");
87
require("./src/commands/browse");

package-lock.json

+11,451-4,630
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mhlabs/evb-cli",
3-
"version": "1.1.52",
3+
"version": "1.2.0",
44
"description": "A package for building EventBridge patterns",
55
"main": "index.js",
66
"scripts": {
@@ -13,8 +13,15 @@
1313
"author": "mhdev",
1414
"license": "ISC",
1515
"dependencies": {
16-
"@mhlabs/aws-sdk-sso": "^0.0.16",
17-
"aws-sdk": "^2.1268.0",
16+
"@aws-sdk/client-eventbridge": "^3.414.0",
17+
"@aws-sdk/client-iam": "^3.423.0",
18+
"@aws-sdk/client-kinesis": "^3.423.0",
19+
"@aws-sdk/client-schemas": "^3.414.0",
20+
"@aws-sdk/client-sfn": "^3.423.0",
21+
"@aws-sdk/client-sns": "^3.423.0",
22+
"@aws-sdk/client-sqs": "^3.423.0",
23+
"@aws-sdk/client-sts": "^3.414.0",
24+
"@aws-sdk/credential-provider-sso": "^3.414.0",
1825
"axios": "^0.21.4",
1926
"cli-spinner": "^0.2.10",
2027
"commander": "^4.1.1",
@@ -31,7 +38,9 @@
3138
"quicktype-core": "^6.0.62",
3239
"temp-dir": "^2.0.0",
3340
"to-json-schema": "^0.2.5",
41+
"toml": "^3.0.0",
3442
"ws": "^7.3.1",
43+
"yaml": "^2.3.2",
3544
"yaml-cfn": "^0.2.3"
3645
},
3746
"bugs": {

src/commands/api-destination/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ program
1515
.requiredOption("-u --url [url]", "URL to OpenAPI specification of API")
1616
.description("Generates API Destination SAM template resources")
1717
.action(async (cmd) => {
18-
authHelper.initAuth(cmd);
18+
await authHelper.initAuth(cmd);
1919

2020
await apiDestination.create(cmd);
2121

src/commands/browse/browse-events.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const patternBuilder = require("../shared/schema-browser");
22
const inputUtil = require("../shared/input-util");
33
const eventBridgeUtil = require("../shared/eventbridge-util");
4-
async function browseEvents(format, schemas, eventbridge) {
4+
const { SchemasClient } = require("@aws-sdk/client-schemas");
5+
const { EventBridgeClient, ListTargetsByRuleCommand } = require("@aws-sdk/client-eventbridge");
6+
const { fromSSO } = require('@aws-sdk/credential-provider-sso');
7+
8+
async function browseEvents(cmd) {
9+
const schemas = new SchemasClient();
510
while (true) {
611
const { targets } = await getTargets(schemas);
712
if (targets.length) {
@@ -37,13 +42,12 @@ async function browseEvents(format, schemas, eventbridge) {
3742
}
3843
}
3944

40-
async function getTargets(schemas) {
41-
const { schema, sourceName } = await patternBuilder.getSchema(schemas);
42-
const AWS = require("aws-sdk");
43-
const evb = new AWS.EventBridge();
44-
const eventBusName = await inputUtil.getEventBusName(evb);
45+
async function getTargets() {
46+
const { schema, sourceName } = await patternBuilder.getSchema();
47+
const evb = new EventBridgeClient();
48+
const eventBusName = await inputUtil.getEventBusName();
4549
const targets = [];
46-
for await (const ruleBatch of eventBridgeUtil.listRules(evb, {
50+
for await (const ruleBatch of eventBridgeUtil.listRules({
4751
EventBusName: eventBusName,
4852
Limit: 100,
4953
})) {
@@ -56,14 +60,9 @@ async function getTargets(schemas) {
5660
if (
5761
pattern.source == sourceName &&
5862
pattern["detail-type"] ==
59-
schema.components.schemas.AWSEvent["x-amazon-events-detail-type"]
63+
schema.components.schemas.AWSEvent["x-amazon-events-detail-type"]
6064
) {
61-
const targetResponse = await evb
62-
.listTargetsByRule({
63-
Rule: rule.Name,
64-
EventBusName: eventBusName,
65-
})
66-
.promise();
65+
const targetResponse = await evb.send(new ListTargetsByRuleCommand({ Rule: rule.Name, EventBusName: eventBusName }));
6766
for (const target of targetResponse.Targets) {
6867
const arnSplit = target.Arn.split(":");
6968
const service = arnSplit[2];

src/commands/browse/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const AWS = require("aws-sdk");
21
const program = require("commander");
32
const browser = require("./browse-events");
43
const authHelper = require("../shared/auth-helper");
@@ -11,8 +10,6 @@ program
1110
.option("--region [region]", "The AWS region to use. Falls back on AWS_REGION environment variable if not specified")
1211
.description("Browses sources and detail types and shows their consumers")
1312
.action(async (cmd) => {
14-
authHelper.initAuth(cmd);
15-
const schemaApi = new AWS.Schemas();
16-
const evbApi = new AWS.EventBridge();
17-
await browser.browseEvents(cmd, schemaApi, evbApi);
13+
await authHelper.initAuth(cmd);
14+
await browser.browseEvents(cmd);
1815
});

src/commands/code-binding/code-binding.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const schemaBrowser = require("../shared/schema-browser");
22
const inputUtil = require("../shared/input-util");
33
const templateParser = require("../shared/template-parser");
4-
const SchemasClient = require("aws-sdk/clients/schemas");
4+
const { SchemasClient, ExportSchemaCommand } = require("@aws-sdk/client-schemas");
55
const jsf = require("json-schema-faker");
66
const jp = require("jsonpath");
77
const toJsonSchema = require("to-json-schema");
@@ -20,22 +20,20 @@ require("./languages/java");
2020
require("./languages/swift");
2121
async function loadFromRegistry(cmd) {
2222
const schemas = new SchemasClient();
23-
const schemaLocation = await schemaBrowser.getSchemaName(schemas);
24-
const schema = await schemas
25-
.exportSchema({
26-
RegistryName: schemaLocation.registry.id,
27-
SchemaName: schemaLocation.schemaName,
28-
Type: "JSONSchemaDraft4",
29-
})
30-
.promise();
23+
const schemaLocation = await schemaBrowser.getSchemaName();
24+
const schema = await schemas.send(new ExportSchemaCommand({
25+
RegistryName: schemaLocation.registry.id,
26+
SchemaName: schemaLocation.schemaName,
27+
Type: "JSONSchemaDraft4",
28+
}));
3129
await generateType(cmd, schema.Content);
3230
}
3331

3432
async function loadFromTemplate(cmd) {
3533
const schemas = new SchemasClient();
3634

3735
if (!cmd.registryName) {
38-
cmd.registryName = (await inputUtil.getRegistry(schemas)).id;
36+
cmd.registryName = (await inputUtil.getRegistry()).id;
3937
}
4038
const template = templateParser.load(cmd.template);
4139
rules = templateParser.getEventRules().map((r) => {
@@ -68,13 +66,13 @@ async function loadFromTemplate(cmd) {
6866
.replace(/ /g, "");
6967

7068
try {
71-
const describeSchemaResponse = await schemas
72-
.exportSchema({
69+
const describeSchemaResponse = await schemas.send(new ExportSchemaCommand
70+
({
7371
RegistryName: cmd.registryName,
7472
SchemaName: schemaName,
7573
Type: "JSONSchemaDraft4",
76-
})
77-
.promise();
74+
}));
75+
7876
let schema = JSON.parse(describeSchemaResponse.Content);
7977
if (target.target.InputTransformer) {
8078
schema = generateSchemaForTransform(schema, target);

src/commands/code-binding/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ program
1919
.option("-l, --language [language]", "Output language")
2020
.description("Generates code bindings from an InputTransformer template")
2121
.action(async (cmd) => {
22-
authHelper.initAuth(cmd);
22+
await authHelper.initAuth(cmd);
2323

2424
if (!cmd.language) {
2525
cmd.language = await codeBinding.getLanguageInput();

0 commit comments

Comments
 (0)