userver: samples/s3api/src/s3api_client.cpp
Loading...
Searching...
No Matches
samples/s3api/src/s3api_client.cpp
#include "s3api_client.hpp"
#include <userver/components/component_config.hpp>
namespace samples {
S3ApiSampleComponent::S3ApiSampleComponent(
)
: LoggableComponentBase(config, context),
http_client_(context.FindComponent<::components::HttpClient>().GetHttpClient()) {
auto my_client = GetClient();
DoVeryImportantThingsInS3(my_client);
}
s3api::ClientPtr S3ApiSampleComponent::GetClient() {
// Create connection settings
auto connection_cfg = s3api::ConnectionCfg(
std::chrono::milliseconds{100}, /* timeout */
2, /* retries */
std::nullopt /* proxy */
);
// Create connection object
auto s3_connection = s3api::MakeS3Connection(
http_client_, s3api::S3ConnectionType::kHttps, "s3-some-site.awsornot.com", connection_cfg
);
// Create authorizer.
auto auth = std::make_shared<s3api::authenticators::AccessKey>("my-access-key", s3api::Secret("my-secret-key"));
// create and return client
return s3api::GetS3Client(s3_connection, auth, "mybucket");
}
void DoVeryImportantThingsInS3(s3api::ClientPtr client) {
std::string path = "path/to/object";
std::string data{"some string data"};
client->PutObject(path, data);
client->GetObject(path);
}
} // namespace samples