Skip to content

Commit b3328d0

Browse files
committed
feat: implemented untested NodesAuditGet
1 parent 89097da commit b3328d0

File tree

2 files changed

+55
-47
lines changed

2 files changed

+55
-47
lines changed

src/nodes/agent/handlers/NodesAuditsGet.ts

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,61 @@ import type { ContextTimed } from '@matrixai/contexts';
22
import type { DB } from '@matrixai/db';
33
import type { JSONValue } from '@matrixai/rpc';
44
import type Sigchain from '../../../sigchain/Sigchain';
5-
import type {
6-
AgentRPCRequestParams,
7-
AgentRPCResponseResult,
8-
ClaimIdMessage,
9-
AgentClaimMessage,
10-
AuditIdMessage,
11-
AgentAuditMessage,
5+
import type
6+
{
7+
AgentRPCRequestParams,
8+
AgentRPCResponseResult,
9+
AuditIdMessage,
10+
AgentAuditMessage,
1211
} from '../types';
1312
import { ServerHandler } from '@matrixai/rpc';
14-
import * as claimsUtils from '../../../claims/utils';
1513
import type Audit from '../../../audit/Audit';
16-
import { AuditEventId } from '@/ids';
14+
import { AuditEventId, AuditEventIdEncoded } from '@/ids';
1715

1816
/**
19-
* Gets the sigchain claims of a node
17+
* Gets audit events from a node
2018
*/
21-
class NodesClaimsGet extends ServerHandler<
22-
{
23-
sigchain: Sigchain;
24-
db: DB;
25-
seek?: AuditEventId | number;
26-
seekTo?: AuditEventId | number;
27-
limit?: number;
28-
},
29-
AgentRPCRequestParams<AuditIdMessage>,
30-
AgentRPCResponseResult<AgentAuditMessage>
31-
> {
32-
public handle = async function* (
33-
_input: AuditIdMessage,
34-
_cancel: (reason?: any) => void,
35-
_meta: Record<string, JSONValue> | undefined,
36-
ctx: ContextTimed,
37-
): AsyncGenerator<AgentRPCResponseResult<AgentAuditMessage>> {
38-
const { audit, db }: { audit: Audit; db: DB } = this.container;
39-
yield* db.withTransactionG(async function* (tran): AsyncGenerator<
40-
AgentRPCResponseResult<AgentClaimMessage>
41-
> {
42-
for await (const [claimId, signedClaim] of audit.getAuditEvents(
43-
{ order: 'asc' },
44-
tran,
45-
)) {
46-
ctx.signal.throwIfAborted();
47-
const encodedClaim = claimsUtils.generateSignedClaim(signedClaim);
48-
const response: AgentClaimMessage = {
49-
claimIdEncoded: claimsUtils.encodeClaimId(claimId),
50-
signedTokenEncoded: encodedClaim,
51-
};
52-
yield response;
53-
}
54-
});
55-
};
19+
class NodesAuditEventsGet extends ServerHandler<
20+
{
21+
sigchain: Sigchain;
22+
db: DB;
23+
},
24+
AgentRPCRequestParams<AuditIdMessage>,
25+
AgentRPCResponseResult<AgentAuditMessage>
26+
>
27+
{
28+
public handle = async function* (
29+
input: AgentRPCRequestParams<AuditIdMessage>,
30+
_cancel: (reason?: any) => void,
31+
_meta: Record<string, JSONValue> | undefined,
32+
ctx: ContextTimed
33+
): AsyncGenerator<AgentRPCResponseResult<AgentAuditMessage>>
34+
{
35+
const { seek, seekEnd, limit } = input;
36+
const { audit, db }: { audit: Audit; db: DB } = this.container;
37+
38+
yield* db.withTransactionG(async function* ( tran ): AsyncGenerator<AgentRPCResponseResult<AgentAuditMessage>>
39+
{
40+
41+
for await (
42+
const auditEvent of audit.getAuditEvents(
43+
[],
44+
{
45+
seek,
46+
seekEnd,
47+
limit
48+
},
49+
tran)
50+
)
51+
{
52+
ctx.signal.throwIfAborted();
53+
yield {
54+
auditIdEncoded: auditEvent.id.toString() as AuditEventIdEncoded,
55+
};
56+
}
57+
58+
});
59+
};
5660
}
5761

58-
export default NodesClaimsGet;
62+
export default NodesAuditEventsGet;

src/nodes/agent/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
JSONRPCResponseResult,
55
} from '@matrixai/rpc';
66
import type { SignedTokenEncoded } from '../../tokens/types';
7-
import type { AuditEventIdEncoded, ClaimIdEncoded, NodeIdEncoded, VaultIdEncoded } from '../../ids';
7+
import type { AuditEventId, AuditEventIdEncoded, ClaimIdEncoded, NodeIdEncoded, VaultIdEncoded } from '../../ids';
88
import type { VaultAction, VaultName } from '../../vaults/types';
99
import type { SignedNotification } from '../../notifications/types';
1010
import type { Host, Hostname, Port } from '../../network/types';
@@ -18,6 +18,10 @@ type AgentRPCResponseResult<T extends JSONObject = JSONObject> =
1818

1919
type AuditIdMessage = {
2020
auditIdEncoded: AuditEventIdEncoded
21+
seek?: AuditEventId | number;
22+
seekEnd?: AuditEventId | number;
23+
order?: 'asc' | 'desc';
24+
limit?: number;
2125
}
2226

2327
type AgentAuditMessage = Partial<AuditIdMessage> & {

0 commit comments

Comments
 (0)