Skip to content

Commit

Permalink
fix: 修复grpc协议的配置请求中的默认命名空间id为public与空字符串等价的兼容问题 #184
Browse files Browse the repository at this point in the history
  • Loading branch information
heqingpan committed Dec 8, 2024
1 parent 5a59930 commit 700c7f4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::common::constant::EMPTY_ARC_STRING;
use std::sync::Arc;

pub mod config_db;
pub mod config_index;
pub mod config_sled;
Expand All @@ -21,6 +24,15 @@ impl ConfigUtils {
val
}
}

pub fn default_tenant_arc(val: Arc<String>) -> Arc<String> {
if val.as_str() == DEFAULT_TENANT {
EMPTY_ARC_STRING.clone()
} else {
val
}
}

pub fn is_default_tenant(val: &str) -> bool {
val == DEFAULT_TENANT
}
Expand Down
7 changes: 6 additions & 1 deletion src/grpc/handler/config_change_batch_listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::sync::Arc;

use crate::config::ConfigUtils;
use crate::grpc::HandlerResult;
use crate::{
common::appdata::AppShareData,
Expand Down Expand Up @@ -40,7 +41,11 @@ impl PayloadHandler for ConfigChangeBatchListenRequestHandler {
let request: ConfigBatchListenRequest = serde_json::from_slice(&body_vec)?;
let mut listener_items = vec![];
for item in request.config_listen_contexts {
let key = ConfigKey::new(&item.data_id, &item.group, &item.tenant);
let key = ConfigKey::new(
&item.data_id,
&item.group,
&ConfigUtils::default_tenant(item.tenant),
);
listener_items.push(ListenerItem::new(key, item.md5));
}
let cmd = if request.listen {
Expand Down
7 changes: 6 additions & 1 deletion src/grpc/handler/config_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;

use crate::common::string_utils::StringUtils;
use crate::config::config_type::ConfigType;
use crate::config::ConfigUtils;
use crate::grpc::HandlerResult;
use crate::{
common::appdata::AppShareData,
Expand Down Expand Up @@ -42,7 +43,11 @@ impl PayloadHandler for ConfigPublishRequestHandler {
let desc =
StringUtils::map_not_empty(request.get_addition_param("desc").cloned()).map(Arc::new);
let mut req = SetConfigReq::new(
ConfigKey::new(&request.data_id, &request.group, &request.tenant),
ConfigKey::new(
&request.data_id,
&request.group,
&ConfigUtils::default_tenant(request.tenant),
),
request.content,
);
req.config_type = config_type;
Expand Down
3 changes: 2 additions & 1 deletion src/grpc/handler/config_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::sync::Arc;

use crate::config::config_type::ConfigType;
use crate::config::ConfigUtils;
use crate::grpc::api_model::NOT_FOUND;
use crate::grpc::HandlerResult;
use crate::{
Expand Down Expand Up @@ -42,7 +43,7 @@ impl PayloadHandler for ConfigQueryRequestHandler {
let cmd = ConfigCmd::GET(ConfigKey::new(
&request.data_id,
&request.group,
&request.tenant,
&ConfigUtils::default_tenant(request.tenant),
));
let mut response = ConfigQueryResponse {
request_id: request.request_id,
Expand Down
3 changes: 2 additions & 1 deletion src/grpc/handler/config_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::sync::Arc;

use crate::config::ConfigUtils;
use crate::grpc::HandlerResult;
use crate::{
common::appdata::AppShareData,
Expand Down Expand Up @@ -38,7 +39,7 @@ impl PayloadHandler for ConfigRemoveRequestHandler {
let req = DelConfigReq::new(ConfigKey::new(
&request.data_id,
&request.group,
&request.tenant,
&ConfigUtils::default_tenant(request.tenant),
));
match self.app_data.config_route.del_config(req).await {
Ok(_res) => {
Expand Down

0 comments on commit 700c7f4

Please sign in to comment.