Skip to content
Snippets Groups Projects
Commit b717ce70 authored by Erik Dahl's avatar Erik Dahl
Browse files

One more place for x-on-behalf-of header

parent 83f6d492
No related branches found
No related tags found
No related merge requests found
Pipeline #173753 failed
......@@ -65,7 +65,7 @@ Options::createSDManager() const
}
auto manager = std::make_unique<seismicdrive::SDManager>(sdCredentials_.url(), sdCredentials_.apiKey());
auto httpHeaders = segysdk::utilities::Settings::instance().getHttpHeaders();
const auto httpHeaders = segysdk::utilities::Settings::instance().getHttpHeaders();
if (!httpHeaders.empty()) {
manager->setHttpHeaders(httpHeaders);
}
......
......@@ -37,9 +37,9 @@ namespace segysdk::utilities
{
void
addHeaders(web::http::http_request& request, std::vector<segysdk::utilities::auth::HttpCredentialProvider::Header>& additional_headers, std::string& data_partition_id)
addHeaders(web::http::http_request& request, std::vector<segysdk::utilities::auth::HttpCredentialProvider::Header>& additional_headers, std::string& data_partition_id, std::string& on_behalf_of)
{
for (auto header : utilities::Settings::instance().getHttpHeaders()) {
for (auto const header : utilities::Settings::instance().getHttpHeaders()) {
request.headers().add(conversions::to_string_t(header.first), conversions::to_string_t(header.second));
}
......@@ -51,6 +51,10 @@ addHeaders(web::http::http_request& request, std::vector<segysdk::utilities::aut
request.headers().add(U("data-partition-id"), conversions::to_string_t(data_partition_id));
}
if (!on_behalf_of.empty() && request.headers().find(U("x-on-behalf-of")) == request.headers().end()) {
request.headers().add(U("x-on-behalf-of"), conversions::to_string_t(on_behalf_of));
}
if (request.headers().find(U("Content-type")) == request.headers().end()) {
request.headers().add(U("Content-type"), U("application/json"));
}
......@@ -71,10 +75,13 @@ StorageSvcClient::getRecord(const std::string& recordId) const
auto service_url = Environment::instance().storageSvcUrl();
auto data_partition_id = Environment::instance().osduDataPartitionId();
auto additional_headers = credentialProvider_->headers();
auto on_behalf_of = Environment::instance().sauth_user_id();
SEGYLOG_DEBUG("About to get record [" + recordId + "]");
SEGYLOG_DEBUG("Storage service URL: [" + service_url + "]");
SEGYLOG_DEBUG("Data partition ID : [" + data_partition_id + "]");
SEGYLOG_DEBUG("On behalf of : [" + on_behalf_of + "]");
if (Environment::instance().insecurePrintTokenToDebug()) {
SEGYLOG_DEBUG("Auth headers : [" + std::to_string(additional_headers.size()) + "]");
for (const auto& h : additional_headers) {
......@@ -99,7 +106,7 @@ StorageSvcClient::getRecord(const std::string& recordId) const
http_request request;
request.set_method(methods::GET);
addHeaders(request, additional_headers, data_partition_id);
addHeaders(request, additional_headers, data_partition_id, on_behalf_of);
auto response = client.request(request).get();
......@@ -128,6 +135,7 @@ StorageSvcClient::storeRecord(const std::string& recordContent) const
auto storage_svc_url = Environment::instance().storageSvcUrl();
auto data_partition_id = Environment::instance().osduDataPartitionId();
auto additional_headers = credentialProvider_->headers();
auto on_behalf_of = Environment::instance().sauth_user_id();
SEGYLOG_DEBUG("About to PUT record [" + std::to_string(recordContent.size()) + " chars]");
SEGYLOG_DEBUG("Storage service URL: [" + storage_svc_url + "]");
......@@ -149,7 +157,7 @@ StorageSvcClient::storeRecord(const std::string& recordContent) const
http_request request;
request.set_method(methods::PUT);
addHeaders(request, additional_headers, data_partition_id);
addHeaders(request, additional_headers, data_partition_id, on_behalf_of);
request.set_body("[" + recordContent + "]");
auto response = client.request(request).get();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment