-
Notifications
You must be signed in to change notification settings - Fork 887
feat: add audit logs for dormancy events #15298
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e137e92
e84b893
388111b
850ee38
7d2b532
68adf8a
764bc25
7846882
cd77405
95ac736
b6c043d
b3269d1
3829773
6fdb233
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package audit | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"cdr.dev/slog" | ||
) | ||
|
||
type BackgroundSubsystem string | ||
|
||
const ( | ||
BackgroundSubsystemDormancy BackgroundSubsystem = "dormancy" | ||
) | ||
|
||
func BackgroundTaskFields(subsystem BackgroundSubsystem) map[string]string { | ||
return map[string]string{ | ||
"automatic_actor": "coder", | ||
"automatic_subsystem": string(subsystem), | ||
} | ||
} | ||
|
||
func BackgroundTaskFieldsBytes(ctx context.Context, logger slog.Logger, subsystem BackgroundSubsystem) []byte { | ||
af := BackgroundTaskFields(subsystem) | ||
|
||
wriBytes, err := json.Marshal(af) | ||
if err != nil { | ||
logger.Error(ctx, "marshal additional fields for dormancy audit", slog.Error(err)) | ||
return []byte("{}") | ||
} | ||
|
||
return wriBytes | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,10 +67,15 @@ INSERT INTO | |
created_at, | ||
updated_at, | ||
rbac_roles, | ||
login_type | ||
login_type, | ||
status | ||
) | ||
VALUES | ||
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *; | ||
($1, $2, $3, $4, $5, $6, $7, $8, $9, | ||
-- if the status passed in is empty, fallback to dormant, which is what | ||
-- we were doing before. | ||
COALESCE(NULLIF(@status::text, '')::user_status, 'dormant'::user_status) | ||
) RETURNING *; | ||
Comment on lines
+74
to
+78
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. why do we handle this as a special case? Shouldn't we expect the status to be provided? 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 didn't really want to leak the previous default behavior out into the API code. I think it makes more sense to do the default behavior here, which is what was happening before when it wasn't being inserted. |
||
|
||
-- name: UpdateUserProfile :one | ||
UPDATE | ||
|
@@ -286,7 +291,7 @@ SET | |
WHERE | ||
last_seen_at < @last_seen_after :: timestamp | ||
AND status = 'active'::user_status | ||
RETURNING id, email, last_seen_at; | ||
RETURNING id, email, username, last_seen_at; | ||
|
||
-- AllUserIDs returns all UserIDs regardless of user status or deletion. | ||
-- name: AllUserIDs :many | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we pass
""
here? Should we just passactive
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I would omit it but the linter doesn't like leaving it out. It doesn't really matter what this is created as, so
""
just does the default behavior which is dormant.