Skip to content

Commit

Permalink
fix(S3): asString output and test config
Browse files Browse the repository at this point in the history
  • Loading branch information
mcakircali committed Dec 25, 2024
1 parent fcc5f37 commit 07b936b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/eckit/io/s3/S3BucketPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct S3BucketPath {

S3BucketPath(std::string bucket) : bucket {std::move(bucket)} { }

auto asString() const -> std::string { return '/' + bucket; }
auto asString() const -> std::string { return bucket; }

operator std::string() const { return asString(); }

Expand Down
13 changes: 8 additions & 5 deletions src/eckit/io/s3/S3Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ auto S3Config::make(std::string path) -> std::vector<S3Config> {
path = Resource<std::string>("s3ConfigFile;$ECKIT_S3_CONFIG_FILE", "~/.config/eckit/S3Config.yaml");
}

PathName configFile(path);
PathName configPath(path);

if (!configFile.exists()) {
Log::debug<LibEcKit>() << "S3 configuration file does not exist: " << configFile << std::endl;
if (!configPath.exists()) {
Log::debug<LibEcKit>() << "S3 configuration file does not exist: " << configPath << std::endl;
return {};
}

LOG_DEBUG_LIB(LibEcKit) << "Reading S3 configuration from: " << configFile << std::endl;
if (configPath.isDir()) {
Log::debug<LibEcKit>() << "Path " << configPath << " is a directory. Expecting a file!" << std::endl;
return {};
}

const auto servers = YAMLConfiguration(configFile).getSubConfigurations("servers");
const auto servers = YAMLConfiguration(configPath).getSubConfigurations("servers");

std::vector<S3Config> result;
result.reserve(servers.size());
Expand Down
15 changes: 9 additions & 6 deletions src/eckit/io/s3/S3Credential.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ auto S3Credential::fromFile(std::string path) -> std::vector<S3Credential> {

if (path.empty()) { path = Resource<std::string>("s3CredentialsFile;$ECKIT_S3_CREDENTIALS_FILE", defaultCredFile); }

PathName credFile(path);
PathName credPath(path);

if (!credFile.exists()) {
Log::debug<LibEcKit>() << "S3 credentials file does not exist: " << credFile << std::endl;
if (!credPath.exists()) {
Log::debug<LibEcKit>() << "S3 credentials file does not exist: " << credPath << std::endl;
return {};
}

LOG_DEBUG_LIB(LibEcKit) << "Reading S3 credentials from: " << credFile << std::endl;
if (credPath.isDir()) {
Log::debug<LibEcKit>() << "Path " << credPath << " is a directory. Expecting a file!" << std::endl;
return {};
}

std::vector<S3Credential> result;
const auto creds = YAMLConfiguration(credPath).getSubConfigurations("credentials");

const auto creds = YAMLConfiguration(credFile).getSubConfigurations("credentials");
std::vector<S3Credential> result;
result.reserve(creds.size());
for (const auto& cred : creds) { result.emplace_back(fromYAML(cred)); }

Expand Down
2 changes: 1 addition & 1 deletion src/eckit/io/s3/S3ObjectPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct S3ObjectPath {

S3ObjectPath(std::string bucket, std::string object) : bucket {std::move(bucket)}, object {std::move(object)} { }

auto asString() const -> std::string { return '/' + bucket + '/' + object; }
auto asString() const -> std::string { return bucket + '/' + object; }

operator std::string() const { return asString(); }

Expand Down
2 changes: 1 addition & 1 deletion tests/io/s3/test_s3_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ inline void cleanup(const std::vector<std::string>& bucketPaths) {
}
}

void writePerformance(S3BucketName& bucket, const int count) {
inline void writePerformance(S3BucketName& bucket, const int count) {
eckit::Timer timer;

Buffer buffer(1024 * 1024);
Expand Down
2 changes: 1 addition & 1 deletion tests/io/s3/test_s3_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ inline void cleanup(const std::vector<std::string>& bucketPaths) {
}
}

void writePerformance(S3BucketName& bucket, const int count) {
inline void writePerformance(S3BucketName& bucket, const int count) {
eckit::Timer timer;

Buffer buffer(1024 * 1024);
Expand Down

0 comments on commit 07b936b

Please sign in to comment.