This is an automated email from the ASF dual-hosted git repository.

jiacai2050 pushed a commit to branch feat-auth
in repository 
https://gitbox.apache.org/repos/asf/incubator-horaedb-client-py.git

commit 8ddc2097be5af4e91b85289750539d962c75d1a5
Author: jiacai2050 <[email protected]>
AuthorDate: Thu May 23 17:27:22 2024 +0800

    feat: support basic auth
---
 Cargo.toml         |  1 +
 ceresdb_client.pyi |  5 +++++
 src/client.rs      | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/Cargo.toml b/Cargo.toml
index 3de266f..8275950 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,6 +6,7 @@ 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/src/client.rs b/src/client.rs
index ef8f97f..23c89cb 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -212,6 +212,22 @@ pub enum Mode {
     Proxy,
 }
 
+#[pyclass]
+#[derive(Debug, Clone)]
+pub struct Authorization {
+    username: String,
+    password: String,
+}
+
+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 +254,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]

Reply via email to