Add GCP KMS example POC to test the CI

This commit is contained in:
Pablo Marcos 2024-11-15 15:47:32 +00:00
parent bf180940cd
commit e0bf6ec7e4
3 changed files with 61 additions and 1 deletions

View File

@ -157,7 +157,7 @@ endif()
no_warning(enum-constexpr-conversion) # breaks Protobuf in clang-16 no_warning(enum-constexpr-conversion) # breaks Protobuf in clang-16
option(ENABLE_TESTS "Provide unit_test_dbms target with Google.Test unit tests" ON) option(ENABLE_TESTS "Provide unit_test_dbms target with Google.Test unit tests" ON)
option(ENABLE_EXAMPLES "Build all example programs in 'examples' subdirectories" OFF) option(ENABLE_EXAMPLES "Build all example programs in 'examples' subdirectories" ON)
option(ENABLE_BENCHMARKS "Build all benchmark programs in 'benchmarks' subdirectories" OFF) option(ENABLE_BENCHMARKS "Build all benchmark programs in 'benchmarks' subdirectories" OFF)
if (OS_LINUX AND (ARCH_AMD64 OR ARCH_AARCH64) AND NOT USE_MUSL) if (OS_LINUX AND (ARCH_AMD64 OR ARCH_AARCH64) AND NOT USE_MUSL)

View File

@ -73,6 +73,9 @@ target_link_libraries (snappy_read_buffer PRIVATE clickhouse_common_io clickhous
clickhouse_add_executable (hadoop_snappy_read_buffer hadoop_snappy_read_buffer.cpp) clickhouse_add_executable (hadoop_snappy_read_buffer hadoop_snappy_read_buffer.cpp)
target_link_libraries (hadoop_snappy_read_buffer PRIVATE clickhouse_common_io clickhouse_common_config) target_link_libraries (hadoop_snappy_read_buffer PRIVATE clickhouse_common_io clickhouse_common_config)
clickhouse_add_executable (gcp_kms gcp_kms.cpp)
target_link_libraries (gcp_kms PRIVATE dbms)
if (TARGET ch_contrib::hdfs) if (TARGET ch_contrib::hdfs)
clickhouse_add_executable (read_buffer_from_hdfs read_buffer_from_hdfs.cpp) clickhouse_add_executable (read_buffer_from_hdfs read_buffer_from_hdfs.cpp)
target_link_libraries (read_buffer_from_hdfs PRIVATE dbms ch_contrib::hdfs) target_link_libraries (read_buffer_from_hdfs PRIVATE dbms ch_contrib::hdfs)

View File

@ -0,0 +1,57 @@
#include <string>
#include <Common/Base64.h>
#include <Core/Settings.h>
#include <Interpreters/Context.h>
#include <IO/S3/AWSLogger.h>
#include <IO/S3/Credentials.h>
#include <IO/S3/PocoHTTPClient.h>
#include <IO/S3/PocoHTTPClientFactory.h>
#include <IO/S3Common.h>
#include <Poco/ConsoleChannel.h>
#include <Poco/Logger.h>
#include <Common/Logger.h>
#include <Common/logger_useful.h>
#include <base/scope_guard.h>
#include "google/cloud/kms/v1/key_management_client.h"
#include "google/cloud/location.h"
#include "google/cloud/status.h"
using namespace DB;
using namespace S3;
int main(int argc, char * argv[])
{
auto shared_context = Context::createShared();
auto global_context = Context::createGlobal(shared_context.get());
global_context->makeGlobalContext();
Poco::AutoPtr<Poco::ConsoleChannel> channel(new Poco::ConsoleChannel(std::cerr));
Poco::Logger::root().setChannel(channel);
Poco::Logger::root().setLevel("debug");
auto logger = getLogger("PMO");
LOG_DEBUG(logger, "GCP KMS testing...");
if (argc != 3)
{
std::cerr << "Usage: " << argv[0] << " project-id location-id\n";
return 1;
}
auto const location = google::cloud::Location(argv[1], argv[2]);
namespace kms = ::google::cloud::kms_v1;
auto client = kms::KeyManagementServiceClient(
kms::MakeKeyManagementServiceConnection());
for (auto kr : client.ListKeyRings(location.FullName()))
{
if (!kr) throw std::runtime_error(std::move(kr).status().message());
std::cout << kr->DebugString() << "\n";
}
return 0;
}