Skip to content

Commit

Permalink
ip访问模式支持按实例级别单独配置(没有主动设置ip模式则兼容之前的ip配置全局共享方式)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinhgchen committed Jul 20, 2022
1 parent 56cb3f2 commit d6d7d3e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions include/cos_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CosConfig {
m_secret_key(""),
m_region(""),
m_tmp_token(""),
m_set_intranet_once(false),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {}
Expand All @@ -42,6 +43,7 @@ class CosConfig {
m_secret_key(secret_key),
m_region(region),
m_tmp_token(""),
m_set_intranet_once(false),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {}
Expand All @@ -60,6 +62,7 @@ class CosConfig {
m_secret_key(secret_key),
m_region(region),
m_tmp_token(tmp_token),
m_set_intranet_once(false),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {}
Expand All @@ -73,6 +76,7 @@ class CosConfig {
m_secret_key = config.m_secret_key;
m_region = config.m_region;
m_tmp_token = config.m_tmp_token;
m_set_intranet_once = config.m_set_intranet_once;
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 @@ -87,6 +91,7 @@ class CosConfig {
m_secret_key = config.m_secret_key;
m_region = config.m_region;
m_tmp_token = config.m_tmp_token;
m_set_intranet_once = config.m_set_intranet_once;
m_is_use_intranet = config.m_is_use_intranet;
m_intranet_addr = config.m_intranet_addr;
m_config_parsed = config.m_config_parsed;
Expand Down Expand Up @@ -159,6 +164,8 @@ class CosConfig {

std::string GetIntranetAddr();

bool GetSetIntranetOnce() const {return m_set_intranet_once;}

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

Expand All @@ -179,6 +186,7 @@ class CosConfig {
std::string m_region;
std::string m_tmp_token;

bool m_set_intranet_once;
bool m_is_use_intranet;
std::string m_intranet_addr;
bool m_config_parsed;
Expand Down
2 changes: 1 addition & 1 deletion include/cos_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace qcloud_cos {

#define COS_CPP_SDK_VERSON "v5.5.6"
#define COS_CPP_SDK_VERSON "v5.5.7"

/// 路径分隔符
const std::string kPathDelimiter = "/";
Expand Down
7 changes: 7 additions & 0 deletions src/cos_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CosConfig::CosConfig(const std::string& config_file)
m_secret_key(""),
m_region(""),
m_tmp_token(""),
m_set_intranet_once(false),
m_is_use_intranet(false),
m_intranet_addr(""),
m_config_parsed(false) {
Expand Down Expand Up @@ -191,11 +192,13 @@ bool CosConfig::InitConf(const std::string& config_file) {
if (JsonObjectGetBoolValue(object, "IsUseIntranet", &bool_value)) {
CosSysConfig::SetIsUseIntranet(bool_value);
m_is_use_intranet = bool_value;
m_set_intranet_once = true;
}

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

CosSysConfig::PrintValue();
Expand Down Expand Up @@ -236,6 +239,8 @@ 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;

m_set_intranet_once = true;
}

bool CosConfig::IsUseIntranet() {
Expand All @@ -245,6 +250,8 @@ bool CosConfig::IsUseIntranet() {
void CosConfig::SetIntranetAddr(const std::string& intranet_addr) {
CosSysConfig::SetIntranetAddr(intranet_addr);
m_intranet_addr = intranet_addr;

m_set_intranet_once = true;
}

std::string CosConfig::GetIntranetAddr() {
Expand Down
8 changes: 7 additions & 1 deletion src/cos_sys_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ unsigned CosSysConfig::m_dns_cache_expire_seconds = 600;
// dns cache大小
unsigned CosSysConfig::m_dns_cache_size = 1000;

std::mutex m_intranet_addr_lock;

void CosSysConfig::PrintValue() {
std::cout << "upload_part_size:" << m_upload_part_size << std::endl;
std::cout << "upload_copy_part_size:" << m_upload_copy_part_size << std::endl;
Expand Down Expand Up @@ -213,6 +215,7 @@ void CosSysConfig::SetIsUseIntranet(bool is_use_intranet) {
bool CosSysConfig::IsUseIntranet() { return m_is_use_intranet; }

void CosSysConfig::SetIntranetAddr(const std::string& intranet_addr) {
std::lock_guard<std::mutex> lock(m_intranet_addr_lock);
m_intranet_addr = intranet_addr;
}

Expand Down Expand Up @@ -248,7 +251,10 @@ std::string CosSysConfig::GetCIHost(const std::string& bucket_name,

std::string CosSysConfig::GetDestDomain() { return m_dest_domain; }

std::string CosSysConfig::GetIntranetAddr() { return m_intranet_addr; }
std::string CosSysConfig::GetIntranetAddr() {
std::lock_guard<std::mutex> lock(m_intranet_addr_lock);
return m_intranet_addr;
}

LogCallback CosSysConfig::GetLogCallback() { return m_log_callback; }

Expand Down
6 changes: 5 additions & 1 deletion src/op/base_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,13 @@ std::string BaseOp::GetRealUrl(const std::string& host, const std::string& path,
dest_path = "/" + dest_path;
}

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

0 comments on commit d6d7d3e

Please sign in to comment.