nacos-sdk-rust-binding-node 0.4.0 → 0.5.3-BETA2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "binding",
8
8
  "ffi"
9
9
  ],
10
- "version": "0.4.0",
10
+ "version": "0.5.3-BETA2",
11
11
  "bugs": "https://github.com/opc-source/nacos-sdk-rust-binding-node/issues",
12
12
  "license": "MIT",
13
13
  "repository": {
@@ -55,19 +55,16 @@
55
55
  },
56
56
  "packageManager": "yarn@3.4.1",
57
57
  "optionalDependencies": {
58
- "nacos-sdk-rust-binding-node-win32-x64-msvc": "0.4.0",
59
- "nacos-sdk-rust-binding-node-darwin-x64": "0.4.0",
60
- "nacos-sdk-rust-binding-node-linux-x64-gnu": "0.4.0",
61
- "nacos-sdk-rust-binding-node-darwin-arm64": "0.4.0",
62
- "nacos-sdk-rust-binding-node-android-arm64": "0.4.0",
63
- "nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.4.0",
64
- "nacos-sdk-rust-binding-node-linux-arm64-musl": "0.4.0",
65
- "nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.4.0",
66
- "nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.4.0",
67
- "nacos-sdk-rust-binding-node-linux-x64-musl": "0.4.0",
68
- "nacos-sdk-rust-binding-node-freebsd-x64": "0.4.0",
69
- "nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.4.0",
70
- "nacos-sdk-rust-binding-node-android-arm-eabi": "0.4.0",
71
- "nacos-sdk-rust-binding-node-darwin-universal": "0.4.0"
58
+ "nacos-sdk-rust-binding-node-darwin-arm64": "0.5.3-BETA2",
59
+ "nacos-sdk-rust-binding-node-android-arm64": "0.5.3-BETA2",
60
+ "nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.5.3-BETA2",
61
+ "nacos-sdk-rust-binding-node-linux-arm64-musl": "0.5.3-BETA2",
62
+ "nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.5.3-BETA2",
63
+ "nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.5.3-BETA2",
64
+ "nacos-sdk-rust-binding-node-linux-x64-musl": "0.5.3-BETA2",
65
+ "nacos-sdk-rust-binding-node-freebsd-x64": "0.5.3-BETA2",
66
+ "nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.5.3-BETA2",
67
+ "nacos-sdk-rust-binding-node-android-arm-eabi": "0.5.3-BETA2",
68
+ "nacos-sdk-rust-binding-node-darwin-universal": "0.5.3-BETA2"
72
69
  }
73
70
  }
package/src/config.rs CHANGED
@@ -6,7 +6,7 @@ use std::sync::Arc;
6
6
  /// Client api of Nacos Config.
7
7
  #[napi]
8
8
  pub struct NacosConfigClient {
9
- inner: Arc<dyn nacos_sdk::api::config::ConfigService + Send + Sync + 'static>,
9
+ inner: nacos_sdk::api::config::ConfigService,
10
10
  }
11
11
 
12
12
  #[napi]
@@ -22,9 +22,6 @@ impl NacosConfigClient {
22
22
  )>,
23
23
  >,
24
24
  ) -> Result<NacosConfigClient> {
25
- // print to console or file
26
- let _ = crate::init_logger();
27
-
28
25
  let props = nacos_sdk::api::props::ClientProps::new()
29
26
  .server_addr(client_options.server_addr)
30
27
  .namespace(client_options.namespace)
@@ -35,18 +32,29 @@ impl NacosConfigClient {
35
32
  );
36
33
 
37
34
  // need enable_auth_plugin_http with username & password
38
- let is_enable_auth = client_options.username.is_some() && client_options.password.is_some();
35
+ let is_enable_auth_http =
36
+ client_options.username.is_some() && client_options.password.is_some();
37
+ // need enable_auth_plugin_aliyun with access_key & access_secret
38
+ let is_enable_auth_aliyun =
39
+ client_options.access_key.is_some() && client_options.access_secret.is_some();
39
40
 
40
- let props = if is_enable_auth {
41
+ let props = if is_enable_auth_http {
41
42
  props
42
43
  .auth_username(client_options.username.unwrap())
43
44
  .auth_password(client_options.password.unwrap())
45
+ } else if is_enable_auth_aliyun {
46
+ props
47
+ .auth_access_key(client_options.access_key.unwrap())
48
+ .auth_access_secret(client_options.access_secret.unwrap())
49
+ .auth_signature_region_id(client_options.signature_region_id.unwrap())
44
50
  } else {
45
51
  props
46
52
  };
47
53
 
48
- let config_service_builder = if is_enable_auth {
54
+ let config_service_builder = if is_enable_auth_http {
49
55
  nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_http()
56
+ } else if is_enable_auth_aliyun {
57
+ nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_aliyun()
50
58
  } else {
51
59
  nacos_sdk::api::config::ConfigServiceBuilder::new(props)
52
60
  };
@@ -64,7 +72,7 @@ impl NacosConfigClient {
64
72
  .map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
65
73
 
66
74
  Ok(NacosConfigClient {
67
- inner: Arc::new(config_service),
75
+ inner: config_service,
68
76
  })
69
77
  }
70
78
 
package/src/lib.rs CHANGED
@@ -8,40 +8,6 @@ pub fn sum(a: i32, b: i32) -> i32 {
8
8
  a + b
9
9
  }
10
10
 
11
- lazy_static::lazy_static! {
12
- static ref LOG_GUARD: tracing_appender::non_blocking::WorkerGuard = {
13
- use std::str::FromStr;
14
- use tracing_subscriber::filter::LevelFilter;
15
- let log_level = match std::env::var("NACOS_CLIENT_LOGGER_LEVEL") {
16
- Ok(level) => LevelFilter::from_str(&level).unwrap_or(LevelFilter::INFO),
17
- Err(_) => LevelFilter::INFO,
18
- };
19
-
20
- let home_dir = match std::env::var("HOME") {
21
- Ok(dir) => dir,
22
- Err(_) => "/tmp".to_string(),
23
- };
24
- let file_appender = tracing_appender::rolling::daily(home_dir + "/logs/nacos", "nacos.log");
25
- let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
26
-
27
- tracing_subscriber::fmt()
28
- .with_writer(non_blocking)
29
- // .with_timer(tracing_subscriber::fmt::time::LocalTime::rfc_3339()) // occur `<unknown time>`
30
- .with_thread_names(true)
31
- .with_thread_ids(true)
32
- .with_max_level(log_level)
33
- .init();
34
-
35
- guard
36
- };
37
-
38
- }
39
-
40
- /// log print to console or file
41
- fn init_logger() -> &'static tracing_appender::non_blocking::WorkerGuard {
42
- &LOG_GUARD
43
- }
44
-
45
11
  #[napi(object)]
46
12
  pub struct ClientOptions {
47
13
  /// Server Addr, e.g. address:port[,address:port],...]
@@ -50,10 +16,16 @@ pub struct ClientOptions {
50
16
  pub namespace: String,
51
17
  /// AppName
52
18
  pub app_name: Option<String>,
53
- /// Username for Auth
19
+ /// Username for Auth, Login by Http with Token
54
20
  pub username: Option<String>,
55
- /// Password for Auth
21
+ /// Password for Auth, Login by Http with Token
56
22
  pub password: Option<String>,
23
+ /// Access_Key for Auth, Login by Aliyun Ram
24
+ pub access_key: Option<String>,
25
+ /// Access_Secret for Auth, Login by Aliyun Ram
26
+ pub access_secret: Option<String>,
27
+ /// Signature_Region_Id for Auth, Login by Aliyun Ram
28
+ pub signature_region_id: Option<String>,
57
29
  /// naming push_empty_protection, default true
58
30
  pub naming_push_empty_protection: Option<bool>,
59
31
  /// naming load_cache_at_start, default false
package/src/naming.rs CHANGED
@@ -6,7 +6,7 @@ use std::sync::Arc;
6
6
  /// Client api of Nacos Naming.
7
7
  #[napi]
8
8
  pub struct NacosNamingClient {
9
- inner: Arc<dyn nacos_sdk::api::naming::NamingService + Send + Sync + 'static>,
9
+ inner: nacos_sdk::api::naming::NamingService,
10
10
  }
11
11
 
12
12
  #[napi]
@@ -14,9 +14,6 @@ impl NacosNamingClient {
14
14
  /// Build a Naming Client.
15
15
  #[napi(constructor)]
16
16
  pub fn new(client_options: crate::ClientOptions) -> Result<NacosNamingClient> {
17
- // print to console or file
18
- let _ = crate::init_logger();
19
-
20
17
  let props = nacos_sdk::api::props::ClientProps::new()
21
18
  .server_addr(client_options.server_addr)
22
19
  .namespace(client_options.namespace)
@@ -29,18 +26,29 @@ impl NacosNamingClient {
29
26
  .naming_load_cache_at_start(client_options.naming_load_cache_at_start.unwrap_or(false));
30
27
 
31
28
  // need enable_auth_plugin_http with username & password
32
- let is_enable_auth = client_options.username.is_some() && client_options.password.is_some();
29
+ let is_enable_auth_http =
30
+ client_options.username.is_some() && client_options.password.is_some();
31
+ // need enable_auth_plugin_aliyun with access_key & access_secret
32
+ let is_enable_auth_aliyun =
33
+ client_options.access_key.is_some() && client_options.access_secret.is_some();
33
34
 
34
- let props = if is_enable_auth {
35
+ let props = if is_enable_auth_http {
35
36
  props
36
37
  .auth_username(client_options.username.unwrap())
37
38
  .auth_password(client_options.password.unwrap())
39
+ } else if is_enable_auth_aliyun {
40
+ props
41
+ .auth_access_key(client_options.access_key.unwrap())
42
+ .auth_access_secret(client_options.access_secret.unwrap())
43
+ .auth_signature_region_id(client_options.signature_region_id.unwrap())
38
44
  } else {
39
45
  props
40
46
  };
41
47
 
42
- let naming_service_builder = if is_enable_auth {
48
+ let naming_service_builder = if is_enable_auth_http {
43
49
  nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_http()
50
+ } else if is_enable_auth_aliyun {
51
+ nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_aliyun()
44
52
  } else {
45
53
  nacos_sdk::api::naming::NamingServiceBuilder::new(props)
46
54
  };
@@ -50,7 +58,7 @@ impl NacosNamingClient {
50
58
  .map_err(|nacos_err| Error::from_reason(nacos_err.to_string()))?;
51
59
 
52
60
  Ok(NacosNamingClient {
53
- inner: Arc::new(naming_service),
61
+ inner: naming_service,
54
62
  })
55
63
  }
56
64