Skip to content

Commit e26f70e

Browse files
committed
chore(core): expand datacenters schema
1 parent c4c7a64 commit e26f70e

File tree

3 files changed

+66
-40
lines changed

3 files changed

+66
-40
lines changed

out/openapi.json

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

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ use crate::ctx::ApiCtx;
2222
#[serde(deny_unknown_fields)]
2323
#[schema(as = RunnerConfigsListResponse)]
2424
pub struct ListResponse {
25-
pub runner_configs: HashMap<String, HashMap<String, rivet_types::runner_configs::RunnerConfig>>,
25+
pub runner_configs: HashMap<String, RunnerConfigDatacenters>,
2626
pub pagination: Pagination,
2727
}
2828

29+
#[derive(Deserialize, Serialize, ToSchema)]
30+
#[schema(as = RunnerConfigsListResponseRunnerConfigsValue)]
31+
pub struct RunnerConfigDatacenters {
32+
pub datacenters: HashMap<String, rivet_types::runner_configs::RunnerConfig>,
33+
}
34+
2935
#[utoipa::path(
3036
get,
3137
operation_id = "runner_configs_list",
@@ -64,7 +70,7 @@ async fn list_inner(
6470
_,
6571
_,
6672
_,
67-
HashMap<String, HashMap<String, rivet_types::runner_configs::RunnerConfig>>,
73+
HashMap<String, RunnerConfigDatacenters>,
6874
>(
6975
ctx.clone().into(),
7076
headers,
@@ -76,9 +82,13 @@ async fn list_inner(
7682
},
7783
|dc_label, res, agg| {
7884
for (runner_name, runner_config) in res.runner_configs {
79-
let entry = agg.entry(runner_name).or_insert_with(HashMap::new);
85+
let entry = agg
86+
.entry(runner_name)
87+
.or_insert_with(|| RunnerConfigDatacenters {
88+
datacenters: HashMap::new(),
89+
});
8090

81-
entry.insert(
91+
entry.datacenters.insert(
8292
ctx.config()
8393
.dc_for_label(dc_label)
8494
.expect("dc should exist")
@@ -100,9 +110,9 @@ async fn list_inner(
100110
#[derive(Deserialize, Serialize, ToSchema)]
101111
#[serde(deny_unknown_fields)]
102112
#[schema(as = RunnerConfigsUpsertRequestBody)]
103-
pub struct UpsertRequest(
104-
#[schema(inline)] HashMap<String, rivet_api_types::namespaces::runner_configs::RunnerConfig>,
105-
);
113+
pub struct UpsertRequest {
114+
pub datacenters: HashMap<String, rivet_api_types::namespaces::runner_configs::RunnerConfig>,
115+
}
106116

107117
#[utoipa::path(
108118
put,
@@ -141,7 +151,7 @@ async fn upsert_inner(
141151
ctx.auth().await?;
142152

143153
for dc in &ctx.config().topology().datacenters {
144-
if let Some(runner_config) = body.0.remove(&dc.name) {
154+
if let Some(runner_config) = body.datacenters.remove(&dc.name) {
145155
if ctx.config().dc_label() == dc.datacenter_label {
146156
rivet_api_peer::runner_configs::upsert(
147157
ctx.clone().into(),

scripts/api/runner-configs/upsert.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ const response = await fetch(
133133
"Content-Type": "application/json",
134134
},
135135
body: JSON.stringify({
136-
[datacenter]: dcRunnerConfig,
136+
datacenters: {
137+
[datacenter]: dcRunnerConfig,
138+
},
137139
}),
138140
},
139141
);

0 commit comments

Comments
 (0)