diff --git a/core/plugin/flusher/sls/FlusherSLS.cpp b/core/plugin/flusher/sls/FlusherSLS.cpp index 47977e47a6..67a87aa1ad 100644 --- a/core/plugin/flusher/sls/FlusherSLS.cpp +++ b/core/plugin/flusher/sls/FlusherSLS.cpp @@ -40,6 +40,9 @@ // TODO: temporarily used here #include "pipeline/PipelineManager.h" #include "plugin/flusher/sls/DiskBufferWriter.h" +#ifdef __ENTERPRISE__ +#include "plugin/flusher/sls/EnterpriseSLSClientManager.h" +#endif using namespace std; @@ -895,6 +898,10 @@ void FlusherSLS::OnSendDone(const HttpResponse& response, SenderQueueItem* item) } } SLSClientManager::GetInstance()->UpdateAccessKeyStatus(mAliuid, !hasAuthError); +#ifdef __ENTERPRISE__ + static auto manager = static_cast(SLSClientManager::GetInstance()); + manager->UpdateProjectAnonymousWriteStatus(mProject, !hasAuthError); +#endif } bool FlusherSLS::Send(string&& data, const string& shardHashKey, const string& logstore) { diff --git a/core/sdk/Client.cpp b/core/sdk/Client.cpp index c99d4dd71f..acfc49f95c 100644 --- a/core/sdk/Client.cpp +++ b/core/sdk/Client.cpp @@ -18,10 +18,14 @@ #include "CurlImp.h" #include "Exception.h" #include "Result.h" -#include "logger/Logger.h" -#include "plugin/flusher/sls/SLSClientManager.h" #include "app_config/AppConfig.h" +#include "common/Flags.h" +#include "logger/Logger.h" #include "monitor/Monitor.h" +#include "plugin/flusher/sls/SLSClientManager.h" +#ifdef __ENTERPRISE__ +#include "plugin/flusher/sls/EnterpriseSLSClientManager.h" +#endif namespace logtail { namespace sdk { @@ -214,7 +218,12 @@ namespace sdk { SLSClientManager::AuthType type; string accessKeyId, accessKeySecret; if (!SLSClientManager::GetInstance()->GetAccessKey(mAliuid, type, accessKeyId, accessKeySecret)) { - throw LOGException(LOGE_UNAUTHORIZED, ""); +#ifdef __ENTERPRISE__ + static auto* manager = static_cast(SLSClientManager::GetInstance()); + if (!manager->GetAccessKeyIfProjectSupportsAnonymousWrite(project, type, accessKeyId, accessKeySecret)) { + throw LOGException(LOGE_UNAUTHORIZED, ""); + } +#endif } if (type == SLSClientManager::AuthType::ANONYMOUS) { header[X_LOG_KEYPROVIDER] = MD5_SHA1_SALT_KEYPROVIDER; @@ -232,8 +241,17 @@ namespace sdk { if (mPort == 80 && mUsingHTTPS) { port = 443; } - mClient->Send( - httpMethod, host, port, url, queryString, header, body, mTimeout, httpMessage, AppConfig::GetInstance()->GetBindInterface(), mUsingHTTPS); + mClient->Send(httpMethod, + host, + port, + url, + queryString, + header, + body, + mTimeout, + httpMessage, + AppConfig::GetInstance()->GetBindInterface(), + mUsingHTTPS); if (httpMessage.statusCode != 200) { if (realIpPtr != NULL) { @@ -252,7 +270,12 @@ namespace sdk { SLSClientManager::AuthType type; string accessKeyId, accessKeySecret; if (!SLSClientManager::GetInstance()->GetAccessKey(mAliuid, type, accessKeyId, accessKeySecret)) { - return nullptr; +#ifdef __ENTERPRISE__ + static auto* manager = static_cast(SLSClientManager::GetInstance()); + if (!manager->GetAccessKeyIfProjectSupportsAnonymousWrite(project, type, accessKeyId, accessKeySecret)) { + return nullptr; + } +#endif } if (type == SLSClientManager::AuthType::ANONYMOUS) { httpHeader[X_LOG_KEYPROVIDER] = MD5_SHA1_SALT_KEYPROVIDER; @@ -280,7 +303,12 @@ namespace sdk { SLSClientManager::AuthType type; string accessKeyId, accessKeySecret; if (!SLSClientManager::GetInstance()->GetAccessKey(mAliuid, type, accessKeyId, accessKeySecret)) { - return nullptr; +#ifdef __ENTERPRISE__ + static auto* manager = static_cast(SLSClientManager::GetInstance()); + if (!manager->GetAccessKeyIfProjectSupportsAnonymousWrite(project, type, accessKeyId, accessKeySecret)) { + return nullptr; + } +#endif } if (type == SLSClientManager::AuthType::ANONYMOUS) { httpHeader[X_LOG_KEYPROVIDER] = MD5_SHA1_SALT_KEYPROVIDER;