swarm-controller: POST /api/notify/dry-run runs a draft flows document
This commit is contained in:
parent
19680a8b78
commit
e8538d8690
1 changed files with 245 additions and 22 deletions
|
|
@ -165,6 +165,20 @@ pub(crate) fn unreadable(why: &DecodeError) -> ProblemDetails {
|
|||
)
|
||||
}
|
||||
|
||||
/// The document a body describes, or the first way it fails
|
||||
/// [`Document::check`].
|
||||
pub(crate) fn checked_document(
|
||||
disabled_builtins: Vec<String>,
|
||||
flows: Vec<Flow>,
|
||||
) -> Result<Document, String> {
|
||||
let doc = Document {
|
||||
version: notify_flows::VERSION,
|
||||
disabled_builtins,
|
||||
flows,
|
||||
};
|
||||
doc.check().map(|()| doc)
|
||||
}
|
||||
|
||||
/// Replace the flows.
|
||||
#[utoipa::path(
|
||||
put,
|
||||
|
|
@ -196,12 +210,7 @@ pub(crate) async fn put_flows(
|
|||
body: Result<Json<PutFlows>, JsonRejection>,
|
||||
) -> Result<Json<FlowsView>, ProblemDetails> {
|
||||
let Json(put) = body.map_err(|e| error_problem(StatusCode::BAD_REQUEST, &e.body_text()))?;
|
||||
let doc = Document {
|
||||
version: notify_flows::VERSION,
|
||||
disabled_builtins: put.disabled_builtins,
|
||||
flows: put.flows,
|
||||
};
|
||||
doc.check()
|
||||
let doc = checked_document(put.disabled_builtins, put.flows)
|
||||
.map_err(|why| error_problem(StatusCode::BAD_REQUEST, &why))?;
|
||||
let client = queue(&state).map_err(refused)?;
|
||||
let store = open(&client).await.map_err(|e| queue_problem(&e))?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue