mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
adding workspace_build resource (#4636)
* adding workspace_build resource * added migration * added migration for audit_actions * 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
This commit is contained in:
@@ -15,6 +15,7 @@ type Auditable interface {
|
||||
database.TemplateVersion |
|
||||
database.User |
|
||||
database.Workspace |
|
||||
database.WorkspaceBuild |
|
||||
database.GitSSHKey |
|
||||
database.Group
|
||||
}
|
||||
|
||||
+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