Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bring eventbridge #42

Merged
merged 29 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c076325
feat: `bring eventbridge`
skorfmann Dec 22, 2023
456259d
Merge branch 'main' into eventbridge
skorfmann Dec 22, 2023
c316216
Merge branch 'main' into eventbridge
eladb Dec 30, 2023
52b9fe8
fix (#45)
MarkMcCulloh Dec 30, 2023
2cd6d10
fix(websockets): fix token usage in simulator (#46)
eladb Jan 1, 2024
aafd29b
chore(bedrock): replacing BEDROCK_DEV with isTestEnvironment (#47)
Jan 2, 2024
c65266b
feat: `bring github` (#39)
eladcon Jan 2, 2024
5c0d7b5
fix(github): mts to js files (#48)
Jan 2, 2024
2a18bad
fix(github): using interface for credentials instead of cloud.secret …
Jan 2, 2024
c18f81b
fix(github): can't compile to tf-aws, missing cloud.service (#50)
Jan 3, 2024
dfa0cb1
chore: set up GitHub releases (#51)
Chriscbr Jan 4, 2024
7ec95d7
chore: mergify fixes (#52)
Chriscbr Jan 4, 2024
ce2696d
chore: fix mergify conditions (#53)
Chriscbr Jan 4, 2024
9adcff4
chore: mergify fixing continued (#54)
Chriscbr Jan 4, 2024
6b9db75
chore: mergify fixes (#55)
Chriscbr Jan 4, 2024
0439bf9
chore: testing
Chriscbr Jan 4, 2024
e4e9ae2
fix: unit test regression (#56)
Chriscbr Jan 4, 2024
40c0f54
Merge branch 'main' into eventbridge
skorfmann Feb 29, 2024
0db1cc1
deployable version
skorfmann Feb 29, 2024
a97d641
remove accidental commit
skorfmann Feb 29, 2024
1d6e04c
Update eventbridge/platform/sim/bus.w
eladcon Mar 7, 2024
df57157
wip
eladcon Mar 7, 2024
7fbd3fa
wip
eladcon Mar 7, 2024
1861b0c
wip
eladcon Mar 7, 2024
e6b86c3
wip
eladcon Mar 7, 2024
9978071
wip
eladcon Mar 13, 2024
0a72274
wip
eladcon Mar 13, 2024
82df437
wip
eladcon Mar 13, 2024
5ff5b76
Merge branch 'main' into eventbridge
eladcon Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/eventbridge-pull.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: eventbridge-pull
on:
pull_request:
paths:
- eventbridge/**
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: eventbridge
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
registry-url: https://registry.npmjs.org
- name: Install winglang
run: npm i -g winglang
- name: Install dependencies
run: npm install --include=dev
working-directory: eventbridge
- name: Test
run: wing test
working-directory: eventbridge
- name: Pack
run: wing pack
working-directory: eventbridge
37 changes: 37 additions & 0 deletions .github/workflows/eventbridge-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: eventbridge-release
on:
push:
branches:
- main
paths:
- eventbridge/**
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: eventbridge
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
registry-url: https://registry.npmjs.org
- name: Install winglang
run: npm i -g winglang
- name: Install dependencies
run: npm install --include=dev
working-directory: eventbridge
- name: Test
run: wing test
working-directory: eventbridge
- name: Pack
run: wing pack
working-directory: eventbridge
- name: Publish
run: npm publish --access=public --registry https://registry.npmjs.org --tag
latest *.tgz
working-directory: eventbridge
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions eventbridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
node_modules/
21 changes: 21 additions & 0 deletions eventbridge/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Wing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
45 changes: 45 additions & 0 deletions eventbridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# eventbridge
eladcon marked this conversation as resolved.
Show resolved Hide resolved

A Wing library for working with [Amazon EventBridge](https://aws.amazon.com/eventbridge/).

## Prerequisites

* [winglang](https://winglang.io)

## Installation

```sh
npm i @winglibs/eventbridge
```

## Usage

```js
bring eventbridge;

let bus = new eventbridge.Bus();

bus.subscribeFunction("github.pull-request.created", inflight (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of feels like subscribeFunction should take a cloud.Function and this should be called onEvent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. do we need subscribeFunction ? seems redundant

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required

log("subscribed event received {Json.stringify(event)}");
}, {
"detail-type": [{"prefix": "pull-request."}],
"source": ["github.com"],
});

new cloud.Function(inflight () => {
bus.publish(
detailType: "pull-request.created",
resources: ["test"],
source: "github.com",
version: "0",
detail: {
"test": "test",
},
);
});

```

## License

This library is licensed under the [MIT License](./LICENSE).
100 changes: 100 additions & 0 deletions eventbridge/lib.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
bring cloud;
bring expect;
bring util;
bring "./lib.w" as lib;
bring "./types.w" as types;

let eventBridge = new lib.Bus(name: "test");

class InboundGithubEvents {
pub bucket: cloud.Bucket;

new() {
this.bucket = new cloud.Bucket();
let counter = new cloud.Counter();

eventBridge.subscribeFunction("github.pull-request.created", inflight (event) => {
log("subscribed event received {Json.stringify(event)}");
this.bucket.put("test-{counter.inc()}", Json.stringify(event));
}, {
"detail-type": [{"prefix": "pull-request."}],
"source": ["github.com"],
});
}
}

class Environments {
pub bucket: cloud.Bucket;
new() {
let queue = new cloud.Queue();
this.bucket = new cloud.Bucket();

queue.setConsumer(inflight (event) => {
log("subscribed event {event} received {Json.stringify(event)}");
this.bucket.put("environment", event);
});

eventBridge.subscribeQueue("environments.created", queue, {
"detail-type": [{"prefix": "myTest"}],
source: ["myTest"],
});
}
}

let github = new InboundGithubEvents();
let env = new Environments();

test "publish to eventbridge" {
log("publishing to eventbridge");
eventBridge.publish(
detailType: "pull-request.created",
resources: ["test"],
source: "github.com",
version: "0",
detail: {
"test": "test",
},
);

log("published");

util.waitUntil(inflight () => {
log("checking bucket for event");
return github.bucket.exists("test-0");
}, {
timeout: 60s,
});

log("after wait");
let published = types.Event.fromJson(github.bucket.getJson("test-0"));
expect.equal("pull-request.created", published.detailType);
expect.equal("test", published.resources.at(0));
expect.equal("github.com", published.source);

expect.equal(0, env.bucket.list().length);

eventBridge.publish(
detailType: "myTest.check",
resources: ["test"],
source: "myTest",
version: "0",
detail: {
"fake": "env",
},
);

log("published 2nd event");

util.waitUntil(inflight () => {
log("checking environment bucket for event");
return env.bucket.exists("environment");
}, {
timeout: 60s,
});

// cant deserialize events coming from queue (see https://github.com/winglang/wing/issues/3686)
let published2 = env.bucket.getJson("environment");
expect.equal("myTest.check", published2.get("detail-type"));
expect.equal("test", published2.get("resources").getAt(0));
expect.equal("myTest", published2.get("source"));
}
37 changes: 37 additions & 0 deletions eventbridge/lib.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
bring cloud;
bring util;
bring "./types.w" as types;
bring "./platform/sim" as sim;
bring "./platform/tfaws" as aws;
bring "./platform/awscdk" as awscdk;

/**
Winglang resource for Amazon EventBridge.
*/
eladcon marked this conversation as resolved.
Show resolved Hide resolved
pub class Bus impl types.IBus {
inner: types.IBus;

new(props: types.BusProps) {
let target = util.env("WING_TARGET");
if target == "sim" {
this.inner = new sim.Bus(props) as "sim";
} elif target == "tf-aws" {
this.inner = new aws.Bus(props) as "tf-aws";
} elif target == "awscdk" {
this.inner = new awscdk.Bus(props) as "awscdk";
} else {
throw "Unsupported target {target}";
}
}

pub inflight publish(event: types.PublishEvent): void {
this.inner.publish(event);
}

pub subscribeFunction(name: str, handler: inflight (types.Event): void, pattern: Json): void {
this.inner.subscribeFunction(name, handler, pattern);
}
pub subscribeQueue(name: str, queue: cloud.Queue, pattern: Json): void {
this.inner.subscribeQueue(name, queue, pattern);
}
}
Loading
Loading