mirror of
https://github.com/telemt/telemt.git
synced 2026-11-22 07:16:38 +03:00
API: add access policy management and source deny rules
This commit is contained in:
@@ -158,6 +158,37 @@ async fn dispatch(
|
||||
}
|
||||
|
||||
match (method.as_str(), normalized_path) {
|
||||
("GET" | "PATCH", "/v1/access/policy") => {
|
||||
if query.is_some_and(|query| !query.is_empty()) {
|
||||
return Err(ApiFailure::bad_request(
|
||||
"Access policy does not accept query parameters",
|
||||
));
|
||||
}
|
||||
let (data, revision) = if method == Method::GET {
|
||||
access_policy::read(shared).await?
|
||||
} else {
|
||||
if cfg.server.api.read_only {
|
||||
return Err(ApiFailure::new(
|
||||
StatusCode::FORBIDDEN,
|
||||
"read_only",
|
||||
"API runs in read-only mode",
|
||||
));
|
||||
}
|
||||
let expected = parse_if_match(req.headers());
|
||||
let runtime = config_edit::parse_runtime_match(req.headers())?;
|
||||
let body =
|
||||
read_json::<access_policy::PolicyPatch>(req.into_body(), body_limit).await?;
|
||||
access_policy::patch(body, expected, runtime, shared)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
shared
|
||||
.runtime_events
|
||||
.record("api.access.policy.patch.failed", error.code);
|
||||
error
|
||||
})?
|
||||
};
|
||||
Ok(success_response(StatusCode::OK, data, revision))
|
||||
}
|
||||
("POST", "/v1/users") => {
|
||||
fixed_routes::create_user_route(req, shared, cfg, config_rx, request_id, body_limit)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user