Skip to content
Snippets Groups Projects
Commit 01ccc3f1 authored by Georgios Bitzes's avatar Georgios Bitzes Committed by Pere Mato
Browse files

Add S3 Alternate support to TDavixFile

parent 502e6e04
No related branches found
No related tags found
No related merge requests found
......@@ -723,10 +723,17 @@ Davix.UseOldClient: @useoldwebfile@
# Sets the Amazon S3 authentication parameters
# Region is optional - if provided, davix will use v4 signatures
# Token is optional, and enables the use of STS temporary credentials
#
# Alternate is optional and takes a boolean value. If set to true, davix
# will assume that the bucket name is in the path, not in the hostname.
# Necessary because davix has to know the bucket name to calculate
# the S3 signatures.
#
# Davix.S3.SecretKey: secret
# Davix.S3.AccessKey: access
# Davix.S3.Region: region
# Davix.S3.Token: token
# Davix.S3.Alternate: yes
# NOTE: The authentication of TDavixFile/TDavixSystem can be influenced
# through some well known environment variables:
......
......@@ -71,6 +71,7 @@ const char* s3_seckey_opt = "s3seckey=";
const char* s3_acckey_opt = "s3acckey=";
const char* s3_region_opt = "s3region=";
const char* s3_token_opt = "s3token=";
const char* s3_alternate_opt = "s3alternate=";
const char* open_mode_read = "READ";
const char* open_mode_create = "CREATE";
const char* open_mode_new = "NEW";
......@@ -92,6 +93,15 @@ bool isno(const char *str)
}
bool strToBool(const char *str, bool defvalue) {
if(!str) return defvalue;
if(strcmp(str, "n") == 0 || strcmp(str, "no") == 0 || strcmp(str, "0") == 0 || strcmp(str, "false") == 0) return false;
if(strcmp(str, "y") == 0 || strcmp(str, "yes") == 0 || strcmp(str, "1") == 0 || strcmp(str, "true") == 0) return true;
return defvalue;
}
////////////////////////////////////////////////////////////////////////////////
int configure_open_flag(const std::string &str, int old_flag)
......@@ -321,6 +331,20 @@ static void awsToken(...) {
Warning("awsToken", "Unable to set AWS token, not supported by this version of davix");
}
// Identical SFINAE trick as above for setAwsAlternate
template<typename TRequestParams = Davix::RequestParams>
static auto awsAlternate(TRequestParams *parameters, bool option)
-> decltype(parameters->setAwsAlternate(option), void())
{
if (gDebug > 1) Info("awsAlternate", "Setting S3 path-based bucket option (s3alternate)");
parameters->setAwsAlternate(option);
}
template<typename TRequestParams = Davix::RequestParams>
static void awsAlternate(...) {
Warning("awsAlternate", "Unable to set AWS path-based bucket option (s3alternate), not supported by this version of davix");
}
void TDavixFileInternal::setAwsRegion(const std::string & region) {
if(!region.empty()) {
awsRegion(davixParam, region.c_str());
......@@ -333,6 +357,11 @@ void TDavixFileInternal::setAwsToken(const std::string & token) {
}
}
void TDavixFileInternal::setAwsAlternate(const bool & option) {
awsAlternate(davixParam, option);
}
void TDavixFileInternal::setS3Auth(const std::string &secret, const std::string &access,
const std::string &region, const std::string &token)
{
......@@ -382,6 +411,10 @@ void TDavixFileInternal::parseConfig()
if( (env_var = gEnv->GetValue("Davix.S3.Token", getenv("S3_TOKEN"))) != NULL) {
setAwsToken(env_var);
}
// need to set aws alternate?
if( (env_var = gEnv->GetValue("Davix.S3.Alternate", getenv("S3_ALTERNATE"))) != NULL) {
setAwsAlternate(strToBool(env_var, false));
}
}
env_var = gEnv->GetValue("Davix.GSI.GridMode", (const char *)"y");
......@@ -429,6 +462,10 @@ void TDavixFileInternal::parseParams(Option_t *option)
if (strncasecmp(it->c_str(), s3_token_opt, strlen(s3_token_opt)) == 0) {
s3token = std::string(it->c_str() + strlen(s3_token_opt));
}
// s3 alternate option
if (strncasecmp(it->c_str(), s3_alternate_opt, strlen(s3_alternate_opt)) == 0) {
setAwsAlternate(strToBool(it->c_str() + strlen(s3_alternate_opt), false));
}
// open mods
oflags = configure_open_flag(*it, oflags);
}
......
......@@ -100,6 +100,7 @@ private:
void setAwsRegion(const std::string & region);
void setAwsToken(const std::string & token);
void setAwsAlternate(const bool &option);
void setS3Auth(const std::string & secret, const std::string & access,
const std::string & region, const std::string & token);
......
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