- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
1f9ccfa
13159ba
f1de717
17aaa38
e17abf1
69cdf39
cb4b5ee
2a3ce9d
2caba31
00c073f
850735e
8eab0d0
bdf48bb
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
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. I would prefer not to add this here and instead to use the | ||
} | ||
// 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: | ||
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 | ||
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 resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
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: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 abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
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 abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.