Skip to content

Commit b9fcf75

Browse files
committed
feat(bus): update README
BREAKING CHANGE: The `sectester/bus` package, which was intended to provide support of communication via the AMQP transport is removed. This change simplifies the codebase by removing deprecated options and encourages the use of more modern and supported transport methods. closes #196
1 parent 8366b76 commit b9fcf75

File tree

2 files changed

+11
-114
lines changed

2 files changed

+11
-114
lines changed

packages/core/README.md

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ await new Ping({ status: 'connected' }).execute(dispatcher);
164164
await dispatcher.execute(new Ping({ status: 'disconnected' }));
165165
```
166166

167-
The same is applicable for the `Event`. You just need to use the `EventDispatcher` instead of `CommandDispatcher`.
168-
169167
Each message have a correlation ID to ensure atomicity. The regular UUID is used, but you might also want to consider other options.
170168

171169
### Request-response
@@ -200,80 +198,9 @@ To adjust its behavior you can use next options:
200198
| `expectReply` | Indicates whether to wait for a reply. By default `true`. |
201199
| `ttl` | Period of time that command should be handled before being discarded. By default `10000` ms. |
202200
| `type` | The name of a command. By default, it is the name of specific class. |
203-
| `corelationId` | Used to ensure atomicity while working with EventBus. By default, random UUID. |
201+
| `corelationId` | Used to ensure atomicity. By default, random UUID. |
204202
| `createdAt` | The exact date and time the command was created. |
205203

206-
### Publish-subscribe
207-
208-
When you just want to publish events without waiting for a response, it is better to use the `Event`.
209-
The ideal use case for the publish-subscribe model is when you want to simply notify another service that a certain condition has occurred.
210-
211-
To create an instance of `Event` use the abstract class as follows:
212-
213-
```ts
214-
import { Event } from '@sectester/core';
215-
216-
interface Issue {
217-
name: string;
218-
details: string;
219-
type: string;
220-
cvss?: string;
221-
cwe?: string;
222-
}
223-
224-
class IssueDetected extends Event<Issue> {
225-
constructor(payload: Issue) {
226-
super(payload);
227-
}
228-
}
229-
```
230-
231-
To adjust its behavior you can use next options:
232-
233-
| Option | Description |
234-
| :------------- | ------------------------------------------------------------------------------ |
235-
| `payload` | Message that we want to transmit to the remote service. |
236-
| `type` | The name of a command. By default, it is the name of specific class. |
237-
| `corelationId` | Used to ensure atomicity while working with EventBus. By default, random UUID. |
238-
| `createdAt` | The exact date and time the event was created. |
239-
240-
To create an event handler, you should implement the `Handler` interface and use the `@bind()` decorator to subscribe a handler to an event:
241-
242-
```ts
243-
@bind(IssueDetected)
244-
class IssueDetectedHandler implements EventHandler<Issue> {
245-
public handle(payload: Issue): Promise<void> {
246-
// implementation
247-
}
248-
}
249-
```
250-
251-
You can register multiple event handlers for a single event pattern and all of them will be automatically triggered in parallel.
252-
253-
```ts
254-
@bind(IssueDetected, IssueReopened)
255-
class IssueDetectedHandler implements EventHandler<Issue> {
256-
public handle(payload: Issue): Promise<void> {
257-
// implementation
258-
}
259-
}
260-
```
261-
262-
You can also use a string and symbol to subscribe a handler to events:
263-
264-
```ts
265-
const IssueReopened = Symbol('IssueReopened');
266-
267-
@bind('IssueDetected', IssueReopened)
268-
class IssueDetectedHandler implements EventHandler<Issue> {
269-
public handle(payload: Issue): Promise<void> {
270-
// implementation
271-
}
272-
}
273-
```
274-
275-
As soon as the `IssueDetected` event appears, the event handler takes a single argument, the data passed from the client (in this case, an event payload which has been sent over the network).
276-
277204
## License
278205

279206
Copyright © 2022 [Bright Security](https://brightsec.com/).

packages/repeater/README.md

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,21 @@ The factory exposes the `createRepeater` method that returns a new `Repeater` in
3737
const repeater = await repeaterFactory.createRepeater();
3838
```
3939

40-
You can customize some properties, e.g. name prefix or description, passing options as follows:
40+
You can customize some properties, e.g. request runner capabilities, passing options as follows:
4141

4242
```ts
4343
const repeater = await repeaterFactory.createRepeater({
44-
namePrefix: 'my-repeater',
45-
description: 'My repeater'
44+
requestRunnerOptions: {...},
45+
requestRunners: {...}
4646
});
4747
```
4848

4949
The `createRepeater` method accepts the options described below:
5050

51-
| Option | Description |
52-
| :---------------------------- | ----------------------------------------------------------------------------------------------------- |
53-
| `namePrefix` | Enter a name prefix that will be used as a constant part of the unique name. By default, `sectester`. |
54-
| `description` | Set a short description of the Repeater. |
55-
| `requestRunnerOptions` | Custom the request runner settings that will be used to execute requests to your application. |
56-
| `projectId` | Specify the project ID to associate the Repeater with. |
57-
| `disableRandomNameGeneration` | Disable random name generation for the Repeater's name. |
51+
| Option | Description |
52+
| :--------------------- | ---------------------------------------------------------------------------------- |
53+
| `requestRunnerOptions` | Request runner settings that will be used to execute requests to your application. |
54+
| `requestRunners` | Custom request runner implementation to override the standard runners set. |
5855

5956
The default `requestRunnerOptions` is as follows:
6057

@@ -95,33 +92,6 @@ export interface RequestRunnerOptions {
9592
}
9693
```
9794

98-
The `RepeaterFactory` also provides a method to create a `Repeater` instance using an existing repeater ID. You can use the `createRepeaterFromExisting` method to accomplish this:
99-
100-
```ts
101-
const existingRepeaterId = '<your repater ID>';
102-
const repeater = await repeaterFactory.createRepeaterFromExisting(
103-
existingRepeaterId
104-
);
105-
```
106-
107-
This method retrieves the existing repeater's details from the cloud using its ID and returns a `Repeater` instance associated with the specified ID.
108-
109-
You can also customize the request runner options for the existing repeater by passing them as options:
110-
111-
```ts
112-
const existingRepeaterId = '<your repater ID>';
113-
const repeater = await repeaterFactory.createRepeaterFromExisting(
114-
existingRepeaterId,
115-
{
116-
requestRunnerOptions: {
117-
timeout: 10000,
118-
maxContentLength: 200,
119-
allowedMimes: ['text/html']
120-
}
121-
}
122-
);
123-
```
124-
12595
The `Repeater` instance provides the `start` method. This method is required to establish a connection with the Bright cloud engine and interact with other services.
12696

12797
```ts
@@ -169,8 +139,8 @@ describe('Scan', () => {
169139

170140
### Implementation details
171141

172-
Under the hood `Repeater` register `ExecuteRequestEventHandler` in bus,
173-
which in turn uses the `RequestRunner` to proceed with request:
142+
Under the hood `Repeater` connects to the Bright engine using web socket protocol, then listens for incoming commands from the engine.
143+
Which in turn get executed with the `RequestRunner` to proceed with the request coming from the engine:
174144

175145
```ts
176146
export interface RequestRunner {
@@ -179,7 +149,7 @@ export interface RequestRunner {
179149
}
180150
```
181151

182-
Package contains `RequestRunner` implementations for both HTTP and WS protocols.
152+
Package contains `RequestRunner` implementations for HTTP protocol only.
183153
To support other protocol new class implementation of `RequestRunner` should be registered in global IoC container:
184154

185155
```ts

0 commit comments

Comments
 (0)