From 952f818538418c36cd987904c709c5b0d0a1d73c Mon Sep 17 00:00:00 2001 From: Andreas-Joachim Peters Date: Mon, 24 Jun 2024 13:28:18 +0200 Subject: [PATCH] XrdS3: add simplie 'getBucketName' function extracting bucket name from virtual host URI --- src/XrdS3/XrdS3Utils.cc | 16 ++++++++++++++++ src/XrdS3/XrdS3Utils.hh | 2 ++ 2 files changed, 18 insertions(+) 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,