aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/cache/cacherpc.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-09-23 19:28:26 +0200
committerGitHub Enterprise <[email protected]>2024-09-23 19:28:26 +0200
commitb9d5ea52a837167b08113823f38e53b59b44a7fe (patch)
tree6daa3416de9a7662c287f7267e7c398fccebd27c /src/zenstore/cache/cacherpc.cpp
parentgc unused refactor (#165) (diff)
downloadzen-b9d5ea52a837167b08113823f38e53b59b44a7fe.tar.xz
zen-b9d5ea52a837167b08113823f38e53b59b44a7fe.zip
Added namespace qualifier (optional) for z$ rpc requests (#166)
This change adds support for a namespace-qualified RPC endpoint for z$ at `/z$/<namespace>/$rpc` which may be used to validate RPC requests by URL inspection. The old scheme is still supported.
Diffstat (limited to 'src/zenstore/cache/cacherpc.cpp')
-rw-r--r--src/zenstore/cache/cacherpc.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/zenstore/cache/cacherpc.cpp b/src/zenstore/cache/cacherpc.cpp
index 6cdfeabd0..ec045af2f 100644
--- a/src/zenstore/cache/cacherpc.cpp
+++ b/src/zenstore/cache/cacherpc.cpp
@@ -155,6 +155,7 @@ CacheRpcHandler::AreDiskWritesAllowed() const
CacheRpcHandler::RpcResponseCode
CacheRpcHandler::HandleRpcRequest(const CacheRequestContext& Context,
+ std::string_view UriNamespace,
const ZenContentType ContentType,
IoBuffer&& Body,
uint32_t& OutAcceptMagic,
@@ -191,10 +192,24 @@ CacheRpcHandler::HandleRpcRequest(const CacheRequestContext& Context,
return RpcResponseCode::BadRequest;
}
}
+
+ if (!UriNamespace.empty())
+ {
+ CbObjectView Params = Object["Params"sv].AsObjectView();
+ std::optional<std::string> ParamsNamespace = GetRpcRequestNamespace(Params);
+
+ if (ParamsNamespace)
+ {
+ if (UriNamespace != ParamsNamespace)
+ {
+ return RpcResponseCode::BadRequest;
+ }
+ }
+ }
}
catch (const std::invalid_argument& ex)
{
- ZEN_WARN("Invalid rpc message package recevied, reason: '{}'", ex.what());
+ ZEN_WARN("Invalid rpc message package received, reason: '{}'", ex.what());
return RpcResponseCode::BadRequest;
}
OutAcceptMagic = Object["Accept"sv].AsUInt32();