Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Created August 5, 2019 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmuellr/7607e1a1a64edeecfda30c0b97f2d5ca to your computer and use it in GitHub Desktop.
Save pmuellr/7607e1a1a64edeecfda30c0b97f2d5ca to your computer and use it in GitHub Desktop.
initial pass on an AuditLog interface
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
type IAuditRecord = Record<string, any>;
interface IAuditLog {
initialize(): Promise<void>;
log(record: IAuditRecord): Promise<void>;
}
interface ICreateAuditLogOptions {
index: string;
}
export function create(options: ICreateAuditLogOptions): IAuditLog {
return new AuditLog(options);
}
class AuditLog implements IAuditLog {
private _index: string;
private _initialized = false;
constructor(options: ICreateAuditLogOptions) {
this._index = options.index;
}
async log(record: IAuditRecord) {
if (!this._initialized) throw new Error(`audit log ${this._index} not initialized`);
console.log('woulda written to index', this._index, { record });
}
async initialize(): Promise<void> {
this._initialized = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment