Skip to content

Commit

Permalink
apply requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Schultz <[email protected]>
  • Loading branch information
schultzp2020 committed Jan 20, 2025
1 parent 1a0556f commit a4aa244
Show file tree
Hide file tree
Showing 32 changed files with 342 additions and 509 deletions.
7 changes: 7 additions & 0 deletions .changeset/olive-boxes-hide-backend-defaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/backend-defaults': minor
---

feat: add auditor to `coreServices`

This change introduces the `auditor` service implementation details.
7 changes: 7 additions & 0 deletions .changeset/olive-boxes-hide-backend-plugin-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/backend-plugin-api': minor
---

feat: add auditor to `coreServices`

This change introduces the `auditor` service definition.
7 changes: 7 additions & 0 deletions .changeset/olive-boxes-hide-backend-test-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/backend-test-utils': minor
---

feat: add auditor to `coreServices`

This change introduces mocks for the `auditor` service.
7 changes: 7 additions & 0 deletions .changeset/olive-boxes-hide-catalog-backend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/plugin-catalog-backend': minor
---

feat: add auditor to `coreServices`

This change integrates the `auditor` service into the Catalog plugin.
7 changes: 7 additions & 0 deletions .changeset/olive-boxes-hide-scaffolder-backend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/plugin-scaffolder-backend': minor
---

feat: add auditor to `coreServices`

This change integrates the `auditor` service into the Scaffolder plugin.
7 changes: 7 additions & 0 deletions .changeset/olive-boxes-hide-scaffolder-node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/plugin-scaffolder-node': minor
---

feat: add auditor to `coreServices`

This change introduces an optional `taskId` property to `TaskContext`.
13 changes: 0 additions & 13 deletions .changeset/olive-boxes-hide.md

This file was deleted.

17 changes: 0 additions & 17 deletions docs/backend-system/core-services/auditor.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,3 @@ When defining `eventId` and `subEventId` for your audit events, follow these gui
- Use `subEventId` to further categorize events within a logical group. For example, if the `eventId` is "fetch", the `subEventId` could be "by-id" or "by-location" to specify the method used for fetching.
- Avoid redundant prefixes related to the plugin ID, as that context is already provided.
- Choose names that clearly and concisely describe the event being audited.

## Configuring the service

The Auditor Service can be configured using the `backend.auditor` section in your `app-config.yaml` file.

### Console Logging

Console logging allows you to see audit events directly in your terminal output. This is useful for development and debugging purposes. To enable console logging, set the `enabled` flag to `true` within the `console` section:

```yaml
backend:
auditor:
console:
enabled: true
```
By default, console logging is enabled. You can disable it by setting the `enabled` flag to `false`.
12 changes: 0 additions & 12 deletions packages/backend-defaults/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,18 +632,6 @@ export interface Config {
paths?: string[];
}>;
};
auditor?: {
/**
* Configuration for the auditing to the console
*/
console: {
/**
* Enables auditing to console
* @default true
*/
enabled: boolean;
};
};
};

/**
Expand Down
54 changes: 25 additions & 29 deletions packages/backend-defaults/report-auditor.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import type { AuditorCreateEvent } from '@backstage/backend-plugin-api';
import type { AuditorEventSeverityLevel } from '@backstage/backend-plugin-api';
import { AuditorService } from '@backstage/backend-plugin-api';
import type { AuditorServiceCreateEventOptions } from '@backstage/backend-plugin-api';
import type { AuditorServiceEvent } from '@backstage/backend-plugin-api';
import type { AuditorServiceEventSeverityLevel } from '@backstage/backend-plugin-api';
import type { AuthService } from '@backstage/backend-plugin-api';
import type { Format } from 'logform';
import type { HttpAuthService } from '@backstage/backend-plugin-api';
import type { JsonObject } from '@backstage/types';
import type { PluginMetadataService } from '@backstage/backend-plugin-api';
import type { Request as Request_2 } from 'express';
import type { RootLoggerService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
import * as winston from 'winston';

// @public
export type AuditorEvent = [
eventId: string,
meta: {
severityLevel: AuditorEventSeverityLevel;
severityLevel: AuditorServiceEventSeverityLevel;
actor: AuditorEventActorDetails;
meta?: JsonObject;
request?: AuditorEventRequest;
Expand All @@ -37,7 +39,7 @@ export type AuditorEventActorDetails = {
// @public
export type AuditorEventOptions<TMeta extends JsonObject> = {
eventId: string;
severityLevel?: AuditorEventSeverityLevel;
severityLevel?: AuditorServiceEventSeverityLevel;
request?: Request_2<any, any, any, any, any>;
meta?: TMeta;
} & AuditorEventStatus;
Expand All @@ -49,23 +51,17 @@ export type AuditorEventRequest = {
};

// @public (undocumented)
export type AuditorEventStatus<TError extends Error = Error> =
export type AuditorEventStatus =
| {
status: 'initiated';
}
| {
status: 'succeeded';
}
| ({
| {
status: 'failed';
} & (
| {
error: TError;
}
| {
errors: TError[];
}
));
error: Error;
};

// @public
export const auditorFieldFormat: Format;
Expand All @@ -88,17 +84,16 @@ export class DefaultAuditorService implements AuditorService {
},
): DefaultAuditorService;
// (undocumented)
createEvent<TMeta extends JsonObject>(
options: Parameters<AuditorCreateEvent<TMeta>>[0],
): ReturnType<AuditorCreateEvent<TMeta>>;
createEvent(
options: AuditorServiceCreateEventOptions,
): Promise<AuditorServiceEvent>;
}

// @public (undocumented)
export const defaultProdFormat: Format;
export const defaultFormatter: Format;

// @public (undocumented)
export class DefaultRootAuditorService {
static colorFormat(): Format;
static create(options?: RootAuditorOptions): DefaultRootAuditorService;
// (undocumented)
forPlugin(deps: {
Expand All @@ -107,18 +102,19 @@ export class DefaultRootAuditorService {
plugin: PluginMetadataService;
}): AuditorService;
// (undocumented)
log(auditEvent: AuditorEvent): Promise<void>;
log(auditorEvent: AuditorEvent): Promise<void>;
}

// @public (undocumented)
export interface RootAuditorOptions {
// (undocumented)
format?: Format;
// (undocumented)
meta?: JsonObject;
// (undocumented)
transports?: winston.transport[];
}
// @public
export type RootAuditorOptions =
| {
meta?: JsonObject;
format?: Format;
transports?: winston.transport[];
}
| {
rootLogger: RootLoggerService;
};

// (No @packageDocumentation comment for this package)
```
41 changes: 0 additions & 41 deletions packages/backend-defaults/src/entrypoints/auditor/Auditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/

import { mockServices } from '@backstage/backend-test-utils';
import { format } from 'logform';
import { MESSAGE } from 'triple-beam';
import Transport from 'winston-transport';
import { DefaultAuditorService, DefaultRootAuditorService } from './Auditor';

describe('Auditor', () => {
Expand All @@ -38,44 +35,6 @@ describe('Auditor', () => {
expect(childLogger).toBeInstanceOf(DefaultAuditorService);
});

it('should log', async () => {
const mockTransport = new Transport({
log: jest.fn(),
logv: jest.fn(),
});

const pluginId = 'test-plugin';

const auditor = DefaultRootAuditorService.create({
format: format.json(),
transports: [mockTransport],
}).forPlugin({
auth: mockServices.auth.mock(),
httpAuth: mockServices.httpAuth.mock(),
plugin: {
getId: () => pluginId,
},
});

await auditor.createEvent({
eventId: 'test-event',
});

expect(mockTransport.log).toHaveBeenCalledWith(
expect.objectContaining({
[MESSAGE]: JSON.stringify({
actor: {},
isAuditorEvent: true,
level: 'info',
message: 'test-plugin.test-event',
severityLevel: 'low',
status: 'initiated',
}),
}),
expect.any(Function),
);
});

it('should log a status "initiated" using createEvent', async () => {
const pluginId = 'test-plugin';

Expand Down
Loading

0 comments on commit a4aa244

Please sign in to comment.