Skip to content

Commit

Permalink
Upgrade aws-sdk-v2->aws-sdk-v3 + support for wildcard filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacobsson committed Oct 4, 2023
1 parent 9779ab4 commit 87538d9
Show file tree
Hide file tree
Showing 34 changed files with 11,926 additions and 5,078 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
process.env.AWS_SDK_LOAD_CONFIG = 1;
const program = require("commander");
const package = require("./package.json");
require("@mhlabs/aws-sdk-sso");
require("./src/commands/pattern");
require("./src/commands/input");
require("./src/commands/browse");
Expand Down
16,081 changes: 11,451 additions & 4,630 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mhlabs/evb-cli",
"version": "1.1.52",
"version": "1.2.0",
"description": "A package for building EventBridge patterns",
"main": "index.js",
"scripts": {
Expand All @@ -13,8 +13,15 @@
"author": "mhdev",
"license": "ISC",
"dependencies": {
"@mhlabs/aws-sdk-sso": "^0.0.16",
"aws-sdk": "^2.1268.0",
"@aws-sdk/client-eventbridge": "^3.414.0",
"@aws-sdk/client-iam": "^3.423.0",
"@aws-sdk/client-kinesis": "^3.423.0",
"@aws-sdk/client-schemas": "^3.414.0",
"@aws-sdk/client-sfn": "^3.423.0",
"@aws-sdk/client-sns": "^3.423.0",
"@aws-sdk/client-sqs": "^3.423.0",
"@aws-sdk/client-sts": "^3.414.0",
"@aws-sdk/credential-provider-sso": "^3.414.0",
"axios": "^0.21.4",
"cli-spinner": "^0.2.10",
"commander": "^4.1.1",
Expand All @@ -31,7 +38,9 @@
"quicktype-core": "^6.0.62",
"temp-dir": "^2.0.0",
"to-json-schema": "^0.2.5",
"toml": "^3.0.0",
"ws": "^7.3.1",
"yaml": "^2.3.2",
"yaml-cfn": "^0.2.3"
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/api-destination/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ program
.requiredOption("-u --url [url]", "URL to OpenAPI specification of API")
.description("Generates API Destination SAM template resources")
.action(async (cmd) => {
authHelper.initAuth(cmd);
await authHelper.initAuth(cmd);

await apiDestination.create(cmd);

Expand Down
27 changes: 13 additions & 14 deletions src/commands/browse/browse-events.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const patternBuilder = require("../shared/schema-browser");
const inputUtil = require("../shared/input-util");
const eventBridgeUtil = require("../shared/eventbridge-util");
async function browseEvents(format, schemas, eventbridge) {
const { SchemasClient } = require("@aws-sdk/client-schemas");
const { EventBridgeClient, ListTargetsByRuleCommand } = require("@aws-sdk/client-eventbridge");
const { fromSSO } = require('@aws-sdk/credential-provider-sso');

async function browseEvents(cmd) {
const schemas = new SchemasClient();
while (true) {
const { targets } = await getTargets(schemas);
if (targets.length) {
Expand Down Expand Up @@ -37,13 +42,12 @@ async function browseEvents(format, schemas, eventbridge) {
}
}

async function getTargets(schemas) {
const { schema, sourceName } = await patternBuilder.getSchema(schemas);
const AWS = require("aws-sdk");
const evb = new AWS.EventBridge();
const eventBusName = await inputUtil.getEventBusName(evb);
async function getTargets() {
const { schema, sourceName } = await patternBuilder.getSchema();
const evb = new EventBridgeClient();
const eventBusName = await inputUtil.getEventBusName();
const targets = [];
for await (const ruleBatch of eventBridgeUtil.listRules(evb, {
for await (const ruleBatch of eventBridgeUtil.listRules({
EventBusName: eventBusName,
Limit: 100,
})) {
Expand All @@ -56,14 +60,9 @@ async function getTargets(schemas) {
if (
pattern.source == sourceName &&
pattern["detail-type"] ==
schema.components.schemas.AWSEvent["x-amazon-events-detail-type"]
schema.components.schemas.AWSEvent["x-amazon-events-detail-type"]
) {
const targetResponse = await evb
.listTargetsByRule({
Rule: rule.Name,
EventBusName: eventBusName,
})
.promise();
const targetResponse = await evb.send(new ListTargetsByRuleCommand({ Rule: rule.Name, EventBusName: eventBusName }));
for (const target of targetResponse.Targets) {
const arnSplit = target.Arn.split(":");
const service = arnSplit[2];
Expand Down
7 changes: 2 additions & 5 deletions src/commands/browse/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const AWS = require("aws-sdk");
const program = require("commander");
const browser = require("./browse-events");
const authHelper = require("../shared/auth-helper");
Expand All @@ -11,8 +10,6 @@ program
.option("--region [region]", "The AWS region to use. Falls back on AWS_REGION environment variable if not specified")
.description("Browses sources and detail types and shows their consumers")
.action(async (cmd) => {
authHelper.initAuth(cmd);
const schemaApi = new AWS.Schemas();
const evbApi = new AWS.EventBridge();
await browser.browseEvents(cmd, schemaApi, evbApi);
await authHelper.initAuth(cmd);
await browser.browseEvents(cmd);
});
26 changes: 12 additions & 14 deletions src/commands/code-binding/code-binding.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const schemaBrowser = require("../shared/schema-browser");
const inputUtil = require("../shared/input-util");
const templateParser = require("../shared/template-parser");
const SchemasClient = require("aws-sdk/clients/schemas");
const { SchemasClient, ExportSchemaCommand } = require("@aws-sdk/client-schemas");
const jsf = require("json-schema-faker");
const jp = require("jsonpath");
const toJsonSchema = require("to-json-schema");
Expand All @@ -20,22 +20,20 @@ require("./languages/java");
require("./languages/swift");
async function loadFromRegistry(cmd) {
const schemas = new SchemasClient();
const schemaLocation = await schemaBrowser.getSchemaName(schemas);
const schema = await schemas
.exportSchema({
RegistryName: schemaLocation.registry.id,
SchemaName: schemaLocation.schemaName,
Type: "JSONSchemaDraft4",
})
.promise();
const schemaLocation = await schemaBrowser.getSchemaName();
const schema = await schemas.send(new ExportSchemaCommand({
RegistryName: schemaLocation.registry.id,
SchemaName: schemaLocation.schemaName,
Type: "JSONSchemaDraft4",
}));
await generateType(cmd, schema.Content);
}

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

if (!cmd.registryName) {
cmd.registryName = (await inputUtil.getRegistry(schemas)).id;
cmd.registryName = (await inputUtil.getRegistry()).id;
}
const template = templateParser.load(cmd.template);
rules = templateParser.getEventRules().map((r) => {
Expand Down Expand Up @@ -68,13 +66,13 @@ async function loadFromTemplate(cmd) {
.replace(/ /g, "");

try {
const describeSchemaResponse = await schemas
.exportSchema({
const describeSchemaResponse = await schemas.send(new ExportSchemaCommand
({
RegistryName: cmd.registryName,
SchemaName: schemaName,
Type: "JSONSchemaDraft4",
})
.promise();
}));

let schema = JSON.parse(describeSchemaResponse.Content);
if (target.target.InputTransformer) {
schema = generateSchemaForTransform(schema, target);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/code-binding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ program
.option("-l, --language [language]", "Output language")
.description("Generates code bindings from an InputTransformer template")
.action(async (cmd) => {
authHelper.initAuth(cmd);
await authHelper.initAuth(cmd);

if (!cmd.language) {
cmd.language = await codeBinding.getLanguageInput();
Expand Down
Loading

0 comments on commit 87538d9

Please sign in to comment.