aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/server/http_svc/routes/rule/create.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/configuration/src/server/http_svc/routes/rule/create.rs')
-rw-r--r--crates/configuration/src/server/http_svc/routes/rule/create.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/crates/configuration/src/server/http_svc/routes/rule/create.rs b/crates/configuration/src/server/http_svc/routes/rule/create.rs
new file mode 100644
index 0000000..809c00b
--- /dev/null
+++ b/crates/configuration/src/server/http_svc/routes/rule/create.rs
@@ -0,0 +1,38 @@
+use axum::{extract::State, response::IntoResponse};
+use warden_core::configuration::rule::{
+ RuleConfiguration, mutate_rule_configuration_server::MutateRuleConfiguration,
+};
+
+use crate::{
+ server::{error::AppError, http_svc::TAG_RULES, version::Version},
+ state::AppHandle,
+};
+
+/// Create rule configuration
+#[utoipa::path(
+ post,
+ path = "/{version}/rule",
+ params(
+ ("version" = Version, Path, description = "API version, e.g., v1, v2, v3"),
+ ),
+ responses((
+ status = CREATED,
+ body = RuleConfiguration,
+ )),
+ operation_id = "create_rule_configuration", // https://github.com/juhaku/utoipa/issues/1170
+ tag = TAG_RULES,
+ )
+]
+#[axum::debug_handler]
+#[tracing::instrument(skip(state))]
+pub async fn create_rule(
+ version: Version,
+ State(state): State<AppHandle>,
+ axum::Json(body): axum::Json<RuleConfiguration>,
+) -> Result<impl IntoResponse, AppError> {
+ let response = state
+ .create_rule_configuration(tonic::Request::new(body))
+ .await?
+ .into_inner();
+ Ok((axum::http::StatusCode::CREATED, axum::Json(response)))
+}