Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support project anonymous write #1959

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading