Skip to content

Commit

Permalink
Merge branch 'nacos-group:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CherishCai authored Sep 13, 2024
2 parents f824ddf + 90c8d49 commit b731066
Show file tree
Hide file tree
Showing 18 changed files with 961 additions and 227 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# 变更日志 | Change log

### 0.4.2

- 功能: 提供 Aliyun ram AuthPlugin,通过 `features = ["auth-plugin-http"]` 开启

---

- Feature: Support Aliyun ram AuthPlugin (#245), enabled with `features = ["auth-plugin-http"]`

### 0.4.1

- 优化: 在 `auth-plugin-http` 使用 `arc-swap` 替换 unsafe 代码
Expand Down
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

[package]
name = "nacos-sdk"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
authors = ["nacos-group", "CheirshCai <785427346@qq.com>", "onewe <2583021406@qq.com>"]
license = "Apache-2.0"
Expand All @@ -43,10 +43,11 @@ config = []
naming = []
tls = ["reqwest/default-tls"]
auth-by-http = ["reqwest"]
auth-by-aliyun = ["ring", "base64", "chrono"]

[dependencies]
arc-swap = "1.7"
nacos-macro = { version = "0.1.0", path = "nacos-macro" }
nacos-macro = { version = "0.1.1", path = "nacos-macro" }
thiserror = "1.0"
tokio = { version = "1", features = ["full"] }

Expand All @@ -64,6 +65,11 @@ rand = "0.8.5"
# now only for feature="auth-by-http"
reqwest = { version = "0.12", default-features = false, features = [], optional = true }

# only for aliyun-ram-auth
ring = { version = "0.17.8", default-features = false, optional = true }
base64 = { version = "0.22.1", default-features = false, optional = true }
chrono = { version = "0.4", features = ["now"] ,optional = true }

async-trait = "0.1"
async-stream = "0.3.5"
tonic = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion nacos-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nacos-macro"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["nacos-group", "CheirshCai <785427346@qq.com>", "onewe <2583021406@qq.com>"]
license = "Apache-2.0"
Expand Down
37 changes: 36 additions & 1 deletion nacos-macro/src/message/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,40 @@ pub(crate) fn grpc_request(
}
};

let into_request_resource = match macro_args.module {
super::Module::Naming => {
quote! {
fn request_resource(&self) -> Option<crate::api::plugin::RequestResource> {
Some(crate::api::plugin::RequestResource {
request_type: "Naming".to_string(),
namespace: self.namespace.clone(),
group: self.group_name.clone(),
resource: self.service_name.clone()
})
}
}
}
super::Module::Config => {
quote! {
fn request_resource(&self) -> Option<crate::api::plugin::RequestResource> {
Some(crate::api::plugin::RequestResource {
request_type: "Config".to_string(),
namespace: self.namespace.clone(),
group: self.group.clone(),
resource: self.data_id.clone()
})
}
}
}
_ => {
quote! {
fn request_resource(&self) -> Option<crate::api::plugin::RequestResource> {
None
}
}
}
};

// add derive GrpcRequestMessage
let grpc_message_request = quote! {

Expand Down Expand Up @@ -52,8 +86,9 @@ pub(crate) fn grpc_request(
fn module(&self) -> &str {
#module
}
}

#into_request_resource
}
};

// add field
Expand Down
5 changes: 5 additions & 0 deletions src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ impl ConfigServiceBuilder {
self.with_auth_plugin(Arc::new(plugin::HttpLoginAuthPlugin::default()))
}

#[cfg(feature = "auth-by-aliyun")]
pub fn enable_auth_plugin_aliyun(self) -> Self {
self.with_auth_plugin(Arc::new(plugin::AliyunRamAuthPlugin::default()))
}

/// Set [`plugin::AuthPlugin`]
pub fn with_auth_plugin(mut self, auth_plugin: Arc<dyn plugin::AuthPlugin>) -> Self {
self.auth_plugin = Some(auth_plugin);
Expand Down
6 changes: 6 additions & 0 deletions src/api/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ pub const ENV_NACOS_CLIENT_AUTH_USERNAME: &str = "NACOS_CLIENT_USERNAME";

pub const ENV_NACOS_CLIENT_AUTH_PASSWORD: &str = "NACOS_CLIENT_PASSWORD";

pub const ENV_NACOS_CLIENT_AUTH_ACCESS_KEY: &str = "NACOS_CLIENT_ACCESS_KEY";

pub const ENV_NACOS_CLIENT_AUTH_ACCESS_SECRET: &str = "NACOS_CLIENT_SECRET_KEY";

pub const ENV_NACOS_CLIENT_SIGN_REGION_ID: &str = "NACOS_CLIENT_SIGN_REGION_ID";

/// env `NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION`, default true
pub const ENV_NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION: &str =
"NACOS_CLIENT_NAMING_PUSH_EMPTY_PROTECTION";
Expand Down
5 changes: 5 additions & 0 deletions src/api/naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ impl NamingServiceBuilder {
self.with_auth_plugin(Arc::new(plugin::HttpLoginAuthPlugin::default()))
}

#[cfg(feature = "auth-by-aliyun")]
pub fn enable_auth_plugin_aliyun(self) -> Self {
self.with_auth_plugin(Arc::new(plugin::AliyunRamAuthPlugin::default()))
}

/// Set [`plugin::AuthPlugin`]
pub fn with_auth_plugin(mut self, auth_plugin: Arc<dyn plugin::AuthPlugin>) -> Self {
self.auth_plugin = Some(auth_plugin);
Expand Down
Loading

0 comments on commit b731066

Please sign in to comment.