apply requested changes

Signed-off-by: Paul Schultz <pschultz@pobox.com>
This commit is contained in:
Paul Schultz
2025-01-13 12:30:16 -06:00
parent 1a0556f015
commit a4aa244fb7
32 changed files with 344 additions and 511 deletions
@@ -137,7 +137,6 @@ export type CatalogEnvironment = {
database: DatabaseService;
config: RootConfigService;
reader: UrlReaderService;
// TODO: Require all services once `backend-legacy` is removed
permissions: PermissionsService | PermissionAuthorizer;
permissionsRegistry?: PermissionsRegistryService;
scheduler?: SchedulerService;
@@ -330,10 +330,23 @@ export async function createRouter(
});
writeSingleEntityResponse(res, entities, `No entity with uid ${uid}`);
await auditorEvent?.success({
meta: {
entities: entities,
// stringify to entity refs
entities: entities.entities.reduce((arr, element) => {
if (!element) {
return arr;
}
if (typeof element === 'string') {
arr.push(element);
return arr;
}
arr.push(stringifyEntityRef(element));
return arr;
}, [] as string[]),
},
});
} catch (err) {
@@ -793,7 +806,8 @@ export async function createRouter(
const errors = processingResult.errors.map(e => serializeError(e));
await auditorEvent?.fail({
errors: errors,
// TODO(Rugvip): Seems like there aren't proper types for AggregateError yet
error: (AggregateError as any)(errors, 'Could not validate entity'),
});
res.status(400).json({
-1
View File
@@ -634,7 +634,6 @@ export class TaskManager implements TaskContext_2 {
auth?: AuthService,
config?: Config,
additionalWorkspaceProviders?: Record<string, WorkspaceProvider>,
auditor?: AuditorService,
): TaskManager;
// (undocumented)
get createdBy(): string | undefined;
@@ -75,7 +75,6 @@ export class TaskManager implements TaskContext {
auth?: AuthService,
config?: Config,
additionalWorkspaceProviders?: Record<string, WorkspaceProvider>,
auditor?: AuditorService,
) {
const workspaceService = DefaultWorkspaceService.create(
task,
@@ -91,7 +90,6 @@ export class TaskManager implements TaskContext {
logger,
workspaceService,
auth,
auditor,
);
agent.startTimeout();
return agent;
@@ -105,7 +103,6 @@ export class TaskManager implements TaskContext {
private readonly logger: Logger,
private readonly workspaceService: WorkspaceService,
private readonly auth?: AuthService,
private readonly auditor?: AuditorService,
) {}
get spec() {
@@ -204,26 +201,6 @@ export class TaskManager implements TaskContext {
if (this.heartbeatTimeoutId) {
clearTimeout(this.heartbeatTimeoutId);
}
const auditorEvent = await this.auditor?.createEvent({
eventId: 'task',
severityLevel: 'medium',
meta: {
actionType: 'execution',
taskId: this.task.taskId,
taskParameters: this.task.spec.parameters,
},
// The initial event is created in TaskWorker
suppressInitialEvent: true,
});
if (result === 'failed') {
await auditorEvent?.fail({
error: metadata?.error as any,
});
} else {
await auditorEvent?.success();
}
}
private startTimeout() {
@@ -396,7 +373,6 @@ export class StorageTaskBroker implements TaskBroker {
this.auth,
this.config,
this.additionalWorkspaceProviders,
this.auditor,
);
}
@@ -174,7 +174,7 @@ export class TaskWorker {
}
async runOneTask(task: TaskContext) {
await this.auditor?.createEvent({
const auditorEvent = await this.auditor?.createEvent({
eventId: 'task',
severityLevel: 'medium',
meta: {
@@ -197,8 +197,12 @@ export class TaskWorker {
);
await task.complete('completed', { output });
await auditorEvent?.success();
} catch (error) {
assertError(error);
await auditorEvent?.fail({
error,
});
await task.complete('failed', {
error: { name: error.name, message: error.message },
});
@@ -589,7 +589,13 @@ export async function createRouter(
const result = validate(values, parameters);
if (!result.valid) {
await auditorEvent?.fail({ errors: result.errors });
await auditorEvent?.fail({
// TODO(Rugvip): Seems like there aren't proper types for AggregateError yet
error: (AggregateError as any)(
result.errors,
'Could not create entity',
),
});
res.status(400).json({ errors: result.errors });
return;
@@ -987,7 +993,11 @@ export async function createRouter(
const result = validate(body.values, parameters);
if (!result.valid) {
await auditorEvent?.fail({
errors: result.errors,
// TODO(Rugvip): Seems like there aren't proper types for AggregateError yet
error: (AggregateError as any)(
result.errors,
'Could not execute dry run',
),
meta: {
templateRef: templateRef,
parameters: template.spec.parameters,