Skip to content

Commit 10dfef9

Browse files
authored
OpenAPI: Describe authentication requirements (#10264)
1 parent 693ba1e commit 10dfef9

File tree

17 files changed

+282
-3
lines changed

17 files changed

+282
-3
lines changed

crates/crates_io_session/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use parking_lot::RwLock;
99
use std::collections::HashMap;
1010
use std::sync::Arc;
1111

12-
static COOKIE_NAME: &str = "cargo_session";
12+
pub static COOKIE_NAME: &str = "cargo_session";
1313
static MAX_AGE_DAYS: i64 = 90;
1414

1515
#[derive(Clone, FromRequestParts)]

src/controllers/crate_owner_invitation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::collections::{HashMap, HashSet};
2727
#[utoipa::path(
2828
get,
2929
path = "/api/v1/me/crate_owner_invitations",
30+
security(("cookie" = [])),
3031
tag = "owners",
3132
responses((status = 200, description = "Successful Response")),
3233
)]
@@ -90,6 +91,7 @@ pub struct ListQueryParams {
9091
get,
9192
path = "/api/private/crate_owner_invitations",
9293
params(ListQueryParams, PaginationQueryParams),
94+
security(("cookie" = [])),
9395
tag = "owners",
9496
responses((status = 200, description = "Successful Response")),
9597
)]
@@ -316,6 +318,10 @@ pub struct OwnerInvitation {
316318
params(
317319
("crate_id" = i32, Path, description = "ID of the crate"),
318320
),
321+
security(
322+
("api_token" = []),
323+
("cookie" = []),
324+
),
319325
tag = "owners",
320326
responses((status = 200, description = "Successful Response")),
321327
)]

src/controllers/krate/delete.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const AVAILABLE_AFTER: TimeDelta = TimeDelta::hours(24);
3131
delete,
3232
path = "/api/v1/crates/{name}",
3333
params(CratePath),
34+
security(("cookie" = [])),
3435
tag = "crates",
3536
responses((status = 200, description = "Successful Response")),
3637
)]

src/controllers/krate/follow.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ async fn follow_target(
3434
put,
3535
path = "/api/v1/crates/{name}/follow",
3636
params(CratePath),
37+
security(
38+
("api_token" = []),
39+
("cookie" = []),
40+
),
3741
tag = "crates",
3842
responses((status = 200, description = "Successful Response")),
3943
)]
@@ -55,6 +59,10 @@ pub async fn follow_crate(app: AppState, path: CratePath, req: Parts) -> AppResu
5559
delete,
5660
path = "/api/v1/crates/{name}/follow",
5761
params(CratePath),
62+
security(
63+
("api_token" = []),
64+
("cookie" = []),
65+
),
5866
tag = "crates",
5967
responses((status = 200, description = "Successful Response")),
6068
)]
@@ -72,6 +80,7 @@ pub async fn unfollow_crate(app: AppState, path: CratePath, req: Parts) -> AppRe
7280
get,
7381
path = "/api/v1/crates/{name}/following",
7482
params(CratePath),
83+
security(("cookie" = [])),
7584
tag = "crates",
7685
responses((status = 200, description = "Successful Response")),
7786
)]

src/controllers/krate/owners.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ pub async fn get_user_owners(state: AppState, path: CratePath) -> AppResult<Eras
8888
put,
8989
path = "/api/v1/crates/{name}/owners",
9090
params(CratePath),
91+
security(
92+
("api_token" = []),
93+
("cookie" = []),
94+
),
9195
tag = "owners",
9296
responses((status = 200, description = "Successful Response")),
9397
)]
@@ -105,6 +109,10 @@ pub async fn add_owners(
105109
delete,
106110
path = "/api/v1/crates/{name}/owners",
107111
params(CratePath),
112+
security(
113+
("api_token" = []),
114+
("cookie" = []),
115+
),
108116
tag = "owners",
109117
responses((status = 200, description = "Successful Response")),
110118
)]

src/controllers/krate/publish.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const MAX_DESCRIPTION_LENGTH: usize = 1000;
5656
#[utoipa::path(
5757
put,
5858
path = "/api/v1/crates/new",
59+
security(
60+
("api_token" = []),
61+
("cookie" = []),
62+
),
5963
tag = "publish",
6064
responses((status = 200, description = "Successful Response")),
6165
)]

src/controllers/krate/search.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ use crate::util::RequestUtils;
3838
get,
3939
path = "/api/v1/crates",
4040
params(ListQueryParams, PaginationQueryParams),
41+
security(
42+
(),
43+
("api_token" = []),
44+
("cookie" = []),
45+
),
4146
tag = "crates",
4247
responses((status = 200, description = "Successful Response")),
4348
)]

src/controllers/session.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ async fn find_user_by_gh_id(conn: &mut AsyncPgConnection, gh_id: i32) -> QueryRe
173173
#[utoipa::path(
174174
delete,
175175
path = "/api/private/session",
176+
security(("cookie" = [])),
176177
tag = "session",
177178
responses((status = 200, description = "Successful Response")),
178179
)]

src/controllers/token.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl GetParams {
3939
#[utoipa::path(
4040
get,
4141
path = "/api/v1/me/tokens",
42+
security(("cookie" = [])),
4243
tag = "api_tokens",
4344
responses((status = 200, description = "Successful Response")),
4445
)]
@@ -86,6 +87,7 @@ pub struct NewApiTokenRequest {
8687
#[utoipa::path(
8788
put,
8889
path = "/api/v1/me/tokens",
90+
security(("cookie" = [])),
8991
tag = "api_tokens",
9092
responses((status = 200, description = "Successful Response")),
9193
)]
@@ -184,6 +186,10 @@ pub async fn create_api_token(
184186
params(
185187
("id" = i32, Path, description = "ID of the API token"),
186188
),
189+
security(
190+
("api_token" = []),
191+
("cookie" = []),
192+
),
187193
tag = "api_tokens",
188194
responses((status = 200, description = "Successful Response")),
189195
)]
@@ -211,6 +217,10 @@ pub async fn find_api_token(
211217
params(
212218
("id" = i32, Path, description = "ID of the API token"),
213219
),
220+
security(
221+
("api_token" = []),
222+
("cookie" = []),
223+
),
214224
tag = "api_tokens",
215225
responses((status = 200, description = "Successful Response")),
216226
)]
@@ -237,6 +247,7 @@ pub async fn revoke_api_token(
237247
#[utoipa::path(
238248
delete,
239249
path = "/api/v1/tokens/current",
250+
security(("api_token" = [])),
240251
tag = "api_tokens",
241252
responses((status = 200, description = "Successful Response")),
242253
)]

src/controllers/user/email_notifications.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub struct CrateEmailNotifications {
2424
#[utoipa::path(
2525
put,
2626
path = "/api/v1/me/email_notifications",
27+
security(
28+
("api_token" = []),
29+
("cookie" = []),
30+
),
2731
tag = "users",
2832
responses((status = 200, description = "Successful Response")),
2933
)]

0 commit comments

Comments
 (0)