-
Notifications
You must be signed in to change notification settings - Fork 888
adding workspace_build resource #4636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f9ccfa
13159ba
f1de717
17aaa38
e17abf1
69cdf39
cb4b5ee
2a3ce9d
2caba31
00c073f
850735e
8eab0d0
bdf48bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ug tell me there's a better way. |
||
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 | ||
Kira-Pilot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT | ||
-- EXISTS". |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TYPE audit_action ADD VALUE IF NOT EXISTS 'start'; | ||
ALTER TYPE audit_action ADD VALUE IF NOT EXISTS 'stop'; | ||
|
||
ALTER TYPE resource_type ADD VALUE IF NOT EXISTS 'workspace_build'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to add this here and instead to use the
ResourceTarget
function.