You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #2644 - jsha:log-auth-type, r=pietroalbini
Log user id and token id when applicable.
In rust-lang/rfcs#2947 (comment),
@pietroalbini says, with regards to restricting the default
authorization of API tokens:
> this would break everyone using the token to authenticate to endpoints
> not used by Cargo. Even though we're not providing stability guarantees
> for them I'd be wary of blindly breaking them. At least I'd like some
> stats on which endpoints are accessed with the cookie and which are used
> with tokens.
This change attempts to provide those stats via the logs. All
authenticated requests receive a `uid` field in the log output. If the
request was authenticated via an API token, the log output additionally
contains a `tokenid` field.
Because the method I used, log_request::add_custom_metadata, requires a
mutable request, I had to make req.authenticate() take a mutable ref.
Since that conflicted with many call sites that were already holding an
immutable ref to the request's DB connection, I moved the taking of the
DB connection reference after the authenticate call.
In crate_owner_invitations.rs and follow.rs, this also meant removing
duplicate authenticate calls and passing through the
already-authenticated user ID from a calling function instead.
In a few places, `req.authenticate(&conn)?.find_user(&conn)?` has been
replaced with two lines, one to do the authentication, and one to do the
database lookup for the user object, after `let conn = req.db_conn()?`
0 commit comments