feat: add audit logs to scaffolder-backend plugin

Signed-off-by: David Rubio Vidal <david.rubiovidal@dazn.com>
This commit is contained in:
David Rubio Vidal
2022-06-30 14:18:47 +02:00
parent 81746eb44b
commit 8a1987a7b2
2 changed files with 38 additions and 1 deletions
+9
View File
@@ -286,6 +286,15 @@ scaffolder:
# email: scaffolder@backstage.io
# Use to customize the default commit message when new components are created
# defaultCommitMessage: 'Initial commit'
# Use to customize the audit log emitted when a template task is created
auditlog:
enabled: true
# Properties of the user entity metadata (i.e. userEntity.metadata.name)
identityMetadata:
- name
# Annotations under the user entity metadata (i.e. userEntity.metadata.annotations['name/of-annotation'])
# identityAnnotations:
# # - name/of-annotation
auth:
### Add auth.keyStore.provider to more granularly control how to store JWK data when running
@@ -193,7 +193,35 @@ export async function createRouter(
? await catalogClient.getEntityByRef(userEntityRef, { token })
: undefined;
logger.info(`POST /v2/tasks from ${userEntity?.metadata.name}`);
const auditlogEnabled = config.getOptionalBoolean(
'scaffolder.auditlog.enabled',
);
if (auditlogEnabled) {
const identityMetadata = config.getOptionalStringArray(
'scaffolder.auditlog.identityMetadata',
);
const identityAnnotations = config.getOptionalStringArray(
'scaffolder.auditlog.identityAnnotations',
);
const logMe: { [key: string]: string }[] = [];
identityMetadata?.forEach((prop: string) =>
logMe.push({ [prop]: userEntity?.metadata[prop] as string }),
);
identityAnnotations?.forEach((prop: string) =>
logMe.push({
[prop]: userEntity?.metadata.annotations?.[prop] as string,
}),
);
logger.info(
`Scaffolding template '${templateRef}'. ${
logMe.length > 0 && JSON.stringify(logMe)
}`,
);
}
const values = req.body.values;