Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d04bf2

Browse files
authored
Revert "adding workspace_build resource (#4636)" (#4742)
This reverts commit 145faf4.
1 parent 145faf4 commit 7d04bf2

File tree

13 files changed

+31
-126
lines changed

13 files changed

+31
-126
lines changed

coderd/audit.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,12 @@ func convertAuditLog(dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
219219
}
220220
}
221221

222-
type WorkspaceResourceInfo struct {
223-
WorkspaceName string
224-
}
225-
226222
func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
227223
str := fmt.Sprintf("{user} %s %s",
228224
codersdk.AuditAction(alog.Action).FriendlyString(),
229225
codersdk.ResourceType(alog.ResourceType).FriendlyString(),
230226
)
231227

232-
// Strings for build updates follow the below format:
233-
// "{user} started workspace build for workspace {target}"
234-
// where target is a workspace instead of the workspace build
235-
if alog.ResourceType == database.ResourceTypeWorkspaceBuild {
236-
workspaceBytes := []byte(alog.AdditionalFields)
237-
var workspaceResourceInfo WorkspaceResourceInfo
238-
_ = json.Unmarshal(workspaceBytes, &workspaceResourceInfo)
239-
str += " for workspace " + workspaceResourceInfo.WorkspaceName
240-
}
241-
242228
// We don't display the name for git ssh keys. It's fairly long and doesn't
243229
// make too much sense to display.
244230
if alog.ResourceType != database.ResourceTypeGitSshKey {
@@ -302,8 +288,6 @@ func resourceTypeFromString(resourceTypeString string) string {
302288
return resourceTypeString
303289
case codersdk.ResourceTypeWorkspace:
304290
return resourceTypeString
305-
case codersdk.ResourceTypeWorkspaceBuild:
306-
return resourceTypeString
307291
case codersdk.ResourceTypeGitSSHKey:
308292
return resourceTypeString
309293
case codersdk.ResourceTypeAPIKey:

coderd/audit/diff.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type Auditable interface {
1515
database.TemplateVersion |
1616
database.User |
1717
database.Workspace |
18-
database.WorkspaceBuild |
1918
database.GitSSHKey |
2019
database.Group
2120
}

coderd/audit/request.go

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

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

2827
type Request[T Auditable] struct {
@@ -44,9 +43,6 @@ func ResourceTarget[T Auditable](tgt T) string {
4443
return typed.Username
4544
case database.Workspace:
4645
return typed.Name
47-
case database.WorkspaceBuild:
48-
// this isn't used
49-
return string(typed.BuildNumber)
5046
case database.GitSSHKey:
5147
return typed.PublicKey
5248
case database.Group:
@@ -68,8 +64,6 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
6864
return typed.ID
6965
case database.Workspace:
7066
return typed.ID
71-
case database.WorkspaceBuild:
72-
return typed.ID
7367
case database.GitSSHKey:
7468
return typed.UserID
7569
case database.Group:
@@ -91,8 +85,6 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
9185
return database.ResourceTypeUser
9286
case database.Workspace:
9387
return database.ResourceTypeWorkspace
94-
case database.WorkspaceBuild:
95-
return database.ResourceTypeWorkspaceBuild
9688
case database.GitSSHKey:
9789
return database.ResourceTypeGitSshKey
9890
case database.Group:
@@ -137,10 +129,6 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
137129
}
138130
}
139131

140-
if p.AdditionalFields == nil {
141-
p.AdditionalFields = json.RawMessage("{}")
142-
}
143-
144132
ip := parseIP(p.Request.RemoteAddr)
145133
err := p.Audit.Export(ctx, database.AuditLog{
146134
ID: uuid.New(),
@@ -155,7 +143,7 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
155143
Diff: diffRaw,
156144
StatusCode: int32(sw.Status),
157145
RequestID: httpmw.RequestID(p.Request),
158-
AdditionalFields: p.AdditionalFields,
146+
AdditionalFields: json.RawMessage("{}"),
159147
})
160148
if err != nil {
161149
p.Log.Error(logCtx, "export audit log", slog.Error(err))

coderd/database/dump.sql

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000064_add_audit_enums.down.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

coderd/database/migrations/000064_add_audit_enums.up.sql

Lines changed: 0 additions & 4 deletions
This file was deleted.

coderd/database/models.go

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspacebuilds.go

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -278,59 +278,28 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
278278
return
279279
}
280280

281-
auditor := api.Auditor.Load()
282-
283-
// if user deletes a workspace, audit the workspace
281+
// we only want to create audit logs for delete builds right now
284282
if action == rbac.ActionDelete {
285-
aReq, commitAudit := audit.InitRequest[database.Workspace](rw, &audit.RequestParams{
286-
Audit: *auditor,
287-
Log: api.Logger,
288-
Request: r,
289-
Action: database.AuditActionDelete,
290-
})
283+
var (
284+
auditor = api.Auditor.Load()
285+
aReq, commitAudit = audit.InitRequest[database.Workspace](rw, &audit.RequestParams{
286+
Audit: *auditor,
287+
Log: api.Logger,
288+
Request: r,
289+
Action: database.AuditActionDelete,
290+
})
291+
)
291292

292293
defer commitAudit()
293294
aReq.Old = workspace
294295
}
295296

296-
latestBuild, latestBuildErr := api.Database.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspace.ID)
297-
298-
// if a user starts/stops a workspace, audit the workspace build
299-
if action == rbac.ActionUpdate {
300-
var auditAction database.AuditAction
301-
if createBuild.Transition == codersdk.WorkspaceTransitionStart {
302-
auditAction = database.AuditActionStart
303-
} else if createBuild.Transition == codersdk.WorkspaceTransitionStop {
304-
auditAction = database.AuditActionStop
305-
} else {
306-
auditAction = database.AuditActionWrite
307-
}
308-
309-
// We pass the workspace name to the Auditor so that it
310-
// can form a friendly string for the user.
311-
workspaceResourceInfo := map[string]string{
312-
"workspaceName": workspace.Name,
313-
}
314-
315-
wriBytes, _ := json.Marshal(workspaceResourceInfo)
316-
317-
aReq, commitAudit := audit.InitRequest[database.WorkspaceBuild](rw, &audit.RequestParams{
318-
Audit: *auditor,
319-
Log: api.Logger,
320-
Request: r,
321-
Action: auditAction,
322-
AdditionalFields: wriBytes,
323-
})
324-
325-
defer commitAudit()
326-
aReq.Old = latestBuild
327-
}
328-
329297
if createBuild.TemplateVersionID == uuid.Nil {
330-
if latestBuildErr != nil {
298+
latestBuild, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspace.ID)
299+
if err != nil {
331300
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
332301
Message: "Internal error fetching the latest workspace build.",
333-
Detail: latestBuildErr.Error(),
302+
Detail: err.Error(),
334303
})
335304
return
336305
}

coderd/workspacebuilds_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,6 @@ func TestWorkspaceBuildStatus(t *testing.T) {
579579
require.EqualValues(t, codersdk.WorkspaceStatusDeleted, workspace.LatestBuild.Status)
580580

581581
// assert an audit log has been created for deletion
582-
require.Len(t, auditor.AuditLogs, 7)
583-
assert.Equal(t, database.AuditActionDelete, auditor.AuditLogs[6].Action)
582+
require.Len(t, auditor.AuditLogs, 5)
583+
assert.Equal(t, database.AuditActionDelete, auditor.AuditLogs[4].Action)
584584
}

codersdk/audit.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const (
1919
ResourceTypeTemplateVersion ResourceType = "template_version"
2020
ResourceTypeUser ResourceType = "user"
2121
ResourceTypeWorkspace ResourceType = "workspace"
22-
ResourceTypeWorkspaceBuild ResourceType = "workspace_build"
2322
ResourceTypeGitSSHKey ResourceType = "git_ssh_key"
2423
ResourceTypeAPIKey ResourceType = "api_key"
2524
ResourceTypeGroup ResourceType = "group"
@@ -37,8 +36,6 @@ func (r ResourceType) FriendlyString() string {
3736
return "user"
3837
case ResourceTypeWorkspace:
3938
return "workspace"
40-
case ResourceTypeWorkspaceBuild:
41-
return "workspace build"
4239
case ResourceTypeGitSSHKey:
4340
return "git ssh key"
4441
case ResourceTypeAPIKey:
@@ -56,8 +53,6 @@ const (
5653
AuditActionCreate AuditAction = "create"
5754
AuditActionWrite AuditAction = "write"
5855
AuditActionDelete AuditAction = "delete"
59-
AuditActionStart AuditAction = "start"
60-
AuditActionStop AuditAction = "stop"
6156
)
6257

6358
func (a AuditAction) FriendlyString() string {
@@ -68,10 +63,6 @@ func (a AuditAction) FriendlyString() string {
6863
return "updated"
6964
case AuditActionDelete:
7065
return "deleted"
71-
case AuditActionStart:
72-
return "started"
73-
case AuditActionStop:
74-
return "stopped"
7566
default:
7667
return "unknown"
7768
}

enterprise/audit/table.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,6 @@ var AuditableResources = auditMap(map[any]map[string]Action{
103103
"ttl": ActionTrack,
104104
"last_used_at": ActionIgnore,
105105
},
106-
// We don't show any diff for the WorkspaceBuild resource
107-
&database.WorkspaceBuild{}: {
108-
"id": ActionIgnore,
109-
"created_at": ActionIgnore,
110-
"updated_at": ActionIgnore,
111-
"workspace_id": ActionIgnore,
112-
"template_version_id": ActionIgnore,
113-
"build_number": ActionIgnore,
114-
"transition": ActionIgnore,
115-
"initiator_id": ActionIgnore,
116-
"provisioner_state": ActionIgnore,
117-
"job_id": ActionIgnore,
118-
"deadline": ActionIgnore,
119-
"reason": ActionIgnore,
120-
},
121106
&database.Group{}: {
122107
"id": ActionTrack,
123108
"name": ActionTrack,

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ export interface WorkspacesRequest extends Pagination {
915915
export type APIKeyScope = "all" | "application_connect"
916916

917917
// From codersdk/audit.go
918-
export type AuditAction = "create" | "delete" | "start" | "stop" | "write"
918+
export type AuditAction = "create" | "delete" | "write"
919919

920920
// From codersdk/workspacebuilds.go
921921
export type BuildReason = "autostart" | "autostop" | "initiator"
@@ -975,7 +975,6 @@ export type ResourceType =
975975
| "template_version"
976976
| "user"
977977
| "workspace"
978-
| "workspace_build"
979978

980979
// From codersdk/sse.go
981980
export type ServerSentEventType = "data" | "error" | "ping"

site/src/components/AuditLogRow/AuditLogRow.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
130130
</Stack>
131131
</Stack>
132132

133-
{shouldDisplayDiff ? (
134-
<div> {isDiffOpen ? <CloseDropdown /> : <OpenDropdown />}</div>
135-
) : (
136-
<div className={styles.columnWithoutDiff}></div>
137-
)}
133+
<div
134+
className={
135+
shouldDisplayDiff ? undefined : styles.disabledDropdownIcon
136+
}
137+
>
138+
{isDiffOpen ? <CloseDropdown /> : <OpenDropdown />}
139+
</div>
138140
</Stack>
139141

140142
{shouldDisplayDiff && (
@@ -188,8 +190,8 @@ const useStyles = makeStyles((theme) => ({
188190
color: theme.palette.text.secondary,
189191
whiteSpace: "nowrap",
190192
},
191-
// offset the absence of the arrow icon on diff-less logs
192-
columnWithoutDiff: {
193-
marginLeft: "24px",
193+
194+
disabledDropdownIcon: {
195+
opacity: 0.5,
194196
},
195197
}))

0 commit comments

Comments
 (0)