Skip to content

Commit 33522cb

Browse files
author
ljacobsson
committed
feat: new command 🎉 that lets you find usages of fields in your payload in downstream consumers
1 parent b0c0fa5 commit 33522cb

File tree

6 files changed

+211
-21
lines changed

6 files changed

+211
-21
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ If no template is passed to the command, then you will get prompted to select a
9898

9999
This is using quicktype. See their docs for [target languages](https://github.com/quicktype/quicktype#target-languages)
100100

101+
## Find usages in event rule patterns
102+
```
103+
Usage: evb find-usages|f [options]
104+
105+
Searches all rules on a bus for matching event patterns.
106+
107+
I.e to find all rules that match on an s3:PutObject event from CloudTrail, use:
108+
evb find-usages -f $.source=aws.s3,$.detail-type=.+CloudTrail,$.detail.eventName=PutObject
109+
110+
Options:
111+
-b, --eventbus [eventbus] Name of the event bus to search. (default: "default")
112+
-f, --filters [filters] Comma separated list of '$.path.to.property=regex-pattern' to filter the event patterns with
113+
-p, --profile [profile] AWS profile to use
114+
--region [region] The AWS region to use. Falls back on AWS_REGION environment variable if not specified
115+
-h, --help output usage information
116+
```
117+
118+
This command allows you to find usages of specific fields across all event rules on a bus. This could be useful in order to find individual consumers of a specific field in your event payload.
119+
120+
Some examples:
121+
122+
* Find all rules that match on a specific `source` and `detail-type` combination on a custom bus: `evb find-usages --filters $.source=my-custom-source,$.detail-type=my-custom-detail-type` --eventbus custombus
123+
* Find all rules that trigger on any of AWS CodePipeline, CodeBuild, CodeDeploy, etc events: `evb find-usages --filters $.source=aws\.code.*`
124+
* Find all rules that trigger on a Lambda failure destination: `evb find-usages --filters $.detail-type='Lambda Function Invocation Result - Failure'`
125+
126+
101127
## Generate API Destinations resources
102128
```
103129
Usage: evb api-destination|api [options]

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require("./src/commands/local");
1515
require("./src/commands/code-binding");
1616
require("./src/commands/api-destination");
1717
require("./src/commands/pipes");
18+
require("./src/commands/find-usages");
1819

1920
program.version(package.version, "-v, --vers", "output the current version");
2021

package-lock.json

+156-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mhlabs/evb-cli",
3-
"version": "1.1.49",
3+
"version": "1.1.50",
44
"description": "A package for building EventBridge/CloudWatch Events patterns",
55
"main": "index.js",
66
"scripts": {
@@ -21,10 +21,12 @@
2121
"date-prompt": "^1.0.0",
2222
"inquirer": "^7.0.4",
2323
"inquirer-autocomplete-prompt": "^1.3.0",
24+
"inquirer-tree-prompt": "^1.1.2",
2425
"json-schema-faker": "^0.5.0-rcv.32",
2526
"json-to-pretty-yaml": "^1.2.2",
2627
"jsonpath": "^1.0.2",
27-
"open": "^7.2.0",
28+
"link2aws": "^1.0.12",
29+
"open": "^7.4.2",
2830
"prompt-skeleton": "^1.0.2",
2931
"quicktype-core": "^6.0.62",
3032
"temp-dir": "^2.0.0",

src/commands/browse/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ const authHelper = require("../shared/auth-helper");
66
program
77
.command("browse")
88
.alias("b")
9+
.option("-f, --filter-patterns [filters]", "Comma separated list of '$.json.path.to.property=regex-pattern' to filter the results with")
910
.option("-p, --profile [profile]", "AWS profile to use")
1011
.option("--region [region]", "The AWS region to use. Falls back on AWS_REGION environment variable if not specified")
1112
.description("Browses sources and detail types and shows their consumers")
1213
.action(async (cmd) => {
1314
authHelper.initAuth(cmd);
1415
const schemaApi = new AWS.Schemas();
1516
const evbApi = new AWS.EventBridge();
16-
await browser.browseEvents(cmd.format, schemaApi, evbApi);
17+
await browser.browseEvents(cmd, schemaApi, evbApi);
1718
});

src/commands/shared/input-util.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ if (!process.stdout.getWindowSize) {
66
}
77

88
const inquirer = require("inquirer");
9+
10+
const TreePrompt = require('inquirer-tree-prompt');
11+
inquirer.registerPrompt('tree', TreePrompt);
12+
913
inquirer.registerPrompt(
1014
"autocomplete",
1115
require("inquirer-autocomplete-prompt")
@@ -118,10 +122,9 @@ async function getProperty(currentObject, objectArray) {
118122
const property = await inquirer.prompt({
119123
name: "id",
120124
type: "autocomplete",
121-
message: `Add ${
122-
objectArray[objectArray.length - 1] ||
125+
message: `Add ${objectArray[objectArray.length - 1] ||
123126
currentObject["x-amazon-events-detail-type"]
124-
} item`,
127+
} item`,
125128
choices: choices,
126129
source: sourceAutocomplete(choices),
127130
});
@@ -252,6 +255,21 @@ async function getDate(message) {
252255
return answer;
253256
}
254257

258+
async function tree(message, items) {
259+
let answer;
260+
do {
261+
answer = await inquirer
262+
.prompt(
263+
{
264+
type: 'tree',
265+
name: "state",
266+
message: message,
267+
tree: items,
268+
});
269+
} while (!answer.state.action);
270+
return answer.state;
271+
}
272+
255273
module.exports = {
256274
getEventBusName,
257275
getRegistry,
@@ -263,6 +281,7 @@ module.exports = {
263281
getPropertyValue,
264282
text,
265283
getDate,
284+
tree,
266285
BACK,
267286
DONE,
268287
UNDO,

0 commit comments

Comments
 (0)