Skip to content

Commit

Permalink
允许独立配置IntranetAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinhgchen committed Jul 5, 2022
1 parent c7bbf99 commit be5e725
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
17 changes: 17 additions & 0 deletions include/cos_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CosConfig {
m_secret_key(""),
m_region(""),
m_tmp_token(""),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {}

/// \brief CosConfig构造函数
Expand All @@ -40,6 +42,8 @@ class CosConfig {
m_secret_key(secret_key),
m_region(region),
m_tmp_token(""),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {}

/// \brief CosConfig构造函数
Expand All @@ -56,6 +60,8 @@ class CosConfig {
m_secret_key(secret_key),
m_region(region),
m_tmp_token(tmp_token),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {}

/// \brief CosConfig复制构造函数
Expand All @@ -67,6 +73,8 @@ class CosConfig {
m_secret_key = config.m_secret_key;
m_region = config.m_region;
m_tmp_token = config.m_tmp_token;
m_is_use_intranet = config.m_is_use_intranet;
m_intranet_addr = config.m_intranet_addr;
m_config_parsed = config.m_config_parsed;
}

Expand All @@ -79,6 +87,8 @@ class CosConfig {
m_secret_key = config.m_secret_key;
m_region = config.m_region;
m_tmp_token = config.m_tmp_token;
m_is_use_intranet = config.m_is_use_intranet;
m_intranet_addr = config.m_intranet_addr;
m_config_parsed = config.m_config_parsed;
return *this;
}
Expand Down Expand Up @@ -142,9 +152,13 @@ class CosConfig {
/// \brief 设置是否使用自定义ip和端口号
void SetIsUseIntranetAddr(bool is_use_intranet);

bool IsUseIntranet();

/// \berief 设置自定义ip和端口号
void SetIntranetAddr(const std::string& intranet_addr);

std::string GetIntranetAddr();

/// \brief 设置日志回调
void SetLogCallback(const LogCallback log_callback);

Expand All @@ -164,6 +178,9 @@ class CosConfig {
std::string m_secret_key;
std::string m_region;
std::string m_tmp_token;

bool m_is_use_intranet;
std::string m_intranet_addr;
bool m_config_parsed;
};

Expand Down
14 changes: 14 additions & 0 deletions src/cos_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ CosConfig::CosConfig(const std::string& config_file)
m_secret_key(""),
m_region(""),
m_tmp_token(""),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {
if (InitConf(config_file)) {
m_config_parsed = true;
Expand Down Expand Up @@ -188,10 +190,12 @@ bool CosConfig::InitConf(const std::string& config_file) {

if (JsonObjectGetBoolValue(object, "IsUseIntranet", &bool_value)) {
CosSysConfig::SetIsUseIntranet(bool_value);
m_is_use_intranet = bool_value;
}

if (JsonObjectGetStringValue(object, "IntranetAddr", &str_value)) {
CosSysConfig::SetIntranetAddr(str_value);
m_intranet_addr = str_value;
}

CosSysConfig::PrintValue();
Expand Down Expand Up @@ -231,10 +235,20 @@ void CosConfig::SetConfigCredentail(const std::string& access_key,

void CosConfig::SetIsUseIntranetAddr(bool is_use_intranet) {
CosSysConfig::SetIsUseIntranet(is_use_intranet);
m_is_use_intranet = is_use_intranet;
}

bool CosConfig::IsUseIntranet() {
return m_is_use_intranet;
}

void CosConfig::SetIntranetAddr(const std::string& intranet_addr) {
CosSysConfig::SetIntranetAddr(intranet_addr);
m_intranet_addr = intranet_addr;
}

std::string CosConfig::GetIntranetAddr() {
return m_intranet_addr;
}

void CosConfig::SetLogCallback(const LogCallback log_callback) {
Expand Down
6 changes: 3 additions & 3 deletions src/op/base_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ std::string BaseOp::GetRealUrl(const std::string& host, const std::string& path,
dest_path = "/" + dest_path;
}

if (CosSysConfig::IsUseIntranet() &&
!CosSysConfig::GetIntranetAddr().empty()) {
dest_host = CosSysConfig::GetIntranetAddr();
if (m_config->IsUseIntranet() &&
!m_config->GetIntranetAddr().empty()) {
dest_host = m_config->GetIntranetAddr();
} else if (!CosSysConfig::GetDestDomain().empty()) {
dest_host = CosSysConfig::GetDestDomain();
} else if (CosSysConfig::GetUseDnsCache()) {
Expand Down

0 comments on commit be5e725

Please sign in to comment.