- Notifications
You must be signed in to change notification settings - Fork1k
fix(coderd): handle deletes and links for new agent/app audit resources#16670
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
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 |
---|---|---|
@@ -367,6 +367,26 @@ func (api *API) auditLogIsResourceDeleted(ctx context.Context, alog database.Get | ||
api.Logger.Error(ctx, "unable to fetch workspace", slog.Error(err)) | ||
} | ||
return workspace.Deleted | ||
case database.ResourceTypeWorkspaceAgent: | ||
// We use workspace as a proxy for workspace agents. | ||
workspace, err := api.Database.GetWorkspaceByAgentID(ctx, alog.AuditLog.ResourceID) | ||
if err != nil { | ||
if xerrors.Is(err, sql.ErrNoRows) { | ||
return true | ||
} | ||
api.Logger.Error(ctx, "unable to fetch workspace", slog.Error(err)) | ||
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. Review: This code-path is confusing, I feel we should return an explicit boolean here, but I simply followed existing convention. 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 agree. Do we run a db query for every single audit log row? I was unaware this function existed tbh 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. Yeah, sure looks like we call it as part of 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 created an issue:#16718 | ||
} | ||
return workspace.Deleted | ||
case database.ResourceTypeWorkspaceApp: | ||
// We use workspace as a proxy for workspace apps. | ||
workspace, err := api.Database.GetWorkspaceByWorkspaceAppID(ctx, alog.AuditLog.ResourceID) | ||
if err != nil { | ||
if xerrors.Is(err, sql.ErrNoRows) { | ||
return true | ||
} | ||
api.Logger.Error(ctx, "unable to fetch workspace", slog.Error(err)) | ||
} | ||
return workspace.Deleted | ||
case database.ResourceTypeOauth2ProviderApp: | ||
_, err := api.Database.GetOAuth2ProviderAppByID(ctx, alog.AuditLog.ResourceID) | ||
if xerrors.Is(err, sql.ErrNoRows) { | ||
@@ -429,6 +449,26 @@ func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAudit | ||
return fmt.Sprintf("/@%s/%s/builds/%s", | ||
workspaceOwner.Username, additionalFields.WorkspaceName, additionalFields.BuildNumber) | ||
case database.ResourceTypeWorkspaceAgent: | ||
if additionalFields.WorkspaceOwner != "" && additionalFields.WorkspaceName != "" { | ||
return fmt.Sprintf("/@%s/%s", additionalFields.WorkspaceOwner, additionalFields.WorkspaceName) | ||
} | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
workspace, getWorkspaceErr := api.Database.GetWorkspaceByAgentID(ctx, alog.AuditLog.ResourceID) | ||
if getWorkspaceErr != nil { | ||
return "" | ||
} | ||
return fmt.Sprintf("/@%s/%s", workspace.OwnerUsername, workspace.Name) | ||
case database.ResourceTypeWorkspaceApp: | ||
if additionalFields.WorkspaceOwner != "" && additionalFields.WorkspaceName != "" { | ||
return fmt.Sprintf("/@%s/%s", additionalFields.WorkspaceOwner, additionalFields.WorkspaceName) | ||
} | ||
workspace, getWorkspaceErr := api.Database.GetWorkspaceByWorkspaceAppID(ctx, alog.AuditLog.ResourceID) | ||
if getWorkspaceErr != nil { | ||
return "" | ||
} | ||
return fmt.Sprintf("/@%s/%s", workspace.OwnerUsername, workspace.Name) | ||
case database.ResourceTypeOauth2ProviderApp: | ||
return fmt.Sprintf("/deployment/oauth2-provider/apps/%s", alog.AuditLog.ResourceID) | ||
Uh oh!
There was an error while loading.Please reload this page.