diff --git a/src/XrdS3/XrdS3Utils.cc b/src/XrdS3/XrdS3Utils.cc index 567ac620de0..d840283cb3a 100644 --- a/src/XrdS3/XrdS3Utils.cc +++ b/src/XrdS3/XrdS3Utils.cc @@ -289,6 +289,22 @@ std::string S3Utils::timestampToRFC7231(const struct tm *gmt) { return std::string(buffer); } +//------------------------------------------------------------------------------ +//! extract bucket name out of virtual host +//! @param FQHN +//! @return the name of the bucket or an empty string +//------------------------------------------------------------------------------ +std::string S3Utils::getBucketName(const std::string& host) +{ + auto ndot = std::count(host.begin(), host.end(), '.'); + if ( ndot > 2) { + // return bucket name + return host.substr(0, host.find('.')); + } else { + return ""; + } +} + //------------------------------------------------------------------------------ //! make a path //! diff --git a/src/XrdS3/XrdS3Utils.hh b/src/XrdS3/XrdS3Utils.hh index 70e538d77b1..63c2a021687 100644 --- a/src/XrdS3/XrdS3Utils.hh +++ b/src/XrdS3/XrdS3Utils.hh @@ -136,6 +136,8 @@ class S3Utils { static std::string timestampToRFC7231(const time_t &t); static std::string timestampToRFC7231(const tm *t); + static std::string getBucketName(const std::string& host); + static int makePath(char *path, mode_t mode); static void RmPath(std::filesystem::path path,