Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haiqi96 committed Aug 14, 2024
1 parent 7a65181 commit 432713c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 6 additions & 7 deletions components/core/src/clp/aws/AwsAuthenticationSigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <boost/regex.hpp>
#include <fmt/chrono.h>
#include <fmt/format.h>
#include <string_utils/string_utils.hpp>

#include "../ErrorCode.hpp"
#include "../hash_utils.hpp"
#include "../string_utils/string_utils.hpp"
#include "../type_utils.hpp"
#include "constants.hpp"

Expand Down Expand Up @@ -173,17 +173,16 @@ S3Url::S3Url(string const& url) {
};

boost::smatch match;
string end_point;
if (boost::regex_match(url, match, host_style_url_regex)) {
m_region = match["region"];
m_bucket = match["bucket"];
m_key = match["key"];
end_point = match["endpoint"];
m_end_point = match["endpoint"];
} else if (boost::regex_match(url, match, path_style_url_regex)) {
m_region = match["region"];
m_bucket = match["bucket"];
m_key = match["key"];
end_point = match["endpoint"];
m_end_point = match["endpoint"];
} else {
throw OperationFailed(
ErrorCode_BadParam,
Expand All @@ -193,19 +192,19 @@ S3Url::S3Url(string const& url) {
);
}

if ("amazonaws.com" != end_point) {
if (cAwsEndpoint != m_end_point) {
throw OperationFailed(
ErrorCode_BadParam,
__FILENAME__,
__LINE__,
"Invalid S3 endpoint: " + end_point
"Invalid S3 endpoint: " + m_end_point
);
}

if (m_region.empty()) {
m_region = cDefaultRegion;
}
m_host = fmt::format("{}.s3.{}.{}", m_bucket, m_region, end_point);
m_host = fmt::format("{}.s3.{}.{}", m_bucket, m_region, m_end_point);
}

auto AwsAuthenticationSigner::generate_presigned_url(
Expand Down
1 change: 1 addition & 0 deletions components/core/src/clp/aws/AwsAuthenticationSigner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class S3Url {

private:
std::string m_region;
std::string m_end_point;
std::string m_bucket;
std::string m_key;
std::string m_host;
Expand Down
3 changes: 3 additions & 0 deletions components/core/src/clp/aws/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <string_view>

namespace clp::aws {
// Endpoint
constexpr std::string_view cAwsEndpoint{"amazonaws.com"};

// Query String Parameter Names
constexpr std::string_view cXAmzAlgorithm{"X-Amz-Algorithm"};
constexpr std::string_view cXAmzCredential{"X-Amz-Credential"};
Expand Down

0 comments on commit 432713c

Please sign in to comment.