From 405916c10a5f38ed3bc332dcbcde35812422c486 Mon Sep 17 00:00:00 2001 From: Paul Schultz Date: Thu, 1 Aug 2024 14:54:17 -0500 Subject: [PATCH] apply requested changes Signed-off-by: Paul Schultz --- beps/00010-event-auditor/README.md | 69 +++++++----------------------- 1 file changed, 15 insertions(+), 54 deletions(-) diff --git a/beps/00010-event-auditor/README.md b/beps/00010-event-auditor/README.md index 5f4e767806..b1af69cf95 100644 --- a/beps/00010-event-auditor/README.md +++ b/beps/00010-event-auditor/README.md @@ -75,7 +75,7 @@ This interface defines the information related to the actor who triggered the lo ```ts export type ActorDetails = { - actorId: string | null; + actorId?: string; ip?: string; hostname?: string; userAgent?: string; @@ -88,16 +88,12 @@ These interfaces define the structure of request and response data that might be ```ts export type AuditRequest = { - body: any; url: string; method: string; - params?: any; - query?: any; }; export type AuditResponse = { status: number; - body?: any; }; ``` @@ -114,20 +110,12 @@ export type AuditEventSuccessStatus = { status: 'succeeded' }; /** * Indicates the event failed and includes details about the encountered errors. */ -export type AuditEventFailureStatus = { +export type AuditEventFailureStatus = { status: 'failed'; - errors: ErrorLike[]; + errors: E; }; -/** - * Indicates the event failed with errors that don't perfectly fit the expected structure. - */ -export type AuditEventUnknownFailureStatus = { - status: 'failed'; - errors: unknown[]; -}; - -export type AuditEventStatus = AuditEventSuccessStatus | AuditEventFailureStatus; +export type AuditEventStatus = AuditEventSuccessStatus | AuditEventFailureStatus | undefined; ``` #### EventAuditor Interface @@ -139,45 +127,28 @@ This interface defines the functionalities of an `EventAuditor` class. This clas ```ts /** - * Common fields of an audit event. Note: timestamp and pluginId are automatically added at event creation. + * Common fields of an audit event. * * @public */ -export type AuditEventDetails = { - actor: ActorDetails; - eventName: string; - stage: string; - request?: AuditRequest; - response?: AuditResponse; - meta: JsonValue; - isAuditEvent: true; -} & AuditEventStatus; - -export type AuditEventDetailsOptions = { - eventName: string; - stage: string; - metadata?: JsonValue; - response?: AuditResponse; - actorId?: string; - request?: Request; -} & (AuditEventSuccessStatus | AuditEventUnknownFailureStatus); - -export type AuditEventOptions = { +export type AuditEventOptions = AuditEventStatus & { eventName: string; message: string; stage: string; level?: 'info' | 'debug' | 'warn' | 'error'; - actorId?: string; metadata?: JsonValue; response?: AuditResponse; request?: Request; -} & (AuditEventSuccessStatus | AuditEventUnknownFailureStatus); +} & ({ actorId: string; } | { credentials: BackstageCredentials } | undefined); -export type EventAuditorOptions = { - logger: LoggerService; - authService: AuthService; - httpAuthService: HttpAuthService; -}; +export type AuditEvent = { + actor: ActorDetails; + eventName: string; + stage: string; + isAuditLog: true; + request?: AuditRequest; + response?: AuditResponse; +} & AuditLogStatus; export interface EventAuditor { /** @@ -187,16 +158,6 @@ export interface EventAuditor { */ getActorId(request?: Request): Promise; - /** - * Generates the audit event details to place in the metadata argument of the logger - * - * Secrets in the metadata field and request body, params and query field should be redacted by the user before passing in the request object - * @public - */ - createAuditEventDetails( - options: AuditEventDetailsOptions, - ): Promise; - /** * Generates an Audit Event and logs it at the level passed by the user. * Supports `info`, `debug`, `warn` or `error` level. Defaults to `info` if no level is passed.