@@ -182,17 +182,17 @@ func (api *API) convertAuditLogs(ctx context.Context, dblogs []database.GetAudit
182
182
}
183
183
184
184
func (api * API ) convertAuditLog (ctx context.Context , dblog database.GetAuditLogsOffsetRow ) codersdk.AuditLog {
185
- ip , _ := netip .AddrFromSlice (dblog .Ip .IPNet .IP )
185
+ ip , _ := netip .AddrFromSlice (dblog .AuditLog . Ip .IPNet .IP )
186
186
187
187
diff := codersdk.AuditDiff {}
188
- _ = json .Unmarshal (dblog .Diff , & diff )
188
+ _ = json .Unmarshal (dblog .AuditLog . Diff , & diff )
189
189
190
190
var user * codersdk.User
191
191
if dblog .UserUsername .Valid {
192
192
// Leaving the organization IDs blank for now; not sure they are useful for
193
193
// the audit query anyway?
194
194
sdkUser := db2sdk .User (database.User {
195
- ID : dblog .UserID ,
195
+ ID : dblog .AuditLog . UserID ,
196
196
Email : dblog .UserEmail .String ,
197
197
Username : dblog .UserUsername .String ,
198
198
CreatedAt : dblog .UserCreatedAt .Time ,
@@ -211,7 +211,7 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
211
211
}
212
212
213
213
var (
214
- additionalFieldsBytes = []byte (dblog .AdditionalFields )
214
+ additionalFieldsBytes = []byte (dblog .AuditLog . AdditionalFields )
215
215
additionalFields audit.AdditionalFields
216
216
err = json .Unmarshal (additionalFieldsBytes , & additionalFields )
217
217
)
@@ -224,7 +224,7 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
224
224
WorkspaceOwner : "unknown" ,
225
225
}
226
226
227
- dblog .AdditionalFields , err = json .Marshal (resourceInfo )
227
+ dblog .AuditLog . AdditionalFields , err = json .Marshal (resourceInfo )
228
228
api .Logger .Error (ctx , "marshal additional fields" , slog .Error (err ))
229
229
}
230
230
@@ -239,30 +239,30 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
239
239
}
240
240
241
241
alog := codersdk.AuditLog {
242
- ID : dblog .ID ,
243
- RequestID : dblog .RequestID ,
244
- Time : dblog .Time ,
242
+ ID : dblog .AuditLog . ID ,
243
+ RequestID : dblog .AuditLog . RequestID ,
244
+ Time : dblog .AuditLog . Time ,
245
245
// OrganizationID is deprecated.
246
- OrganizationID : dblog .OrganizationID ,
246
+ OrganizationID : dblog .AuditLog . OrganizationID ,
247
247
IP : ip ,
248
- UserAgent : dblog .UserAgent .String ,
249
- ResourceType : codersdk .ResourceType (dblog .ResourceType ),
250
- ResourceID : dblog .ResourceID ,
251
- ResourceTarget : dblog .ResourceTarget ,
252
- ResourceIcon : dblog .ResourceIcon ,
253
- Action : codersdk .AuditAction (dblog .Action ),
248
+ UserAgent : dblog .AuditLog . UserAgent .String ,
249
+ ResourceType : codersdk .ResourceType (dblog .AuditLog . ResourceType ),
250
+ ResourceID : dblog .AuditLog . ResourceID ,
251
+ ResourceTarget : dblog .AuditLog . ResourceTarget ,
252
+ ResourceIcon : dblog .AuditLog . ResourceIcon ,
253
+ Action : codersdk .AuditAction (dblog .AuditLog . Action ),
254
254
Diff : diff ,
255
- StatusCode : dblog .StatusCode ,
256
- AdditionalFields : dblog .AdditionalFields ,
255
+ StatusCode : dblog .AuditLog . StatusCode ,
256
+ AdditionalFields : dblog .AuditLog . AdditionalFields ,
257
257
User : user ,
258
258
Description : auditLogDescription (dblog ),
259
259
ResourceLink : resourceLink ,
260
260
IsDeleted : isDeleted ,
261
261
}
262
262
263
- if dblog .OrganizationID != uuid .Nil {
263
+ if dblog .AuditLog . OrganizationID != uuid .Nil {
264
264
alog .Organization = & codersdk.MinimalOrganization {
265
- ID : dblog .OrganizationID ,
265
+ ID : dblog .AuditLog . OrganizationID ,
266
266
Name : dblog .OrganizationName ,
267
267
DisplayName : dblog .OrganizationDisplayName ,
268
268
Icon : dblog .OrganizationIcon ,
@@ -276,32 +276,32 @@ func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
276
276
b := strings.Builder {}
277
277
// NOTE: WriteString always returns a nil error, so we never check it
278
278
_ , _ = b .WriteString ("{user} " )
279
- if alog .StatusCode >= 400 {
279
+ if alog .AuditLog . StatusCode >= 400 {
280
280
_ , _ = b .WriteString ("unsuccessfully attempted to " )
281
- _ , _ = b .WriteString (string (alog .Action ))
281
+ _ , _ = b .WriteString (string (alog .AuditLog . Action ))
282
282
} else {
283
- _ , _ = b .WriteString (codersdk .AuditAction (alog .Action ).Friendly ())
283
+ _ , _ = b .WriteString (codersdk .AuditAction (alog .AuditLog . Action ).Friendly ())
284
284
}
285
285
286
286
// API Key resources (used for authentication) do not have targets and follow the below format:
287
287
// "User {logged in | logged out | registered}"
288
- if alog .ResourceType == database .ResourceTypeApiKey &&
289
- (alog .Action == database .AuditActionLogin || alog .Action == database .AuditActionLogout || alog .Action == database .AuditActionRegister ) {
288
+ if alog .AuditLog . ResourceType == database .ResourceTypeApiKey &&
289
+ (alog .AuditLog . Action == database .AuditActionLogin || alog .AuditLog . Action == database .AuditActionLogout || alog . AuditLog .Action == database .AuditActionRegister ) {
290
290
return b .String ()
291
291
}
292
292
293
293
// We don't display the name (target) for git ssh keys. It's fairly long and doesn't
294
294
// make too much sense to display.
295
- if alog .ResourceType == database .ResourceTypeGitSshKey {
295
+ if alog .AuditLog . ResourceType == database .ResourceTypeGitSshKey {
296
296
_ , _ = b .WriteString (" the " )
297
- _ , _ = b .WriteString (codersdk .ResourceType (alog .ResourceType ).FriendlyString ())
297
+ _ , _ = b .WriteString (codersdk .ResourceType (alog .AuditLog . ResourceType ).FriendlyString ())
298
298
return b .String ()
299
299
}
300
300
301
301
_ , _ = b .WriteString (" " )
302
- _ , _ = b .WriteString (codersdk .ResourceType (alog .ResourceType ).FriendlyString ())
302
+ _ , _ = b .WriteString (codersdk .ResourceType (alog .AuditLog . ResourceType ).FriendlyString ())
303
303
304
- if alog .ResourceType == database .ResourceTypeConvertLogin {
304
+ if alog .AuditLog . ResourceType == database .ResourceTypeConvertLogin {
305
305
_ , _ = b .WriteString (" to" )
306
306
}
307
307
@@ -311,9 +311,9 @@ func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
311
311
}
312
312
313
313
func (api * API ) auditLogIsResourceDeleted (ctx context.Context , alog database.GetAuditLogsOffsetRow ) bool {
314
- switch alog .ResourceType {
314
+ switch alog .AuditLog . ResourceType {
315
315
case database .ResourceTypeTemplate :
316
- template , err := api .Database .GetTemplateByID (ctx , alog .ResourceID )
316
+ template , err := api .Database .GetTemplateByID (ctx , alog .AuditLog . ResourceID )
317
317
if err != nil {
318
318
if xerrors .Is (err , sql .ErrNoRows ) {
319
319
return true
@@ -322,7 +322,7 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
322
322
}
323
323
return template .Deleted
324
324
case database .ResourceTypeUser :
325
- user , err := api .Database .GetUserByID (ctx , alog .ResourceID )
325
+ user , err := api .Database .GetUserByID (ctx , alog .AuditLog . ResourceID )
326
326
if err != nil {
327
327
if xerrors .Is (err , sql .ErrNoRows ) {
328
328
return true
@@ -331,7 +331,7 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
331
331
}
332
332
return user .Deleted
333
333
case database .ResourceTypeWorkspace :
334
- workspace , err := api .Database .GetWorkspaceByID (ctx , alog .ResourceID )
334
+ workspace , err := api .Database .GetWorkspaceByID (ctx , alog .AuditLog . ResourceID )
335
335
if err != nil {
336
336
if xerrors .Is (err , sql .ErrNoRows ) {
337
337
return true
@@ -340,7 +340,7 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
340
340
}
341
341
return workspace .Deleted
342
342
case database .ResourceTypeWorkspaceBuild :
343
- workspaceBuild , err := api .Database .GetWorkspaceBuildByID (ctx , alog .ResourceID )
343
+ workspaceBuild , err := api .Database .GetWorkspaceBuildByID (ctx , alog .AuditLog . ResourceID )
344
344
if err != nil {
345
345
if xerrors .Is (err , sql .ErrNoRows ) {
346
346
return true
@@ -357,15 +357,15 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
357
357
}
358
358
return workspace .Deleted
359
359
case database .ResourceTypeOauth2ProviderApp :
360
- _ , err := api .Database .GetOAuth2ProviderAppByID (ctx , alog .ResourceID )
360
+ _ , err := api .Database .GetOAuth2ProviderAppByID (ctx , alog .AuditLog . ResourceID )
361
361
if xerrors .Is (err , sql .ErrNoRows ) {
362
362
return true
363
363
} else if err != nil {
364
364
api .Logger .Error (ctx , "unable to fetch oauth2 app" , slog .Error (err ))
365
365
}
366
366
return false
367
367
case database .ResourceTypeOauth2ProviderAppSecret :
368
- _ , err := api .Database .GetOAuth2ProviderAppSecretByID (ctx , alog .ResourceID )
368
+ _ , err := api .Database .GetOAuth2ProviderAppSecretByID (ctx , alog .AuditLog . ResourceID )
369
369
if xerrors .Is (err , sql .ErrNoRows ) {
370
370
return true
371
371
} else if err != nil {
@@ -378,17 +378,17 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get
378
378
}
379
379
380
380
func (api * API ) auditLogResourceLink (ctx context.Context , alog database.GetAuditLogsOffsetRow , additionalFields audit.AdditionalFields ) string {
381
- switch alog .ResourceType {
381
+ switch alog .AuditLog . ResourceType {
382
382
case database .ResourceTypeTemplate :
383
383
return fmt .Sprintf ("/templates/%s" ,
384
- alog .ResourceTarget )
384
+ alog .AuditLog . ResourceTarget )
385
385
386
386
case database .ResourceTypeUser :
387
387
return fmt .Sprintf ("/users?filter=%s" ,
388
- alog .ResourceTarget )
388
+ alog .AuditLog . ResourceTarget )
389
389
390
390
case database .ResourceTypeWorkspace :
391
- workspace , getWorkspaceErr := api .Database .GetWorkspaceByID (ctx , alog .ResourceID )
391
+ workspace , getWorkspaceErr := api .Database .GetWorkspaceByID (ctx , alog .AuditLog . ResourceID )
392
392
if getWorkspaceErr != nil {
393
393
return ""
394
394
}
@@ -397,13 +397,13 @@ func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAudit
397
397
return ""
398
398
}
399
399
return fmt .Sprintf ("/@%s/%s" ,
400
- workspaceOwner .Username , alog .ResourceTarget )
400
+ workspaceOwner .Username , alog .AuditLog . ResourceTarget )
401
401
402
402
case database .ResourceTypeWorkspaceBuild :
403
403
if len (additionalFields .WorkspaceName ) == 0 || len (additionalFields .BuildNumber ) == 0 {
404
404
return ""
405
405
}
406
- workspaceBuild , getWorkspaceBuildErr := api .Database .GetWorkspaceBuildByID (ctx , alog .ResourceID )
406
+ workspaceBuild , getWorkspaceBuildErr := api .Database .GetWorkspaceBuildByID (ctx , alog .AuditLog . ResourceID )
407
407
if getWorkspaceBuildErr != nil {
408
408
return ""
409
409
}
@@ -419,10 +419,10 @@ func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAudit
419
419
workspaceOwner .Username , additionalFields .WorkspaceName , additionalFields .BuildNumber )
420
420
421
421
case database .ResourceTypeOauth2ProviderApp :
422
- return fmt .Sprintf ("/deployment/oauth2-provider/apps/%s" , alog .ResourceID )
422
+ return fmt .Sprintf ("/deployment/oauth2-provider/apps/%s" , alog .AuditLog . ResourceID )
423
423
424
424
case database .ResourceTypeOauth2ProviderAppSecret :
425
- secret , err := api .Database .GetOAuth2ProviderAppSecretByID (ctx , alog .ResourceID )
425
+ secret , err := api .Database .GetOAuth2ProviderAppSecretByID (ctx , alog .AuditLog . ResourceID )
426
426
if err != nil {
427
427
return ""
428
428
}
0 commit comments