Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8a573e

Browse files
committed
feat(coderd): add audit resource for tasks
Updatescoder/internal#976
1 parente0b1536 commitf8a573e

File tree

12 files changed

+51
-7
lines changed

12 files changed

+51
-7
lines changed

‎coderd/apidoc/docs.go‎

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

‎coderd/apidoc/swagger.json‎

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

‎coderd/audit.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,14 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
420420
api.Logger.Error(ctx,"unable to fetch oauth2 app secret",slog.Error(err))
421421
}
422422
returnfalse
423+
casedatabase.ResourceTypeTask:
424+
task,err:=api.Database.GetTaskByID(ctx,alog.AuditLog.ResourceID)
425+
ifxerrors.Is(err,sql.ErrNoRows) {
426+
returntrue
427+
}elseiferr!=nil {
428+
api.Logger.Error(ctx,"unable to fetch task",slog.Error(err))
429+
}
430+
returntask.DeletedAt.Valid&&task.DeletedAt.Time.Before(time.Now())
423431
default:
424432
returnfalse
425433
}
@@ -496,6 +504,17 @@ func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAudit
496504
}
497505
returnfmt.Sprintf("/deployment/oauth2-provider/apps/%s",secret.AppID)
498506

507+
casedatabase.ResourceTypeTask:
508+
task,err:=api.Database.GetTaskByID(ctx,alog.AuditLog.ResourceID)
509+
iferr!=nil {
510+
return""
511+
}
512+
workspace,err:=api.Database.GetWorkspaceByID(ctx,task.WorkspaceID.UUID)
513+
iferr!=nil {
514+
return""
515+
}
516+
returnfmt.Sprintf("/tasks/%s/%s",workspace.OwnerName,task.Name)
517+
499518
default:
500519
return""
501520
}

‎coderd/audit/diff.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ type Auditable interface {
3131
database.NotificationTemplate|
3232
idpsync.OrganizationSyncSettings|
3333
idpsync.GroupSyncSettings|
34-
idpsync.RoleSyncSettings
34+
idpsync.RoleSyncSettings|
35+
database.TaskTable
3536
}
3637

3738
// Map is a map of changed fields in an audited resource. It maps field names to

‎coderd/audit/request.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ func ResourceTarget[T Auditable](tgt T) string {
131131
return"Organization Group Sync"
132132
case idpsync.RoleSyncSettings:
133133
return"Organization Role Sync"
134+
case database.Task:
135+
returntyped.Name
134136
default:
135137
panic(fmt.Sprintf("unknown resource %T for ResourceTarget",tgt))
136138
}
@@ -193,6 +195,8 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
193195
returnnoID// Org field on audit log has org id
194196
case idpsync.RoleSyncSettings:
195197
returnnoID// Org field on audit log has org id
198+
case database.Task:
199+
returntyped.ID
196200
default:
197201
panic(fmt.Sprintf("unknown resource %T for ResourceID",tgt))
198202
}
@@ -246,6 +250,8 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
246250
returndatabase.ResourceTypeIdpSyncSettingsRole
247251
case idpsync.GroupSyncSettings:
248252
returndatabase.ResourceTypeIdpSyncSettingsGroup
253+
case database.TaskTable:
254+
returndatabase.ResourceTypeTask
249255
default:
250256
panic(fmt.Sprintf("unknown resource %T for ResourceType",typed))
251257
}
@@ -302,6 +308,8 @@ func ResourceRequiresOrgID[T Auditable]() bool {
302308
returntrue
303309
case idpsync.RoleSyncSettings:
304310
returntrue
311+
case database.Task:
312+
returntrue
305313
default:
306314
panic(fmt.Sprintf("unknown resource %T for ResourceRequiresOrgID",tgt))
307315
}

‎coderd/database/dump.sql‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Nothing to do
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTERTYPE resource_type ADD VALUE IF NOT EXISTS'task';

‎coderd/database/models.go‎

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎codersdk/audit.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
// Deprecated: Workspace App connections are now included in the
4545
// connection log.
4646
ResourceTypeWorkspaceAppResourceType="workspace_app"
47+
ResourceTypeTaskResourceType="task"
4748
)
4849

4950
func (rResourceType)FriendlyString()string {
@@ -100,6 +101,8 @@ func (r ResourceType) FriendlyString() string {
100101
return"workspace agent"
101102
caseResourceTypeWorkspaceApp:
102103
return"workspace app"
104+
caseResourceTypeTask:
105+
return"task"
103106
default:
104107
return"unknown"
105108
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp