Skip to content

Commit

Permalink
support project anonymous write (#1959)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryzhx8 authored Dec 13, 2024
1 parent 8d42203 commit 7695ae8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
7 changes: 7 additions & 0 deletions core/plugin/flusher/sls/FlusherSLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -895,6 +898,10 @@ void FlusherSLS::OnSendDone(const HttpResponse& response, SenderQueueItem* item)
}
}
SLSClientManager::GetInstance()->UpdateAccessKeyStatus(mAliuid, !hasAuthError);
#ifdef __ENTERPRISE__
static auto manager = static_cast<EnterpriseSLSClientManager*>(SLSClientManager::GetInstance());
manager->UpdateProjectAnonymousWriteStatus(mProject, !hasAuthError);
#endif
}

bool FlusherSLS::Send(string&& data, const string& shardHashKey, const string& logstore) {
Expand Down
42 changes: 35 additions & 7 deletions core/sdk/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<EnterpriseSLSClientManager*>(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;
Expand All @@ -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) {
Expand All @@ -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<EnterpriseSLSClientManager*>(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;
Expand Down Expand Up @@ -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<EnterpriseSLSClientManager*>(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;
Expand Down

0 comments on commit 7695ae8

Please sign in to comment.