Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.

Commit 6e16525

Browse files
authored
feat: support basic auth (#41)
* feat: support basic auth * fix deps * update examples
1 parent 48a1e1a commit 6e16525

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

Cargo.lock

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["HoraeDB Authors"]
55
edition = "2021"
66

77
[dependencies]
8-
horaedb-client = "1.0"
8+
horaedb-client = { git = "https://github.com/apache/incubator-horaedb-client-rs.git", rev = "cc7a2fd07a8dbaad2d405f310f4239b889709afa" }
99
pyo3 = { version = "0.16", features = ["extension-module", "abi3-py37"] }
1010
pyo3-asyncio = { version = "0.16", features = ["attributes", "tokio-runtime"] }
1111
tokio = { version = "1", features = ["sync"] }

ceresdb_client.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,14 @@ class RpcContext:
129129
timeout_ms: int
130130
database: str
131131

132+
class Authorization:
133+
def __init__(self): ...
134+
username: str
135+
password: str
132136

133137
class Builder:
134138
def __init__(self, endpoint: str): ...
135139
def set_rpc_config(self, conf: RpcConfig): ...
136140
def set_default_database(self, db: str): ...
141+
def set_authorization(self, auth: Authorization): ...
137142
def build(self) -> Client: ...

examples/read_write.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncio
44
import datetime
5-
from horaedb_client import Builder, RpcContext, PointBuilder, ValueBuilder, WriteRequest, SqlQueryRequest, Mode, RpcConfig
5+
from horaedb_client import Builder, RpcContext, PointBuilder, ValueBuilder, WriteRequest, SqlQueryRequest, Mode, RpcConfig, Authorization
66

77

88
def create_table(ctx):
@@ -75,6 +75,8 @@ def process_write_resp(resp):
7575
builder = Builder("127.0.0.1:8831", Mode.Direct)
7676
builder.set_rpc_config(rpc_config)
7777
builder.set_default_database("public")
78+
# Required when server enable auth
79+
builder.set_authorization(Authorization("test", "test"))
7880
client = builder.build()
7981

8082
ctx = RpcContext()

src/client.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn register_py_module(m: &PyModule) -> PyResult<()> {
2020
m.add_class::<Builder>()?;
2121
m.add_class::<RpcConfig>()?;
2222
m.add_class::<Mode>()?;
23+
m.add_class::<Authorization>()?;
2324

2425
Ok(())
2526
}
@@ -212,6 +213,30 @@ pub enum Mode {
212213
Proxy,
213214
}
214215

216+
#[pyclass]
217+
#[derive(Debug, Clone)]
218+
pub struct Authorization {
219+
username: String,
220+
password: String,
221+
}
222+
223+
#[pymethods]
224+
impl Authorization {
225+
#[new]
226+
pub fn new(username: String, password: String) -> Self {
227+
Self { username, password }
228+
}
229+
}
230+
231+
impl From<Authorization> for horaedb_client::Authorization {
232+
fn from(auth: Authorization) -> Self {
233+
Self {
234+
username: auth.username,
235+
password: auth.password,
236+
}
237+
}
238+
}
239+
215240
#[pymethods]
216241
impl Builder {
217242
#[new]
@@ -238,6 +263,11 @@ impl Builder {
238263
self.rust_builder = Some(builder);
239264
}
240265

266+
pub fn set_authorization(&mut self, auth: Authorization) {
267+
let builder = self.rust_builder.take().unwrap().authorization(auth.into());
268+
self.rust_builder = Some(builder);
269+
}
270+
241271
pub fn build(&mut self) -> Client {
242272
let client = self.rust_builder.take().unwrap().build();
243273
Client {

0 commit comments

Comments
 (0)