Skip to content

Commit

Permalink
Changed naming as suggested in code review
Browse files Browse the repository at this point in the history
  • Loading branch information
thomheymann committed Dec 2, 2020
1 parent 9014744 commit 2873fe7
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 108 deletions.
54 changes: 27 additions & 27 deletions x-pack/plugins/actions/server/actions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
getAuthorizationModeBySource,
AuthorizationMode,
} from './authorization/get_authorization_mode_by_source';
import { connectorEvent, ConnectorAction } from './lib/audit_events';
import { connectorAuditEvent, ConnectorAuditAction } from './lib/audit_events';

// We are assuming there won't be many actions. This is why we will load
// all the actions in advance and assume the total count to not go over 10000.
Expand Down Expand Up @@ -124,8 +124,8 @@ export class ActionsClient {
await this.authorization.ensureAuthorized('create', actionTypeId);
} catch (error) {
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.CREATE,
connectorAuditEvent({
action: ConnectorAuditAction.CREATE,
savedObject: { type: 'action', id },
error,
})
Expand All @@ -140,8 +140,8 @@ export class ActionsClient {
this.actionTypeRegistry.ensureActionTypeEnabled(actionTypeId);

this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.CREATE,
connectorAuditEvent({
action: ConnectorAuditAction.CREATE,
savedObject: { type: 'action', id },
outcome: EventOutcome.UNKNOWN,
})
Expand Down Expand Up @@ -190,8 +190,8 @@ export class ActionsClient {
}
} catch (error) {
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.UPDATE,
connectorAuditEvent({
action: ConnectorAuditAction.UPDATE,
savedObject: { type: 'action', id },
error,
})
Expand All @@ -212,8 +212,8 @@ export class ActionsClient {
this.actionTypeRegistry.ensureActionTypeEnabled(actionTypeId);

this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.UPDATE,
connectorAuditEvent({
action: ConnectorAuditAction.UPDATE,
savedObject: { type: 'action', id },
outcome: EventOutcome.UNKNOWN,
})
Expand Down Expand Up @@ -256,8 +256,8 @@ export class ActionsClient {
await this.authorization.ensureAuthorized('get');
} catch (error) {
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.GET,
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
error,
})
Expand All @@ -270,8 +270,8 @@ export class ActionsClient {
);
if (preconfiguredActionsList !== undefined) {
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.GET,
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
})
);
Expand All @@ -287,8 +287,8 @@ export class ActionsClient {
const result = await this.unsecuredSavedObjectsClient.get<RawAction>('action', id);

this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.GET,
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
})
);
Expand All @@ -310,8 +310,8 @@ export class ActionsClient {
await this.authorization.ensureAuthorized('get');
} catch (error) {
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.FIND,
connectorAuditEvent({
action: ConnectorAuditAction.FIND,
error,
})
);
Expand All @@ -327,8 +327,8 @@ export class ActionsClient {

savedObjectsActions.forEach(({ id }) =>
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.FIND,
connectorAuditEvent({
action: ConnectorAuditAction.FIND,
savedObject: { type: 'action', id },
})
)
Expand Down Expand Up @@ -359,8 +359,8 @@ export class ActionsClient {
} catch (error) {
ids.forEach((id) =>
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.GET,
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
error,
})
Expand Down Expand Up @@ -394,8 +394,8 @@ export class ActionsClient {

ids.forEach((id) =>
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.GET,
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
})
)
Expand Down Expand Up @@ -435,8 +435,8 @@ export class ActionsClient {
}
} catch (error) {
this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.DELETE,
connectorAuditEvent({
action: ConnectorAuditAction.DELETE,
savedObject: { type: 'action', id },
error,
})
Expand All @@ -445,8 +445,8 @@ export class ActionsClient {
}

this.auditLogger?.log(
connectorEvent({
action: ConnectorAction.DELETE,
connectorAuditEvent({
action: ConnectorAuditAction.DELETE,
outcome: EventOutcome.UNKNOWN,
savedObject: { type: 'action', id },
})
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/actions/server/lib/audit_events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/

import { EventOutcome } from '../../../security/server/audit';
import { ConnectorAction, connectorEvent } from './audit_events';
import { ConnectorAuditAction, connectorAuditEvent } from './audit_events';

describe('#connectorEvent', () => {
describe('#connectorAuditEvent', () => {
test('creates event with `unknown` outcome', () => {
expect(
connectorEvent({
action: ConnectorAction.CREATE,
connectorAuditEvent({
action: ConnectorAuditAction.CREATE,
outcome: EventOutcome.UNKNOWN,
savedObject: { type: 'action', id: 'ACTION_ID' },
})
Expand All @@ -37,8 +37,8 @@ describe('#connectorEvent', () => {

test('creates event with `success` outcome', () => {
expect(
connectorEvent({
action: ConnectorAction.CREATE,
connectorAuditEvent({
action: ConnectorAuditAction.CREATE,
savedObject: { type: 'action', id: 'ACTION_ID' },
})
).toMatchInlineSnapshot(`
Expand All @@ -63,8 +63,8 @@ describe('#connectorEvent', () => {

test('creates event with `failure` outcome', () => {
expect(
connectorEvent({
action: ConnectorAction.CREATE,
connectorAuditEvent({
action: ConnectorAuditAction.CREATE,
savedObject: { type: 'action', id: 'ACTION_ID' },
error: new Error('ERROR_MESSAGE'),
})
Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/actions/server/lib/audit_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { AuditEvent, EventOutcome, EventCategory, EventType } from '../../../security/server';

export enum ConnectorAction {
export enum ConnectorAuditAction {
CREATE = 'connector_create',
GET = 'connector_get',
UPDATE = 'connector_update',
Expand All @@ -17,7 +17,7 @@ export enum ConnectorAction {

type VerbsTuple = [string, string, string];

const eventVerbs: Record<ConnectorAction, VerbsTuple> = {
const eventVerbs: Record<ConnectorAuditAction, VerbsTuple> = {
connector_create: ['create', 'creating', 'created'],
connector_get: ['access', 'accessing', 'accessed'],
connector_update: ['update', 'updating', 'updated'],
Expand All @@ -26,7 +26,7 @@ const eventVerbs: Record<ConnectorAction, VerbsTuple> = {
connector_execute: ['execute', 'executing', 'executed'],
};

const eventTypes: Record<ConnectorAction, EventType | undefined> = {
const eventTypes: Record<ConnectorAuditAction, EventType | undefined> = {
connector_create: EventType.CREATION,
connector_get: EventType.ACCESS,
connector_update: EventType.CHANGE,
Expand All @@ -35,19 +35,19 @@ const eventTypes: Record<ConnectorAction, EventType | undefined> = {
connector_execute: undefined,
};

export interface ConnectorEventParams {
action: ConnectorAction;
export interface ConnectorAuditEventParams {
action: ConnectorAuditAction;
outcome?: EventOutcome;
savedObject?: NonNullable<AuditEvent['kibana']>['saved_object'];
error?: Error;
}

export function connectorEvent({
export function connectorAuditEvent({
action,
savedObject,
outcome,
error,
}: ConnectorEventParams): AuditEvent {
}: ConnectorAuditEventParams): AuditEvent {
const doc = savedObject ? `connector [id=${savedObject.id}]` : 'a connector';
const [present, progressive, past] = eventVerbs[action];
const message = error
Expand Down
Loading

0 comments on commit 2873fe7

Please sign in to comment.