Skip to content

Commit 69cdf39

Browse files
committed
adding workspace name to string
1 parent e17abf1 commit 69cdf39

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

coderd/audit.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ func convertAuditLog(dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
220220
}
221221
}
222222

223+
type WorkspaceResourceInfo struct {
224+
WorkspaceName string
225+
}
226+
223227
func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
224228
str := fmt.Sprintf("{user} %s %s",
225229
codersdk.AuditAction(alog.Action).FriendlyString(),
@@ -230,7 +234,10 @@ func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
230234
// "{user} started workspace build for workspace {target}"
231235
// where target is a workspace instead of the workspace build
232236
if alog.ResourceType == database.ResourceTypeWorkspaceBuild {
233-
str += " for workspace"
237+
workspace_bytes := []byte(alog.AdditionalFields)
238+
var workspaceResourceInfo WorkspaceResourceInfo
239+
json.Unmarshal(workspace_bytes, &workspaceResourceInfo)
240+
str += " for workspace " + workspaceResourceInfo.WorkspaceName
234241
}
235242

236243
// We don't display the name for git ssh keys. It's fairly long and doesn't

coderd/audit/request.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ type RequestParams struct {
2020
Audit Auditor
2121
Log slog.Logger
2222

23-
Request *http.Request
24-
Action database.AuditAction
23+
Request *http.Request
24+
Action database.AuditAction
25+
AdditionalFields json.RawMessage
2526
}
2627

2728
type Request[T Auditable] struct {
@@ -44,7 +45,8 @@ func ResourceTarget[T Auditable](tgt T) string {
4445
case database.Workspace:
4546
return typed.Name
4647
case database.WorkspaceBuild:
47-
return string(typed.Transition)
48+
// this isn't used
49+
return string(typed.BuildNumber)
4850
case database.GitSSHKey:
4951
return typed.PublicKey
5052
default:
@@ -147,7 +149,7 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
147149
Diff: diffRaw,
148150
StatusCode: int32(sw.Status),
149151
RequestID: httpmw.RequestID(p.Request),
150-
AdditionalFields: json.RawMessage("{}"),
152+
AdditionalFields: p.AdditionalFields,
151153
})
152154
if err != nil {
153155
p.Log.Error(logCtx, "export audit log", slog.Error(err))

coderd/workspacebuilds.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,21 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
309309
auditAction = database.AuditActionWrite
310310
}
311311

312+
// We pass the workspace name to the Auditor so that it
313+
// can form a friendly string for the user.
314+
workspaceResourceInfo := map[string]string{
315+
"workspaceName": workspace.Name,
316+
}
317+
318+
wri_bytes, _ := json.Marshal(workspaceResourceInfo)
319+
312320
var (
313321
aReq, commitAudit = audit.InitRequest[database.WorkspaceBuild](rw, &audit.RequestParams{
314-
Audit: *auditor,
315-
Log: api.Logger,
316-
Request: r,
317-
Action: auditAction,
322+
Audit: *auditor,
323+
Log: api.Logger,
324+
Request: r,
325+
Action: auditAction,
326+
AdditionalFields: wri_bytes,
318327
})
319328
)
320329

0 commit comments

Comments
 (0)