v0.25.4
This commit is contained in:
1 parent
e6604e41fc
commit
1dea7f55c8
49 files changed
+4499
-4025
No files matched your search
@@ -342,6 +342,13 @@ struct ConfigHistoryQuery {
|
||||
limit: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct ConfigHistoryRestore {
|
||||
revision: u64,
|
||||
expected_revision: u64,
|
||||
}
|
||||
|
||||
async fn config_history(
|
||||
State(state): State<Arc<App>>,
|
||||
Query(query): Query<ConfigHistoryQuery>,
|
||||
@@ -363,6 +370,42 @@ async fn config_history(
|
||||
.map_err(auth::internal)?;
|
||||
Ok(Json(json!({"revisions": revisions})))
|
||||
}
|
||||
async fn restore_config_history(
|
||||
State(state): State<Arc<App>>,
|
||||
Extension(session): Extension<Session>,
|
||||
Json(input): Json<ConfigHistoryRestore>,
|
||||
) -> Result<Json<crate::config::Envelope>, ApiError> {
|
||||
let current_revision = state.config.load().envelope.revision;
|
||||
if current_revision != input.expected_revision {
|
||||
return Err(ApiError(
|
||||
StatusCode::CONFLICT,
|
||||
"configuration changed; reload before restoring".into(),
|
||||
));
|
||||
}
|
||||
if input.revision >= current_revision {
|
||||
return Err(ApiError(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"only an older configuration revision can be restored".into(),
|
||||
));
|
||||
}
|
||||
let detail = state
|
||||
.store
|
||||
.configuration_revision(input.revision)
|
||||
.await
|
||||
.map_err(auth::internal)?
|
||||
.ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "configuration revision not found".into()))?;
|
||||
state
|
||||
.restore_as(
|
||||
Update {
|
||||
expected_revision: input.expected_revision,
|
||||
config: detail.config,
|
||||
},
|
||||
session.username,
|
||||
input.revision,
|
||||
)
|
||||
.await
|
||||
.map(Json)
|
||||
}
|
||||
async fn update(
|
||||
State(state): State<Arc<App>>,
|
||||
Extension(session): Extension<Session>,
|
||||
|
||||
Reference in new issue
Block a user