fixed key-based access control for Tantivy backends
This commit is contained in:
52
src/rpc.rs
52
src/rpc.rs
@@ -505,10 +505,15 @@ impl RpcServer for RpcServerImpl {
|
||||
if !matches!(server.option.backend, crate::options::BackendType::Tantivy) {
|
||||
return Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, "DB backend is not Tantivy", None::<()>));
|
||||
}
|
||||
crate::search_cmd::ft_create_cmd(&*server, index_name, schema)
|
||||
let proto = crate::search_cmd::ft_create_cmd(&*server, index_name, schema)
|
||||
.await
|
||||
.map_err(|e| jsonrpsee::types::ErrorObjectOwned::owned(-32000, e.0, None::<()>))?;
|
||||
Ok(true)
|
||||
match proto {
|
||||
crate::protocol::Protocol::Error(msg) => {
|
||||
Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, msg, None::<()>))
|
||||
}
|
||||
_ => Ok(true),
|
||||
}
|
||||
}
|
||||
|
||||
async fn ft_add(
|
||||
@@ -526,10 +531,15 @@ impl RpcServer for RpcServerImpl {
|
||||
if !matches!(server.option.backend, crate::options::BackendType::Tantivy) {
|
||||
return Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, "DB backend is not Tantivy", None::<()>));
|
||||
}
|
||||
crate::search_cmd::ft_add_cmd(&*server, index_name, doc_id, score, fields)
|
||||
let proto = crate::search_cmd::ft_add_cmd(&*server, index_name, doc_id, score, fields)
|
||||
.await
|
||||
.map_err(|e| jsonrpsee::types::ErrorObjectOwned::owned(-32000, e.0, None::<()>))?;
|
||||
Ok(true)
|
||||
match proto {
|
||||
crate::protocol::Protocol::Error(msg) => {
|
||||
Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, msg, None::<()>))
|
||||
}
|
||||
_ => Ok(true),
|
||||
}
|
||||
}
|
||||
|
||||
async fn ft_search(
|
||||
@@ -560,7 +570,12 @@ impl RpcServer for RpcServerImpl {
|
||||
)
|
||||
.await
|
||||
.map_err(|e| jsonrpsee::types::ErrorObjectOwned::owned(-32000, e.0, None::<()>))?;
|
||||
Ok(serde_json::json!({ "resp": proto.encode() }))
|
||||
match proto {
|
||||
crate::protocol::Protocol::Error(msg) => {
|
||||
Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, msg, None::<()>))
|
||||
}
|
||||
_ => Ok(serde_json::json!({ "resp": proto.encode() })),
|
||||
}
|
||||
}
|
||||
|
||||
async fn ft_del(&self, db_id: u64, index_name: String, doc_id: String) -> RpcResult<bool> {
|
||||
@@ -571,10 +586,16 @@ impl RpcServer for RpcServerImpl {
|
||||
if !matches!(server.option.backend, crate::options::BackendType::Tantivy) {
|
||||
return Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, "DB backend is not Tantivy", None::<()>));
|
||||
}
|
||||
crate::search_cmd::ft_del_cmd(&*server, index_name, doc_id)
|
||||
let proto = crate::search_cmd::ft_del_cmd(&*server, index_name, doc_id)
|
||||
.await
|
||||
.map_err(|e| jsonrpsee::types::ErrorObjectOwned::owned(-32000, e.0, None::<()>))?;
|
||||
Ok(true)
|
||||
match proto {
|
||||
crate::protocol::Protocol::Error(msg) => {
|
||||
Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, msg, None::<()>))
|
||||
}
|
||||
crate::protocol::Protocol::SimpleString(s) => Ok(s == "1"),
|
||||
_ => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
async fn ft_info(&self, db_id: u64, index_name: String) -> RpcResult<serde_json::Value> {
|
||||
@@ -588,7 +609,12 @@ impl RpcServer for RpcServerImpl {
|
||||
let proto = crate::search_cmd::ft_info_cmd(&*server, index_name)
|
||||
.await
|
||||
.map_err(|e| jsonrpsee::types::ErrorObjectOwned::owned(-32000, e.0, None::<()>))?;
|
||||
Ok(serde_json::json!({ "resp": proto.encode() }))
|
||||
match proto {
|
||||
crate::protocol::Protocol::Error(msg) => {
|
||||
Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, msg, None::<()>))
|
||||
}
|
||||
_ => Ok(serde_json::json!({ "resp": proto.encode() })),
|
||||
}
|
||||
}
|
||||
|
||||
async fn ft_drop(&self, db_id: u64, index_name: String) -> RpcResult<bool> {
|
||||
@@ -599,10 +625,16 @@ impl RpcServer for RpcServerImpl {
|
||||
if !matches!(server.option.backend, crate::options::BackendType::Tantivy) {
|
||||
return Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, "DB backend is not Tantivy", None::<()>));
|
||||
}
|
||||
crate::search_cmd::ft_drop_cmd(&*server, index_name)
|
||||
let proto = crate::search_cmd::ft_drop_cmd(&*server, index_name)
|
||||
.await
|
||||
.map_err(|e| jsonrpsee::types::ErrorObjectOwned::owned(-32000, e.0, None::<()>))?;
|
||||
Ok(true)
|
||||
match proto {
|
||||
crate::protocol::Protocol::Error(msg) => {
|
||||
Err(jsonrpsee::types::ErrorObjectOwned::owned(-32000, msg, None::<()>))
|
||||
}
|
||||
crate::protocol::Protocol::SimpleString(s) => Ok(s.eq_ignore_ascii_case("OK")),
|
||||
_ => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_access_key(&self, db_id: u64, key: String, permissions: String) -> RpcResult<bool> {
|
||||
|
Reference in New Issue
Block a user