Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add gcp skeleton #290

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/third_party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ add_third_party(
add_third_party(
rapidjson
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG 1a803826f1197b5e30703afe4b9c0e7dd48074f5
GIT_TAG ab1842a
CMAKE_PASS_FLAGS "-DRAPIDJSON_BUILD_TESTS=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF \
-DRAPIDJSON_BUILD_DOC=OFF"
LIB "none"
Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ cxx_link(echo_server base fibers2 http_server_lib TRDP::gperf)
add_executable(s3_demo s3_demo.cc)
cxx_link(s3_demo base awsv2_lib)

add_executable(gcs_demo gcs_demo.cc)
cxx_link(gcs_demo gcp_lib)

add_executable(https_client_cli https_client_cli.cc)
cxx_link(https_client_cli base fibers2 http_client_lib tls_lib)
59 changes: 59 additions & 0 deletions examples/gcs_demo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.

#include "base/flags.h"
#include "base/init.h"
#include "base/logging.h"
#include "util/cloud/gcp/gcs.h"
#include "util/fibers/pool.h"

using namespace std;
using namespace boost;
using namespace util;

using absl::GetFlag;

ABSL_FLAG(string, bucket, "", "");
ABSL_FLAG(string, access_token, "", "");
ABSL_FLAG(uint32_t, connect_ms, 2000, "");
ABSL_FLAG(bool, epoll, false, "Whether to use epoll instead of io_uring");


void Run(SSL_CTX* ctx) {
fb2::ProactorBase* pb = fb2::ProactorBase::me();
cloud::GCS gcs(ctx, pb);
error_code ec = gcs.Connect(GetFlag(FLAGS_connect_ms));
CHECK(!ec) << "Could not connect " << ec;
auto res = gcs.ListBuckets();
CHECK(res) << res.error();
for (auto v : *res) {
CONSOLE_INFO << v;
}
}

int main(int argc, char** argv) {
MainInitGuard guard(&argc, &argv);

std::unique_ptr<util::ProactorPool> pp;

#ifdef __linux__
if (absl::GetFlag(FLAGS_epoll)) {
pp.reset(util::fb2::Pool::Epoll());
} else {
pp.reset(util::fb2::Pool::IOUring(256));
}
#else
pp.reset(util::fb2::Pool::Epoll());
#endif

pp->Run();

SSL_CTX* ctx = util::http::TlsClient::CreateSslContext();
pp->GetNextProactor()->Await([ctx] {
Run(ctx);
});
util::http::TlsClient::FreeContext(ctx);


return 0;
}
1 change: 1 addition & 0 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_subdirectory(html)
add_subdirectory(metrics)
add_subdirectory(tls)
add_subdirectory(http)
add_subdirectory(cloud)

if (WITH_AWS)
add_subdirectory(aws)
Expand Down
1 change: 1 addition & 0 deletions util/cloud/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(gcp)
3 changes: 3 additions & 0 deletions util/cloud/gcp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(gcp_lib gcs.cc)

cxx_link(gcp_lib http_client_lib)
32 changes: 32 additions & 0 deletions util/cloud/gcp/gcs.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.

#include "util/cloud/gcp/gcs.h"

namespace util {
namespace cloud {

namespace {
constexpr char kDomain[] = "www.googleapis.com";
} // namespace


GCS::GCS(SSL_CTX* ssl_cntx, fb2::ProactorBase* pb) {
client_.reset(new http::TlsClient(pb));
}

GCS::~GCS() {
}

std::error_code GCS::Connect(unsigned msec) {
client_->set_connect_timeout_ms(msec);

return client_->Connect(kDomain, "443");
}

auto GCS::ListBuckets() -> ListBucketResult {
return {};
}

} // namespace cloud
} // namespace util
39 changes: 39 additions & 0 deletions util/cloud/gcp/gcs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.

#pragma once

#include <io/io.h>

#include <vector>

#include "util/http/http_client.h"

typedef struct ssl_ctx_st SSL_CTX;

namespace util {

namespace fb2 {
class ProactorBase;
} // namespace fb2

namespace cloud {

class GCS {
public:
using ListBucketResult = io::Result<std::vector<std::string>>;

GCS(SSL_CTX* ssl_cntx, fb2::ProactorBase* pb);
~GCS();

std::error_code Connect(unsigned msec);

ListBucketResult ListBuckets();

private:
SSL_CTX* ssl_ctx_;
std::unique_ptr<http::Client> client_;
};

} // namespace cloud
} // namespace util
Loading