nacos-sdk-rust-binding-node 0.3.7-alpha → 0.4.2
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/Cargo.toml +3 -3
- package/example/config.js +5 -5
- package/example/config_decrypt.js +4 -4
- package/example/naming.js +2 -2
- package/index.d.ts +9 -3
- package/package.json +15 -15
- package/src/config.rs +14 -3
- package/src/lib.rs +8 -2
- package/src/naming.rs +14 -3
package/Cargo.toml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
edition = "2021"
|
|
3
3
|
name = "nacos-sdk-rust-binding-node"
|
|
4
|
-
version = "0.
|
|
4
|
+
version = "0.4.2"
|
|
5
5
|
authors = ["CheirshCai <785427346@qq.com>"]
|
|
6
6
|
license = "Apache-2.0"
|
|
7
7
|
readme = "README.md"
|
|
@@ -18,8 +18,8 @@ crate-type = ["cdylib"]
|
|
|
18
18
|
napi = { version = "2", default-features = false, features = ["napi4", "async"] }
|
|
19
19
|
napi-derive = "2"
|
|
20
20
|
|
|
21
|
-
nacos-sdk = { version = "0.
|
|
22
|
-
#nacos-sdk = { git = "https://github.com/nacos-group/nacos-sdk-rust.git", branch = "main", features = ["
|
|
21
|
+
nacos-sdk = { version = "0.4.2", features = ["default", "auth-by-aliyun"] }
|
|
22
|
+
#nacos-sdk = { git = "https://github.com/nacos-group/nacos-sdk-rust.git", branch = "main", features = ["default"] }
|
|
23
23
|
|
|
24
24
|
tracing-subscriber = { version = "0.3", features = ["default"] }
|
|
25
25
|
#tracing-subscriber = { version = "0.3", features = ["env-filter", "local-time"] } # occur `<unknown time>`
|
package/example/config.js
CHANGED
|
@@ -6,22 +6,22 @@ const { NacosConfigClient, NacosConfigResponse } = require('../index')
|
|
|
6
6
|
// 请注意!一般情况下,应用下仅需一个 Config 客户端,而且需要长期持有直至应用停止。
|
|
7
7
|
// 因为它内部会初始化与服务端的长链接,后续的数据交互及变更订阅,都是实时地通过长链接告知客户端的。
|
|
8
8
|
const nacos_config_client = new NacosConfigClient({
|
|
9
|
-
serverAddr: '
|
|
10
|
-
namespace: "
|
|
9
|
+
serverAddr: '127.0.0.1:8848',
|
|
10
|
+
namespace: "love",
|
|
11
11
|
appName: "binding-node-example-app"
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
15
|
// If it fails, pay attention to err
|
|
16
|
-
nacos_config_client.getConfig('
|
|
16
|
+
nacos_config_client.getConfig('todo-dataid', 'LOVE').then(data => {
|
|
17
17
|
console.log('getConfig => ' + data);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
nacos_config_client.getConfigResp('
|
|
20
|
+
nacos_config_client.getConfigResp('todo-dataid', 'LOVE').then(data => {
|
|
21
21
|
console.log('getConfigResp => ' + JSON.stringify(data));
|
|
22
22
|
});
|
|
23
23
|
} catch(e) {
|
|
24
24
|
console.log(e);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
nacos_config_client.addListener('
|
|
27
|
+
nacos_config_client.addListener('todo-dataid', 'LOVE', (err, config_resp) => { console.log(config_resp) });
|
|
@@ -8,7 +8,7 @@ const { NacosConfigClient, NacosConfigResponse } = require('../index')
|
|
|
8
8
|
const nacos_config_client = new NacosConfigClient(
|
|
9
9
|
{
|
|
10
10
|
serverAddr: '127.0.0.1:8848',
|
|
11
|
-
namespace: "
|
|
11
|
+
namespace: "love",
|
|
12
12
|
appName: "binding-node-example-app"
|
|
13
13
|
},
|
|
14
14
|
(err, config_req, config_resp) => {
|
|
@@ -29,15 +29,15 @@ const nacos_config_client = new NacosConfigClient(
|
|
|
29
29
|
|
|
30
30
|
try {
|
|
31
31
|
// If it fails, pay attention to err
|
|
32
|
-
nacos_config_client.getConfig('
|
|
32
|
+
nacos_config_client.getConfig('todo-dataid', 'LOVE').then(data => {
|
|
33
33
|
console.log('getConfig => ' + data);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
nacos_config_client.getConfigResp('
|
|
36
|
+
nacos_config_client.getConfigResp('todo-dataid', 'LOVE').then((data) => {
|
|
37
37
|
console.log('getConfigResp => ' + JSON.stringify(data));
|
|
38
38
|
});
|
|
39
39
|
} catch(e) {
|
|
40
40
|
console.log(e);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
nacos_config_client.addListener('
|
|
43
|
+
nacos_config_client.addListener('todo-dataid', 'LOVE', (err, config_resp) => { console.log(config_resp) });
|
package/example/naming.js
CHANGED
|
@@ -6,8 +6,8 @@ const { NacosNamingClient, NacosServiceInstance } = require('../index')
|
|
|
6
6
|
// 请注意!一般情况下,应用下仅需一个 Naming 客户端,而且需要长期持有直至应用停止。
|
|
7
7
|
// 因为它内部会初始化与服务端的长链接,后续的数据交互及变更订阅,都是实时地通过长链接告知客户端的。
|
|
8
8
|
const nacos_naming_client = new NacosNamingClient({
|
|
9
|
-
serverAddr: '
|
|
10
|
-
namespace: "
|
|
9
|
+
serverAddr: '127.0.0.1:8848',
|
|
10
|
+
namespace: "love",
|
|
11
11
|
appName: "binding-node-example-app"
|
|
12
12
|
});
|
|
13
13
|
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
-
export function sum(a: number, b: number): number
|
|
6
|
+
export declare function sum(a: number, b: number): number
|
|
7
7
|
export interface ClientOptions {
|
|
8
8
|
/** Server Addr, e.g. address:port[,address:port],...] */
|
|
9
9
|
serverAddr: string
|
|
@@ -11,10 +11,16 @@ export interface ClientOptions {
|
|
|
11
11
|
namespace: string
|
|
12
12
|
/** AppName */
|
|
13
13
|
appName?: string
|
|
14
|
-
/** Username for Auth */
|
|
14
|
+
/** Username for Auth, Login by Http with Token */
|
|
15
15
|
username?: string
|
|
16
|
-
/** Password for Auth */
|
|
16
|
+
/** Password for Auth, Login by Http with Token */
|
|
17
17
|
password?: string
|
|
18
|
+
/** Access_Key for Auth, Login by Aliyun Ram */
|
|
19
|
+
accessKey?: string
|
|
20
|
+
/** Access_Secret for Auth, Login by Aliyun Ram */
|
|
21
|
+
accessSecret?: string
|
|
22
|
+
/** Signature_Region_Id for Auth, Login by Aliyun Ram */
|
|
23
|
+
signatureRegionId?: string
|
|
18
24
|
/** naming push_empty_protection, default true */
|
|
19
25
|
namingPushEmptyProtection?: boolean
|
|
20
26
|
/** naming load_cache_at_start, default false */
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"binding",
|
|
8
8
|
"ffi"
|
|
9
9
|
],
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.4.2",
|
|
11
11
|
"bugs": "https://github.com/opc-source/nacos-sdk-rust-binding-node/issues",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"repository": {
|
|
@@ -55,19 +55,19 @@
|
|
|
55
55
|
},
|
|
56
56
|
"packageManager": "yarn@3.4.1",
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"nacos-sdk-rust-binding-node-win32-x64-msvc": "0.
|
|
59
|
-
"nacos-sdk-rust-binding-node-darwin-x64": "0.
|
|
60
|
-
"nacos-sdk-rust-binding-node-linux-x64-gnu": "0.
|
|
61
|
-
"nacos-sdk-rust-binding-node-darwin-arm64": "0.
|
|
62
|
-
"nacos-sdk-rust-binding-node-android-arm64": "0.
|
|
63
|
-
"nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.
|
|
64
|
-
"nacos-sdk-rust-binding-node-linux-arm64-musl": "0.
|
|
65
|
-
"nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.
|
|
66
|
-
"nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.
|
|
67
|
-
"nacos-sdk-rust-binding-node-linux-x64-musl": "0.
|
|
68
|
-
"nacos-sdk-rust-binding-node-freebsd-x64": "0.
|
|
69
|
-
"nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.
|
|
70
|
-
"nacos-sdk-rust-binding-node-android-arm-eabi": "0.
|
|
71
|
-
"nacos-sdk-rust-binding-node-darwin-universal": "0.
|
|
58
|
+
"nacos-sdk-rust-binding-node-win32-x64-msvc": "0.4.2",
|
|
59
|
+
"nacos-sdk-rust-binding-node-darwin-x64": "0.4.2",
|
|
60
|
+
"nacos-sdk-rust-binding-node-linux-x64-gnu": "0.4.2",
|
|
61
|
+
"nacos-sdk-rust-binding-node-darwin-arm64": "0.4.2",
|
|
62
|
+
"nacos-sdk-rust-binding-node-android-arm64": "0.4.2",
|
|
63
|
+
"nacos-sdk-rust-binding-node-linux-arm64-gnu": "0.4.2",
|
|
64
|
+
"nacos-sdk-rust-binding-node-linux-arm64-musl": "0.4.2",
|
|
65
|
+
"nacos-sdk-rust-binding-node-win32-arm64-msvc": "0.4.2",
|
|
66
|
+
"nacos-sdk-rust-binding-node-linux-arm-gnueabihf": "0.4.2",
|
|
67
|
+
"nacos-sdk-rust-binding-node-linux-x64-musl": "0.4.2",
|
|
68
|
+
"nacos-sdk-rust-binding-node-freebsd-x64": "0.4.2",
|
|
69
|
+
"nacos-sdk-rust-binding-node-win32-ia32-msvc": "0.4.2",
|
|
70
|
+
"nacos-sdk-rust-binding-node-android-arm-eabi": "0.4.2",
|
|
71
|
+
"nacos-sdk-rust-binding-node-darwin-universal": "0.4.2"
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src/config.rs
CHANGED
|
@@ -35,18 +35,29 @@ impl NacosConfigClient {
|
|
|
35
35
|
);
|
|
36
36
|
|
|
37
37
|
// need enable_auth_plugin_http with username & password
|
|
38
|
-
let
|
|
38
|
+
let is_enable_auth_http =
|
|
39
|
+
client_options.username.is_some() && client_options.password.is_some();
|
|
40
|
+
// need enable_auth_plugin_aliyun with access_key & access_secret
|
|
41
|
+
let is_enable_auth_aliyun =
|
|
42
|
+
client_options.access_key.is_some() && client_options.access_secret.is_some();
|
|
39
43
|
|
|
40
|
-
let props = if
|
|
44
|
+
let props = if is_enable_auth_http {
|
|
41
45
|
props
|
|
42
46
|
.auth_username(client_options.username.unwrap())
|
|
43
47
|
.auth_password(client_options.password.unwrap())
|
|
48
|
+
} else if is_enable_auth_aliyun {
|
|
49
|
+
props
|
|
50
|
+
.auth_access_key(client_options.access_key.unwrap())
|
|
51
|
+
.auth_access_secret(client_options.access_secret.unwrap())
|
|
52
|
+
.auth_signature_region_id(client_options.signature_region_id.unwrap())
|
|
44
53
|
} else {
|
|
45
54
|
props
|
|
46
55
|
};
|
|
47
56
|
|
|
48
|
-
let config_service_builder = if
|
|
57
|
+
let config_service_builder = if is_enable_auth_http {
|
|
49
58
|
nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_http()
|
|
59
|
+
} else if is_enable_auth_aliyun {
|
|
60
|
+
nacos_sdk::api::config::ConfigServiceBuilder::new(props).enable_auth_plugin_aliyun()
|
|
50
61
|
} else {
|
|
51
62
|
nacos_sdk::api::config::ConfigServiceBuilder::new(props)
|
|
52
63
|
};
|
package/src/lib.rs
CHANGED
|
@@ -50,10 +50,16 @@ pub struct ClientOptions {
|
|
|
50
50
|
pub namespace: String,
|
|
51
51
|
/// AppName
|
|
52
52
|
pub app_name: Option<String>,
|
|
53
|
-
/// Username for Auth
|
|
53
|
+
/// Username for Auth, Login by Http with Token
|
|
54
54
|
pub username: Option<String>,
|
|
55
|
-
/// Password for Auth
|
|
55
|
+
/// Password for Auth, Login by Http with Token
|
|
56
56
|
pub password: Option<String>,
|
|
57
|
+
/// Access_Key for Auth, Login by Aliyun Ram
|
|
58
|
+
pub access_key: Option<String>,
|
|
59
|
+
/// Access_Secret for Auth, Login by Aliyun Ram
|
|
60
|
+
pub access_secret: Option<String>,
|
|
61
|
+
/// Signature_Region_Id for Auth, Login by Aliyun Ram
|
|
62
|
+
pub signature_region_id: Option<String>,
|
|
57
63
|
/// naming push_empty_protection, default true
|
|
58
64
|
pub naming_push_empty_protection: Option<bool>,
|
|
59
65
|
/// naming load_cache_at_start, default false
|
package/src/naming.rs
CHANGED
|
@@ -29,18 +29,29 @@ impl NacosNamingClient {
|
|
|
29
29
|
.naming_load_cache_at_start(client_options.naming_load_cache_at_start.unwrap_or(false));
|
|
30
30
|
|
|
31
31
|
// need enable_auth_plugin_http with username & password
|
|
32
|
-
let
|
|
32
|
+
let is_enable_auth_http =
|
|
33
|
+
client_options.username.is_some() && client_options.password.is_some();
|
|
34
|
+
// need enable_auth_plugin_aliyun with access_key & access_secret
|
|
35
|
+
let is_enable_auth_aliyun =
|
|
36
|
+
client_options.access_key.is_some() && client_options.access_secret.is_some();
|
|
33
37
|
|
|
34
|
-
let props = if
|
|
38
|
+
let props = if is_enable_auth_http {
|
|
35
39
|
props
|
|
36
40
|
.auth_username(client_options.username.unwrap())
|
|
37
41
|
.auth_password(client_options.password.unwrap())
|
|
42
|
+
} else if is_enable_auth_aliyun {
|
|
43
|
+
props
|
|
44
|
+
.auth_access_key(client_options.access_key.unwrap())
|
|
45
|
+
.auth_access_secret(client_options.access_secret.unwrap())
|
|
46
|
+
.auth_signature_region_id(client_options.signature_region_id.unwrap())
|
|
38
47
|
} else {
|
|
39
48
|
props
|
|
40
49
|
};
|
|
41
50
|
|
|
42
|
-
let naming_service_builder = if
|
|
51
|
+
let naming_service_builder = if is_enable_auth_http {
|
|
43
52
|
nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_http()
|
|
53
|
+
} else if is_enable_auth_aliyun {
|
|
54
|
+
nacos_sdk::api::naming::NamingServiceBuilder::new(props).enable_auth_plugin_aliyun()
|
|
44
55
|
} else {
|
|
45
56
|
nacos_sdk::api::naming::NamingServiceBuilder::new(props)
|
|
46
57
|
};
|