feat: add workspace build start/stop to audit log (#4744)

* adding workspace_build resource

* added migration

* fix keyword

* got rid oof diffs for workspace builds

* adding workspace name to string

* renamed migrations

* fixed lint

* pass throough AdditionalFields and fix tests

* no need to pass through each handler

* cleaned up migrations

* generated types; fixed missing cases

* logging error
This commit is contained in:
Kira Pilot
2022-10-25 15:34:48 -04:00
committed by GitHub
parent 9070fcd5e7
commit 3c5e292c5a
13 changed files with 131 additions and 32 deletions

View File

@ -219,12 +219,26 @@ func convertAuditLog(dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
}
}
type WorkspaceResourceInfo struct {
WorkspaceName string
}
func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
str := fmt.Sprintf("{user} %s %s",
codersdk.AuditAction(alog.Action).FriendlyString(),
codersdk.ResourceType(alog.ResourceType).FriendlyString(),
)
// Strings for build updates follow the below format:
// "{user} started workspace build for workspace {target}"
// where target is a workspace instead of the workspace build
if alog.ResourceType == database.ResourceTypeWorkspaceBuild {
workspaceBytes := []byte(alog.AdditionalFields)
var workspaceResourceInfo WorkspaceResourceInfo
_ = json.Unmarshal(workspaceBytes, &workspaceResourceInfo)
str += " for workspace " + workspaceResourceInfo.WorkspaceName
}
// We don't display the name for git ssh keys. It's fairly long and doesn't
// make too much sense to display.
if alog.ResourceType != database.ResourceTypeGitSshKey {
@ -288,6 +302,8 @@ func resourceTypeFromString(resourceTypeString string) string {
return resourceTypeString
case codersdk.ResourceTypeWorkspace:
return resourceTypeString
case codersdk.ResourceTypeWorkspaceBuild:
return resourceTypeString
case codersdk.ResourceTypeGitSSHKey:
return resourceTypeString
case codersdk.ResourceTypeAPIKey: