Skip to content

Commit

Permalink
feat: Support Aliyun ram AuthPlugin (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiner committed Sep 12, 2024
1 parent c446e86 commit f8922e1
Show file tree
Hide file tree
Showing 16 changed files with 954 additions and 224 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ config = []
naming = []
tls = ["reqwest/default-tls"]
auth-by-http = ["reqwest"]
auth-by-aliyun = ["ring", "base64", "chrono"]

[dependencies]
arc-swap = "1.7"
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
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 f8922e1

Please sign in to comment.