Skip to content

Commit 7bc1a3d

Browse files
committed
auth: Remove obsolete async_ prefixes from fns
We don't use blocking check implementations anymore, so we remove these temporary prefixes.
1 parent f32cea4 commit 7bc1a3d

File tree

10 files changed

+28
-45
lines changed

10 files changed

+28
-45
lines changed

src/auth.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ impl AuthCheck {
5757
}
5858
}
5959

60-
#[instrument(name = "auth.async_check", skip_all)]
61-
pub async fn async_check(
60+
#[instrument(name = "auth.check", skip_all)]
61+
pub async fn check(
6262
&self,
6363
parts: &Parts,
6464
conn: &mut AsyncPgConnection,
6565
) -> AppResult<Authentication> {
66-
let auth = async_authenticate(parts, conn).await?;
66+
let auth = authenticate(parts, conn).await?;
6767

6868
if let Some(token) = auth.api_token() {
6969
if !self.allow_token {
@@ -172,7 +172,7 @@ impl Authentication {
172172
}
173173

174174
#[instrument(skip_all)]
175-
async fn async_authenticate_via_cookie(
175+
async fn authenticate_via_cookie(
176176
parts: &Parts,
177177
conn: &mut AsyncPgConnection,
178178
) -> AppResult<Option<CookieAuthentication>> {
@@ -198,7 +198,7 @@ async fn async_authenticate_via_cookie(
198198
}
199199

200200
#[instrument(skip_all)]
201-
async fn async_authenticate_via_token(
201+
async fn authenticate_via_token(
202202
parts: &Parts,
203203
conn: &mut AsyncPgConnection,
204204
) -> AppResult<Option<TokenAuthentication>> {
@@ -237,19 +237,16 @@ async fn async_authenticate_via_token(
237237
}
238238

239239
#[instrument(skip_all)]
240-
async fn async_authenticate(
241-
parts: &Parts,
242-
conn: &mut AsyncPgConnection,
243-
) -> AppResult<Authentication> {
240+
async fn authenticate(parts: &Parts, conn: &mut AsyncPgConnection) -> AppResult<Authentication> {
244241
controllers::util::verify_origin(parts)?;
245242

246-
match async_authenticate_via_cookie(parts, conn).await {
243+
match authenticate_via_cookie(parts, conn).await {
247244
Ok(None) => {}
248245
Ok(Some(auth)) => return Ok(Authentication::Cookie(auth)),
249246
Err(err) => return Err(err),
250247
}
251248

252-
match async_authenticate_via_token(parts, conn).await {
249+
match authenticate_via_token(parts, conn).await {
253250
Ok(None) => {}
254251
Ok(Some(auth)) => return Ok(Authentication::Token(auth)),
255252
Err(err) => return Err(err),

src/controllers/crate_owner_invitation.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ use tokio::runtime::Handle;
2828
/// Handles the `GET /api/v1/me/crate_owner_invitations` route.
2929
pub async fn list(app: AppState, req: Parts) -> AppResult<Json<Value>> {
3030
let mut conn = app.db_read().await?;
31-
let auth = AuthCheck::only_cookie()
32-
.async_check(&req, &mut conn)
33-
.await?;
31+
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;
3432
spawn_blocking(move || {
3533
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
3634

@@ -72,9 +70,7 @@ pub async fn list(app: AppState, req: Parts) -> AppResult<Json<Value>> {
7270
/// Handles the `GET /api/private/crate_owner_invitations` route.
7371
pub async fn private_list(app: AppState, req: Parts) -> AppResult<Json<PrivateListResponse>> {
7472
let mut conn = app.db_read().await?;
75-
let auth = AuthCheck::only_cookie()
76-
.async_check(&req, &mut conn)
77-
.await?;
73+
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;
7874
spawn_blocking(move || {
7975
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
8076

@@ -288,7 +284,7 @@ pub async fn handle_invite(state: AppState, req: BytesRequest) -> AppResult<Json
288284
let crate_invite = crate_invite.crate_owner_invite;
289285

290286
let mut conn = state.db_write().await?;
291-
let auth = AuthCheck::default().async_check(&parts, &mut conn).await?;
287+
let auth = AuthCheck::default().check(&parts, &mut conn).await?;
292288
spawn_blocking(move || {
293289
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
294290

src/controllers/krate/follow.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ pub async fn follow(
3535
req: Parts,
3636
) -> AppResult<Response> {
3737
let mut conn = app.db_write().await?;
38-
let user_id = AuthCheck::default()
39-
.async_check(&req, &mut conn)
40-
.await?
41-
.user_id();
38+
let user_id = AuthCheck::default().check(&req, &mut conn).await?.user_id();
4239
spawn_blocking(move || {
4340
use diesel::RunQueryDsl;
4441

@@ -62,10 +59,7 @@ pub async fn unfollow(
6259
req: Parts,
6360
) -> AppResult<Response> {
6461
let mut conn = app.db_write().await?;
65-
let user_id = AuthCheck::default()
66-
.async_check(&req, &mut conn)
67-
.await?
68-
.user_id();
62+
let user_id = AuthCheck::default().check(&req, &mut conn).await?.user_id();
6963
spawn_blocking(move || {
7064
use diesel::RunQueryDsl;
7165

@@ -87,7 +81,7 @@ pub async fn following(
8781
) -> AppResult<Json<Value>> {
8882
let mut conn = app.db_read_prefer_primary().await?;
8983
let user_id = AuthCheck::only_cookie()
90-
.async_check(&req, &mut conn)
84+
.check(&req, &mut conn)
9185
.await?
9286
.user_id();
9387
spawn_blocking(move || {

src/controllers/krate/owners.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async fn modify_owners(
134134
let auth = AuthCheck::default()
135135
.with_endpoint_scope(EndpointScope::ChangeOwners)
136136
.for_crate(&crate_name)
137-
.async_check(&parts, &mut conn)
137+
.check(&parts, &mut conn)
138138
.await?;
139139
spawn_blocking(move || {
140140
use diesel::RunQueryDsl;

src/controllers/krate/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
102102
let auth = AuthCheck::default()
103103
.with_endpoint_scope(endpoint_scope)
104104
.for_crate(&metadata.name)
105-
.async_check(&req, &mut conn)
105+
.check(&req, &mut conn)
106106
.await?;
107107
(existing_crate, auth)
108108
};

src/controllers/krate/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'a> FilterParams<'a> {
310310
}
311311

312312
let user_id = Handle::current()
313-
.block_on(AuthCheck::default().async_check(req, conn))?
313+
.block_on(AuthCheck::default().check(req, conn))?
314314
.user_id();
315315

316316
// This should not fail, because of the `get()` check above

src/controllers/token.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ pub async fn list(
4242
req: Parts,
4343
) -> AppResult<Json<Value>> {
4444
let mut conn = app.db_read_prefer_primary().await?;
45-
let auth = AuthCheck::only_cookie()
46-
.async_check(&req, &mut conn)
47-
.await?;
45+
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;
4846
spawn_blocking(move || {
4947
use diesel::RunQueryDsl;
5048

@@ -95,7 +93,7 @@ pub async fn new(
9593
}
9694

9795
let mut conn = app.db_write().await?;
98-
let auth = AuthCheck::default().async_check(&parts, &mut conn).await?;
96+
let auth = AuthCheck::default().check(&parts, &mut conn).await?;
9997
spawn_blocking(move || {
10098
use diesel::RunQueryDsl;
10199

@@ -178,7 +176,7 @@ pub async fn new(
178176
/// Handles the `GET /me/tokens/:id` route.
179177
pub async fn show(app: AppState, Path(id): Path<i32>, req: Parts) -> AppResult<Json<Value>> {
180178
let mut conn = app.db_write().await?;
181-
let auth = AuthCheck::default().async_check(&req, &mut conn).await?;
179+
let auth = AuthCheck::default().check(&req, &mut conn).await?;
182180
spawn_blocking(move || {
183181
use diesel::RunQueryDsl;
184182

@@ -198,7 +196,7 @@ pub async fn show(app: AppState, Path(id): Path<i32>, req: Parts) -> AppResult<J
198196
/// Handles the `DELETE /me/tokens/:id` route.
199197
pub async fn revoke(app: AppState, Path(id): Path<i32>, req: Parts) -> AppResult<Json<Value>> {
200198
let mut conn = app.db_write().await?;
201-
let auth = AuthCheck::default().async_check(&req, &mut conn).await?;
199+
let auth = AuthCheck::default().check(&req, &mut conn).await?;
202200
spawn_blocking(move || {
203201
use diesel::RunQueryDsl;
204202

@@ -217,7 +215,7 @@ pub async fn revoke(app: AppState, Path(id): Path<i32>, req: Parts) -> AppResult
217215
/// Handles the `DELETE /tokens/current` route.
218216
pub async fn revoke_current(app: AppState, req: Parts) -> AppResult<Response> {
219217
let mut conn = app.db_write().await?;
220-
let auth = AuthCheck::default().async_check(&req, &mut conn).await?;
218+
let auth = AuthCheck::default().check(&req, &mut conn).await?;
221219
spawn_blocking(move || {
222220
use diesel::RunQueryDsl;
223221

src/controllers/user/me.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::views::{EncodableMe, EncodablePrivateUser, EncodableVersion, OwnedCra
2323
pub async fn me(app: AppState, req: Parts) -> AppResult<Json<EncodableMe>> {
2424
let mut conn = app.db_read_prefer_primary().await?;
2525
let user_id = AuthCheck::only_cookie()
26-
.async_check(&req, &mut conn)
26+
.check(&req, &mut conn)
2727
.await?
2828
.user_id();
2929
spawn_blocking(move || {
@@ -70,9 +70,7 @@ pub async fn me(app: AppState, req: Parts) -> AppResult<Json<EncodableMe>> {
7070
/// Handles the `GET /me/updates` route.
7171
pub async fn updates(app: AppState, req: Parts) -> AppResult<Json<Value>> {
7272
let mut conn = app.db_read_prefer_primary().await?;
73-
let auth = AuthCheck::only_cookie()
74-
.async_check(&req, &mut conn)
75-
.await?;
73+
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;
7674
spawn_blocking(move || {
7775
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
7876

@@ -151,7 +149,7 @@ pub async fn update_email_notifications(app: AppState, req: BytesRequest) -> App
151149

152150
let mut conn = app.db_write().await?;
153151
let user_id = AuthCheck::default()
154-
.async_check(&parts, &mut conn)
152+
.check(&parts, &mut conn)
155153
.await?
156154
.user_id();
157155
spawn_blocking(move || {

src/controllers/user/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub async fn update_user(
3434
Json(user_update): Json<UserUpdate>,
3535
) -> AppResult<Response> {
3636
let mut conn = state.db_write().await?;
37-
let auth = AuthCheck::default().async_check(&req, &mut conn).await?;
37+
let auth = AuthCheck::default().check(&req, &mut conn).await?;
3838
spawn_blocking(move || {
3939
use diesel::RunQueryDsl;
4040

@@ -121,7 +121,7 @@ pub async fn regenerate_token_and_send(
121121
req: Parts,
122122
) -> AppResult<Response> {
123123
let mut conn = state.db_write().await?;
124-
let auth = AuthCheck::default().async_check(&req, &mut conn).await?;
124+
let auth = AuthCheck::default().check(&req, &mut conn).await?;
125125
spawn_blocking(move || {
126126
use diesel::RunQueryDsl;
127127

src/controllers/version/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub async fn authenticate(
176176
AuthCheck::default()
177177
.with_endpoint_scope(EndpointScope::Yank)
178178
.for_crate(name)
179-
.async_check(req, conn)
179+
.check(req, conn)
180180
.await
181181
}
182182

0 commit comments

Comments
 (0)