Skip to content

Commit

Permalink
bump: version=0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
CherishCai committed Sep 14, 2024
1 parent 7d3e35a commit 16f00a4
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nacos-sdk-rust-binding-py"
version = "0.4.0"
version = "0.4.2"
edition = "2021"
license = "Apache-2.0"
publish = false
Expand All @@ -23,7 +23,7 @@ pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
# for block api
futures = { version = "0.3", default-features = false, features = [] }

nacos-sdk = { version = "0.4.0", features = ["default"] }
nacos-sdk = { version = "0.4.2", features = ["default", "auth-by-aliyun"] }
#nacos-sdk = { git = "https://github.com/nacos-group/nacos-sdk-rust.git", features = ["default"] }

tracing-subscriber = { version = "0.3", features = ["default"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/async_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import nacos_sdk_rust_binding_py as nacos

client_options = nacos.ClientOptions("0.0.0.0:8848", "love", "simple_app_py", "nacos", "nacos")
client_options = nacos.ClientOptions("127.0.0.1:8848", "love", "simple_app_py", "nacos", "nacos")

# 一般大部分情况下,应用下仅需一个客户端,而且需要长期持有直至应用停止。
# 因为它内部会初始化与服务端的长链接,后续的数据交互及服务变更等订阅,都是实时地通过长链接告知客户端的。
Expand Down
2 changes: 1 addition & 1 deletion examples/async_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import nacos_sdk_rust_binding_py as nacos

client_options = nacos.ClientOptions("0.0.0.0:8848", "love", "simple_app_py", "nacos", "nacos")
client_options = nacos.ClientOptions("127.0.0.1:8848", "love", "simple_app_py", "nacos", "nacos")

# 一般大部分情况下,应用下仅需一个客户端,而且需要长期持有直至应用停止。
# 因为它内部会初始化与服务端的长链接,后续的数据交互及服务变更等订阅,都是实时地通过长链接告知客户端的。
Expand Down
2 changes: 1 addition & 1 deletion examples/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import nacos_sdk_rust_binding_py as nacos

client_options = nacos.ClientOptions("0.0.0.0:8848", "love", "simple_app_py", "nacos", "nacos")
client_options = nacos.ClientOptions("127.0.0.1:8848", "love", "simple_app_py", "nacos", "nacos")

# 一般大部分情况下,应用下仅需一个客户端,而且需要长期持有直至应用停止。
# 因为它内部会初始化与服务端的长链接,后续的数据交互及服务变更等订阅,都是实时地通过长链接告知客户端的。
Expand Down
2 changes: 1 addition & 1 deletion examples/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import nacos_sdk_rust_binding_py as nacos

client_options = nacos.ClientOptions("0.0.0.0:8848", "love", "simple_app_py", "nacos", "nacos")
client_options = nacos.ClientOptions("127.0.0.1:8848", "love", "simple_app_py", "nacos", "nacos")

# 一般大部分情况下,应用下仅需一个客户端,而且需要长期持有直至应用停止。
# 因为它内部会初始化与服务端的长链接,后续的数据交互及服务变更等订阅,都是实时地通过长链接告知客户端的。
Expand Down
3 changes: 3 additions & 0 deletions nacos_sdk_rust_binding_py.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class ClientOptions:
app_name: Optional[str],
username: Optional[str],
password: Optional[str],
access_key: Optional[str],
access_secret: Optional[str],
signature_region_id: Optional[str],
naming_push_empty_protection: Optional[bool],
naming_load_cache_at_start: Optional[bool],
) -> None: ...
Expand Down
17 changes: 14 additions & 3 deletions src/async_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,29 @@ impl AsyncNacosConfigClient {
);

// need enable_auth_plugin_http with username & password
let is_enable_auth = client_options.username.is_some() && client_options.password.is_some();
let is_enable_auth_http =
client_options.username.is_some() && client_options.password.is_some();
// need enable_auth_plugin_aliyun with access_key & access_secret
let is_enable_auth_aliyun =
client_options.access_key.is_some() && client_options.access_secret.is_some();

let props = if is_enable_auth {
let props = if is_enable_auth_http {
props
.auth_username(client_options.username.unwrap())
.auth_password(client_options.password.unwrap())
} else if is_enable_auth_aliyun {
props
.auth_access_key(client_options.access_key.unwrap())
.auth_access_secret(client_options.access_secret.unwrap())
.auth_signature_region_id(client_options.signature_region_id.unwrap())
} else {
props
};

let config_service_builder = if is_enable_auth {
let config_service_builder = if is_enable_auth_http {
nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_http()
} else if is_enable_auth_aliyun {
nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_aliyun()
} else {
nacos_sdk::api::config::ConfigServiceBuilder::new(props)
};
Expand Down
17 changes: 14 additions & 3 deletions src/async_naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,29 @@ impl AsyncNacosNamingClient {
.naming_load_cache_at_start(client_options.naming_load_cache_at_start.unwrap_or(false));

// need enable_auth_plugin_http with username & password
let is_enable_auth = client_options.username.is_some() && client_options.password.is_some();
let is_enable_auth_http =
client_options.username.is_some() && client_options.password.is_some();
// need enable_auth_plugin_aliyun with access_key & access_secret
let is_enable_auth_aliyun =
client_options.access_key.is_some() && client_options.access_secret.is_some();

let props = if is_enable_auth {
let props = if is_enable_auth_http {
props
.auth_username(client_options.username.unwrap())
.auth_password(client_options.password.unwrap())
} else if is_enable_auth_aliyun {
props
.auth_access_key(client_options.access_key.unwrap())
.auth_access_secret(client_options.access_secret.unwrap())
.auth_signature_region_id(client_options.signature_region_id.unwrap())
} else {
props
};

let naming_service_builder = if is_enable_auth {
let naming_service_builder = if is_enable_auth_http {
nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_http()
} else if is_enable_auth_aliyun {
nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_aliyun()
} else {
nacos_sdk::api::naming::NamingServiceBuilder::new(props)
};
Expand Down
17 changes: 14 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,29 @@ impl NacosConfigClient {
);

// need enable_auth_plugin_http with username & password
let is_enable_auth = client_options.username.is_some() && client_options.password.is_some();
let is_enable_auth_http =
client_options.username.is_some() && client_options.password.is_some();
// need enable_auth_plugin_aliyun with access_key & access_secret
let is_enable_auth_aliyun =
client_options.access_key.is_some() && client_options.access_secret.is_some();

let props = if is_enable_auth {
let props = if is_enable_auth_http {
props
.auth_username(client_options.username.unwrap())
.auth_password(client_options.password.unwrap())
} else if is_enable_auth_aliyun {
props
.auth_access_key(client_options.access_key.unwrap())
.auth_access_secret(client_options.access_secret.unwrap())
.auth_signature_region_id(client_options.signature_region_id.unwrap())
} else {
props
};

let config_service_builder = if is_enable_auth {
let config_service_builder = if is_enable_auth_http {
nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_http()
} else if is_enable_auth_aliyun {
nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_aliyun()
} else {
nacos_sdk::api::config::ConfigServiceBuilder::new(props)
};
Expand Down
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,21 @@ pub struct ClientOptions {
/// AppName
#[pyo3(set, get)]
pub app_name: Option<String>,
/// Username for Auth
/// Username for Auth, Login by Http with Token
#[pyo3(set, get)]
pub username: Option<String>,
/// Password for Auth
/// Password for Auth, Login by Http with Token
#[pyo3(set, get)]
pub password: Option<String>,
/// Access_Key for Auth, Login by Aliyun Ram
#[pyo3(set, get)]
pub access_key: Option<String>,
/// Access_Secret for Auth, Login by Aliyun Ram
#[pyo3(set, get)]
pub access_secret: Option<String>,
/// Signature_Region_Id for Auth, Login by Aliyun Ram
#[pyo3(set, get)]
pub signature_region_id: Option<String>,
/// naming push_empty_protection, default true
#[pyo3(set, get)]
pub naming_push_empty_protection: Option<bool>,
Expand All @@ -84,12 +93,16 @@ pub struct ClientOptions {
#[pymethods]
impl ClientOptions {
#[new]
#[allow(clippy::too_many_arguments)]
pub fn new(
server_addr: String,
namespace: String,
app_name: Option<String>,
username: Option<String>,
password: Option<String>,
access_key: Option<String>,
access_secret: Option<String>,
signature_region_id: Option<String>,
naming_push_empty_protection: Option<bool>,
naming_load_cache_at_start: Option<bool>,
) -> PyResult<ClientOptions> {
Expand All @@ -99,6 +112,9 @@ impl ClientOptions {
app_name,
username,
password,
access_key,
access_secret,
signature_region_id,
naming_push_empty_protection,
naming_load_cache_at_start,
})
Expand Down
17 changes: 14 additions & 3 deletions src/naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,29 @@ impl NacosNamingClient {
.naming_load_cache_at_start(client_options.naming_load_cache_at_start.unwrap_or(false));

// need enable_auth_plugin_http with username & password
let is_enable_auth = client_options.username.is_some() && client_options.password.is_some();
let is_enable_auth_http =
client_options.username.is_some() && client_options.password.is_some();
// need enable_auth_plugin_aliyun with access_key & access_secret
let is_enable_auth_aliyun =
client_options.access_key.is_some() && client_options.access_secret.is_some();

let props = if is_enable_auth {
let props = if is_enable_auth_http {
props
.auth_username(client_options.username.unwrap())
.auth_password(client_options.password.unwrap())
} else if is_enable_auth_aliyun {
props
.auth_access_key(client_options.access_key.unwrap())
.auth_access_secret(client_options.access_secret.unwrap())
.auth_signature_region_id(client_options.signature_region_id.unwrap())
} else {
props
};

let naming_service_builder = if is_enable_auth {
let naming_service_builder = if is_enable_auth_http {
nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_http()
} else if is_enable_auth_aliyun {
nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_aliyun()
} else {
nacos_sdk::api::naming::NamingServiceBuilder::new(props)
};
Expand Down

0 comments on commit 16f00a4

Please sign in to comment.