Skip to content

Commit 595625c

Browse files
MasterPtatoNathanFlurry
authored andcommitted
fix(api): fix openapi security
1 parent 512f8d5 commit 595625c

File tree

8 files changed

+128
-35
lines changed

8 files changed

+128
-35
lines changed

out/openapi.json

Lines changed: 72 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/api-public/src/actors/delete.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct DeleteResponse {}
4545
responses(
4646
(status = 200, body = DeleteResponse),
4747
),
48+
security(("bearer_auth" = [])),
4849
)]
4950
pub async fn delete(
5051
Extension(ctx): Extension<ApiCtx>,

packages/core/api-public/src/actors/list_names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::ctx::ApiCtx;
2424
responses(
2525
(status = 200, body = ListNamesResponse),
2626
),
27+
security(("bearer_auth" = [])),
2728
)]
2829
pub async fn list_names(
2930
Extension(ctx): Extension<ApiCtx>,

packages/core/api-public/src/datacenters.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::ctx::ApiCtx;
1616
responses(
1717
(status = 200, body = ListResponse),
1818
),
19+
security(("bearer_auth" = [])),
1920
)]
2021
pub async fn list(Extension(ctx): Extension<ApiCtx>) -> Response {
2122
match list_inner(ctx).await {

packages/core/api-public/src/namespaces.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::ctx::ApiCtx;
1919
responses(
2020
(status = 200, body = ListResponse),
2121
),
22+
security(("bearer_auth" = [])),
2223
)]
2324
pub async fn list(
2425
Extension(ctx): Extension<ApiCtx>,
@@ -59,6 +60,7 @@ async fn list_inner(ctx: ApiCtx, headers: HeaderMap, query: ListQuery) -> Result
5960
responses(
6061
(status = 200, body = CreateResponse),
6162
),
63+
security(("bearer_auth" = [])),
6264
)]
6365
pub async fn create(
6466
Extension(ctx): Extension<ApiCtx>,

packages/core/api-public/src/router.rs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,28 @@ use utoipa::OpenApi;
1010
use crate::{actors, ctx, datacenters, namespaces, runner_configs, runners, ui};
1111

1212
#[derive(OpenApi)]
13-
#[openapi(paths(
14-
actors::list::list,
15-
actors::create::create,
16-
actors::delete::delete,
17-
actors::list_names::list_names,
18-
actors::get_or_create::get_or_create,
19-
runners::list,
20-
runners::list_names,
21-
namespaces::list,
22-
namespaces::create,
23-
runner_configs::list,
24-
runner_configs::upsert,
25-
runner_configs::delete,
26-
datacenters::list,
27-
))]
28-
#[openapi(components(schemas(namespace::keys::RunnerConfigVariant)))]
13+
#[openapi(
14+
paths(
15+
actors::list::list,
16+
actors::create::create,
17+
actors::delete::delete,
18+
actors::list_names::list_names,
19+
actors::get_or_create::get_or_create,
20+
runners::list,
21+
runners::list_names,
22+
namespaces::list,
23+
namespaces::create,
24+
runner_configs::list,
25+
runner_configs::upsert,
26+
runner_configs::delete,
27+
datacenters::list,
28+
),
29+
components(
30+
schemas(namespace::keys::RunnerConfigVariant)
31+
),
32+
security( ("bearer_auth" = []) ),
33+
modifiers(&SecurityAddon),
34+
)]
2935
pub struct ApiDoc;
3036

3137
pub async fn router(
@@ -118,3 +124,19 @@ async fn auth_middleware(
118124

119125
Ok(res)
120126
}
127+
128+
struct SecurityAddon;
129+
130+
impl utoipa::Modify for SecurityAddon {
131+
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
132+
openapi.components.as_mut().unwrap().add_security_scheme(
133+
"bearer_auth",
134+
utoipa::openapi::security::SecurityScheme::Http(
135+
utoipa::openapi::security::HttpBuilder::new()
136+
.scheme(utoipa::openapi::security::HttpAuthScheme::Bearer)
137+
// .bearer_format("Rivet")
138+
.build(),
139+
),
140+
);
141+
}
142+
}

packages/core/api-public/src/runner_configs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::ctx::ApiCtx;
2121
responses(
2222
(status = 200, body = ListResponse),
2323
),
24+
security(("bearer_auth" = [])),
2425
)]
2526
pub async fn list(
2627
Extension(ctx): Extension<ApiCtx>,
@@ -71,6 +72,7 @@ async fn list_inner(
7172
responses(
7273
(status = 200, body = UpsertResponse),
7374
),
75+
security(("bearer_auth" = [])),
7476
)]
7577
pub async fn upsert(
7678
Extension(ctx): Extension<ApiCtx>,
@@ -122,6 +124,7 @@ async fn upsert_inner(
122124
responses(
123125
(status = 200, body = DeleteResponse),
124126
),
127+
security(("bearer_auth" = [])),
125128
)]
126129
pub async fn delete(
127130
Extension(ctx): Extension<ApiCtx>,

packages/core/api-public/src/runners.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::ctx::ApiCtx;
2020
responses(
2121
(status = 200, body = ListResponse),
2222
),
23+
security(("bearer_auth" = [])),
2324
)]
2425
pub async fn list(
2526
Extension(ctx): Extension<ApiCtx>,
@@ -85,14 +86,15 @@ pub struct ListNamesResponse {
8586
/// - GET /runners/names (fanout)
8687
/// - [api-peer] namespace::ops::resolve_for_name_global
8788
#[utoipa::path(
88-
get,
89-
operation_id = "runners_list_names",
90-
path = "/runners/names",
91-
params(ListNamesQuery),
92-
responses(
93-
(status = 200, body = ListNamesResponse),
94-
),
95-
)]
89+
get,
90+
operation_id = "runners_list_names",
91+
path = "/runners/names",
92+
params(ListNamesQuery),
93+
responses(
94+
(status = 200, body = ListNamesResponse),
95+
),
96+
security(("bearer_auth" = [])),
97+
)]
9698
pub async fn list_names(
9799
Extension(ctx): Extension<ApiCtx>,
98100
headers: HeaderMap,

0 commit comments

Comments
 (0)