mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -16,7 +16,8 @@ type Auditable interface {
|
||||
database.User |
|
||||
database.Workspace |
|
||||
database.GitSSHKey |
|
||||
database.Group
|
||||
database.Group |
|
||||
database.WorkspaceBuild
|
||||
}
|
||||
|
||||
// Map is a map of changed fields in an audited resource. It maps field names to
|
||||
|
||||
+15
-3
@@ -20,8 +20,9 @@ type RequestParams struct {
|
||||
Audit Auditor
|
||||
Log slog.Logger
|
||||
|
||||
Request *http.Request
|
||||
Action database.AuditAction
|
||||
Request *http.Request
|
||||
Action database.AuditAction
|
||||
AdditionalFields json.RawMessage
|
||||
}
|
||||
|
||||
type Request[T Auditable] struct {
|
||||
@@ -43,6 +44,9 @@ func ResourceTarget[T Auditable](tgt T) string {
|
||||
return typed.Username
|
||||
case database.Workspace:
|
||||
return typed.Name
|
||||
case database.WorkspaceBuild:
|
||||
// this isn't used
|
||||
return string(typed.BuildNumber)
|
||||
case database.GitSSHKey:
|
||||
return typed.PublicKey
|
||||
case database.Group:
|
||||
@@ -64,6 +68,8 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
|
||||
return typed.ID
|
||||
case database.Workspace:
|
||||
return typed.ID
|
||||
case database.WorkspaceBuild:
|
||||
return typed.ID
|
||||
case database.GitSSHKey:
|
||||
return typed.UserID
|
||||
case database.Group:
|
||||
@@ -85,6 +91,8 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
|
||||
return database.ResourceTypeUser
|
||||
case database.Workspace:
|
||||
return database.ResourceTypeWorkspace
|
||||
case database.WorkspaceBuild:
|
||||
return database.ResourceTypeWorkspaceBuild
|
||||
case database.GitSSHKey:
|
||||
return database.ResourceTypeGitSshKey
|
||||
case database.Group:
|
||||
@@ -129,6 +137,10 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
|
||||
}
|
||||
}
|
||||
|
||||
if p.AdditionalFields == nil {
|
||||
p.AdditionalFields = json.RawMessage("{}")
|
||||
}
|
||||
|
||||
ip := parseIP(p.Request.RemoteAddr)
|
||||
err := p.Audit.Export(ctx, database.AuditLog{
|
||||
ID: uuid.New(),
|
||||
@@ -143,7 +155,7 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
|
||||
Diff: diffRaw,
|
||||
StatusCode: int32(sw.Status),
|
||||
RequestID: httpmw.RequestID(p.Request),
|
||||
AdditionalFields: json.RawMessage("{}"),
|
||||
AdditionalFields: p.AdditionalFields,
|
||||
})
|
||||
if err != nil {
|
||||
p.Log.Error(logCtx, "export audit log", slog.Error(err))
|
||||
|
||||
Reference in New Issue
Block a user