Skip to content

Commit

Permalink
feat(S3): added make to S3Config
Browse files Browse the repository at this point in the history
  • Loading branch information
mcakircali committed Dec 20, 2024
1 parent 701fe9e commit 3c29ecf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/eckit/io/s3/S3Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "eckit/config/LocalConfiguration.h"
#include "eckit/config/Resource.h"
#include "eckit/config/YAMLConfiguration.h"
#include "eckit/container/DenseSet.h"
#include "eckit/exception/Exceptions.h"
#include "eckit/filesystem/URI.h"
#include "eckit/log/CodeLocation.h"
Expand All @@ -28,9 +27,7 @@

#include <cstdint>
#include <iostream>
#include <map>
#include <ostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
Expand All @@ -43,7 +40,11 @@ namespace {

const std::string defaultConfigFile = "~/.config/eckit/S3Config.yaml";

S3Config fromYAML(const LocalConfiguration& config) {
} // namespace

//----------------------------------------------------------------------------------------------------------------------

S3Config S3Config::make(const LocalConfiguration& config) {
const net::Endpoint endpoint {config.getString("endpoint")};

const auto region = config.getString("region", s3DefaultRegion);
Expand All @@ -70,11 +71,7 @@ S3Config fromYAML(const LocalConfiguration& config) {
return s3config;
}

} // namespace

//----------------------------------------------------------------------------------------------------------------------

auto S3Config::fromFile(std::string path) -> std::vector<S3Config> {
auto S3Config::make(std::string path) -> std::vector<S3Config> {

if (path.empty()) { path = Resource<std::string>("s3ConfigFile;$ECKIT_S3_CONFIG_FILE", defaultConfigFile); }

Expand All @@ -89,7 +86,7 @@ auto S3Config::fromFile(std::string path) -> std::vector<S3Config> {

std::vector<S3Config> result;
result.reserve(servers.size());
for (const auto& server : servers) { result.emplace_back(fromYAML(server)); }
for (const auto& server : servers) { result.emplace_back(make(server)); }

return result;
}
Expand Down
14 changes: 13 additions & 1 deletion src/eckit/io/s3/S3Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace eckit {

class LocalConfiguration;

enum class S3Backend : std::uint8_t { AWS, REST, MINIO };

constexpr auto s3DefaultHost = "127.0.0.1";
Expand Down Expand Up @@ -60,7 +62,13 @@ constexpr auto s3DefaultRegion = "default";
///
struct S3Config {

static auto fromFile(std::string path) -> std::vector<S3Config>;
// static methods

static auto make(const LocalConfiguration& config) -> S3Config;

static auto make(std::string path) -> std::vector<S3Config>;

// constructors

S3Config() = default;

Expand All @@ -70,6 +78,8 @@ struct S3Config {

explicit S3Config(const URI& uri);

// operators

bool operator==(const S3Config& other) const {
return backend == other.backend && endpoint == other.endpoint && region == other.region;
}
Expand All @@ -80,6 +90,8 @@ struct S3Config {

friend std::ostream& operator<<(std::ostream& out, const S3Config& config);

// members

net::Endpoint endpoint {s3DefaultHost, s3DefaultPort};
std::string region {s3DefaultRegion};
S3Backend backend {S3Backend::AWS};
Expand Down
2 changes: 1 addition & 1 deletion src/eckit/io/s3/S3Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void S3Session::clear() {
// CLIENT

void S3Session::loadClients(const std::string& path) {
const auto configs = S3Config::fromFile(path);
const auto configs = S3Config::make(path);
for (const auto& config : configs) { addClient(config); }
}

Expand Down

0 comments on commit 3c29ecf

Please sign in to comment.