This is an automated email from the ASF dual-hosted git repository.
xikai pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-horaedb-client-py.git
The following commit(s) were added to refs/heads/main by this push:
new 6e16525 feat: support basic auth (#41)
6e16525 is described below
commit 6e165252196851e033d61b9dd7371b4656a835f5
Author: Jiacai Liu <[email protected]>
AuthorDate: Thu May 23 18:15:24 2024 +0800
feat: support basic auth (#41)
* feat: support basic auth
* fix deps
* update examples
---
Cargo.lock | 19 +++++++++++++------
Cargo.toml | 2 +-
ceresdb_client.pyi | 5 +++++
examples/read_write.py | 4 +++-
src/client.rs | 30 ++++++++++++++++++++++++++++++
5 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 6d07b02..5b48935 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -56,9 +56,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.69"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
+checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "arrow"
@@ -373,6 +373,12 @@ version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
+[[package]]
+name = "base64"
+version = "0.22.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -775,12 +781,13 @@ dependencies = [
[[package]]
name = "horaedb-client"
-version = "1.0.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7bb850f1e1fc5d95b31278a842836652f0159e7f00d5e846e78c6076ae46b3b3"
+version = "2.0.0"
+source =
"git+https://github.com/apache/incubator-horaedb-client-rs.git?rev=cc7a2fd07a8dbaad2d405f310f4239b889709afa#cc7a2fd07a8dbaad2d405f310f4239b889709afa"
dependencies = [
+ "anyhow",
"arrow",
"async-trait",
+ "base64 0.22.1",
"dashmap",
"futures",
"horaedbproto",
@@ -1910,7 +1917,7 @@ dependencies = [
"async-stream",
"async-trait",
"axum",
- "base64",
+ "base64 0.13.1",
"bytes",
"futures-core",
"futures-util",
diff --git a/Cargo.toml b/Cargo.toml
index 3de266f..39f97c6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["HoraeDB Authors"]
edition = "2021"
[dependencies]
-horaedb-client = "1.0"
+horaedb-client = { git =
"https://github.com/apache/incubator-horaedb-client-rs.git", rev =
"cc7a2fd07a8dbaad2d405f310f4239b889709afa" }
pyo3 = { version = "0.16", features = ["extension-module",
"abi3-py37"] }
pyo3-asyncio = { version = "0.16", features = ["attributes",
"tokio-runtime"] }
tokio = { version = "1", features = ["sync"] }
diff --git a/ceresdb_client.pyi b/ceresdb_client.pyi
index 8e057cd..20550e6 100644
--- a/ceresdb_client.pyi
+++ b/ceresdb_client.pyi
@@ -129,9 +129,14 @@ class RpcContext:
timeout_ms: int
database: str
+class Authorization:
+ def __init__(self): ...
+ username: str
+ password: str
class Builder:
def __init__(self, endpoint: str): ...
def set_rpc_config(self, conf: RpcConfig): ...
def set_default_database(self, db: str): ...
+ def set_authorization(self, auth: Authorization): ...
def build(self) -> Client: ...
diff --git a/examples/read_write.py b/examples/read_write.py
index 4d5ac48..64c3e9d 100644
--- a/examples/read_write.py
+++ b/examples/read_write.py
@@ -2,7 +2,7 @@
import asyncio
import datetime
-from horaedb_client import Builder, RpcContext, PointBuilder, ValueBuilder,
WriteRequest, SqlQueryRequest, Mode, RpcConfig
+from horaedb_client import Builder, RpcContext, PointBuilder, ValueBuilder,
WriteRequest, SqlQueryRequest, Mode, RpcConfig, Authorization
def create_table(ctx):
@@ -75,6 +75,8 @@ if __name__ == "__main__":
builder = Builder("127.0.0.1:8831", Mode.Direct)
builder.set_rpc_config(rpc_config)
builder.set_default_database("public")
+ # Required when server enable auth
+ builder.set_authorization(Authorization("test", "test"))
client = builder.build()
ctx = RpcContext()
diff --git a/src/client.rs b/src/client.rs
index ef8f97f..2c53fdd 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -20,6 +20,7 @@ pub fn register_py_module(m: &PyModule) -> PyResult<()> {
m.add_class::<Builder>()?;
m.add_class::<RpcConfig>()?;
m.add_class::<Mode>()?;
+ m.add_class::<Authorization>()?;
Ok(())
}
@@ -212,6 +213,30 @@ pub enum Mode {
Proxy,
}
+#[pyclass]
+#[derive(Debug, Clone)]
+pub struct Authorization {
+ username: String,
+ password: String,
+}
+
+#[pymethods]
+impl Authorization {
+ #[new]
+ pub fn new(username: String, password: String) -> Self {
+ Self { username, password }
+ }
+}
+
+impl From<Authorization> for horaedb_client::Authorization {
+ fn from(auth: Authorization) -> Self {
+ Self {
+ username: auth.username,
+ password: auth.password,
+ }
+ }
+}
+
#[pymethods]
impl Builder {
#[new]
@@ -238,6 +263,11 @@ impl Builder {
self.rust_builder = Some(builder);
}
+ pub fn set_authorization(&mut self, auth: Authorization) {
+ let builder =
self.rust_builder.take().unwrap().authorization(auth.into());
+ self.rust_builder = Some(builder);
+ }
+
pub fn build(&mut self) -> Client {
let client = self.rust_builder.take().unwrap().build();
Client {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]