-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a19d2b
commit 16ee9d9
Showing
7 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const REPLICATOR_EVENT_BRIDGE_SOURCE_EVENT = 'w3infra-replicator' | ||
|
||
/** | ||
* @typedef {object} EventBridgeDetail | ||
* @property {string} key | ||
* @property {string} url | ||
* @property {string} destinationName | ||
*/ | ||
|
||
/** | ||
* @param {EventBridgeDetail} detail | ||
* @param {import('@aws-sdk/client-eventbridge').EventBridge} eventBridge | ||
* @param {string} eventBusName | ||
*/ | ||
export async function notifyBus(detail, eventBridge, eventBusName) { | ||
await eventBridge.putEvents({ | ||
Entries: [{ | ||
EventBusName: eventBusName, | ||
Source: REPLICATOR_EVENT_BRIDGE_SOURCE_EVENT, | ||
DetailType: 'file_replicated', | ||
Detail: JSON.stringify(detail) | ||
}] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { test } from './helpers/context.js' | ||
|
||
import { notifyBus, REPLICATOR_EVENT_BRIDGE_SOURCE_EVENT } from '../event-bus/index.js' | ||
|
||
const eventBusName = 'event-bus-arn' | ||
|
||
test('notifies event bus when new file is replicated', async t => { | ||
const detail = { | ||
key: 'bafyfoo/bafyfoo.car', | ||
url: 'https://endpoint.io/bafyfoo/bafyfoo.car', | ||
destinationName: 'carpark-prod-1' | ||
} | ||
const bus = { | ||
putEvents: (/** @type {any} */ data) => { | ||
t.is(data.Entries.length, 1) | ||
for (let i = 0; i < data.Entries.length; i++) { | ||
const entry = data.Entries[i] | ||
|
||
t.is(entry.EventBusName, eventBusName) | ||
t.is(entry.Source, REPLICATOR_EVENT_BRIDGE_SOURCE_EVENT) | ||
t.is(entry.DetailType, 'file_replicated') | ||
|
||
const entryDetail = JSON.parse(entry.Detail) | ||
t.deepEqual(entryDetail, detail) | ||
} | ||
return { | ||
promise: () => Promise.resolve(data) | ||
} | ||
} | ||
} | ||
|
||
await notifyBus( | ||
detail, | ||
// @ts-expect-error non complete event bus implementation | ||
bus, | ||
eventBusName | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters