From c62cd6dc1a3f9a94b3c0774d425a4083a35d5c7e Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 10 Mar 2022 16:39:17 +0000 Subject: [PATCH 1/3] feat(kms): support the EKM service --- generator/generator_config.textproto | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/generator/generator_config.textproto b/generator/generator_config.textproto index e8611da79811b..193859c136d5a 100644 --- a/generator/generator_config.textproto +++ b/generator/generator_config.textproto @@ -485,6 +485,13 @@ service { retryable_status_codes: ["kDeadlineExceeded", "kUnavailable"] } +service { + service_proto_path: "google/cloud/kms/v1/ekm_service.proto" + product_path: "google/cloud/kms" + initial_copyright_year: "2022" + retryable_status_codes: ["kUnavailable"] +} + # Language service { service_proto_path: "google/cloud/language/v1/language_service.proto" From ae003649969ea1844bdac57ecbe12656eb9d4811 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 10 Mar 2022 16:39:40 +0000 Subject: [PATCH 2/3] Run generator and format its output --- google/cloud/kms/ekm_client.cc | 109 +++++++ google/cloud/kms/ekm_client.h | 268 ++++++++++++++++++ google/cloud/kms/ekm_connection.cc | 96 +++++++ google/cloud/kms/ekm_connection.h | 88 ++++++ .../kms/ekm_connection_idempotency_policy.cc | 76 +++++ .../kms/ekm_connection_idempotency_policy.h | 62 ++++ google/cloud/kms/ekm_options.h | 58 ++++ .../cloud/kms/internal/ekm_auth_decorator.cc | 72 +++++ .../cloud/kms/internal/ekm_auth_decorator.h | 70 +++++ .../cloud/kms/internal/ekm_connection_impl.cc | 119 ++++++++ .../cloud/kms/internal/ekm_connection_impl.h | 102 +++++++ .../kms/internal/ekm_logging_decorator.cc | 90 ++++++ .../kms/internal/ekm_logging_decorator.h | 71 +++++ .../kms/internal/ekm_metadata_decorator.cc | 90 ++++++ .../kms/internal/ekm_metadata_decorator.h | 70 +++++ .../cloud/kms/internal/ekm_option_defaults.cc | 63 ++++ .../cloud/kms/internal/ekm_option_defaults.h | 37 +++ google/cloud/kms/internal/ekm_retry_traits.h | 43 +++ google/cloud/kms/internal/ekm_stub.cc | 87 ++++++ google/cloud/kms/internal/ekm_stub.h | 89 ++++++ google/cloud/kms/internal/ekm_stub_factory.cc | 63 ++++ google/cloud/kms/internal/ekm_stub_factory.h | 42 +++ google/cloud/kms/mocks/mock_ekm_connection.h | 59 ++++ 23 files changed, 1924 insertions(+) create mode 100644 google/cloud/kms/ekm_client.cc create mode 100644 google/cloud/kms/ekm_client.h create mode 100644 google/cloud/kms/ekm_connection.cc create mode 100644 google/cloud/kms/ekm_connection.h create mode 100644 google/cloud/kms/ekm_connection_idempotency_policy.cc create mode 100644 google/cloud/kms/ekm_connection_idempotency_policy.h create mode 100644 google/cloud/kms/ekm_options.h create mode 100644 google/cloud/kms/internal/ekm_auth_decorator.cc create mode 100644 google/cloud/kms/internal/ekm_auth_decorator.h create mode 100644 google/cloud/kms/internal/ekm_connection_impl.cc create mode 100644 google/cloud/kms/internal/ekm_connection_impl.h create mode 100644 google/cloud/kms/internal/ekm_logging_decorator.cc create mode 100644 google/cloud/kms/internal/ekm_logging_decorator.h create mode 100644 google/cloud/kms/internal/ekm_metadata_decorator.cc create mode 100644 google/cloud/kms/internal/ekm_metadata_decorator.h create mode 100644 google/cloud/kms/internal/ekm_option_defaults.cc create mode 100644 google/cloud/kms/internal/ekm_option_defaults.h create mode 100644 google/cloud/kms/internal/ekm_retry_traits.h create mode 100644 google/cloud/kms/internal/ekm_stub.cc create mode 100644 google/cloud/kms/internal/ekm_stub.h create mode 100644 google/cloud/kms/internal/ekm_stub_factory.cc create mode 100644 google/cloud/kms/internal/ekm_stub_factory.h create mode 100644 google/cloud/kms/mocks/mock_ekm_connection.h diff --git a/google/cloud/kms/ekm_client.cc b/google/cloud/kms/ekm_client.cc new file mode 100644 index 0000000000000..d7854f4e175f4 --- /dev/null +++ b/google/cloud/kms/ekm_client.cc @@ -0,0 +1,109 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/ekm_client.h" +#include "google/cloud/kms/internal/ekm_option_defaults.h" +#include + +namespace google { +namespace cloud { +namespace kms { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +EkmServiceClient::EkmServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_(internal::MergeOptions( + std::move(opts), + kms_internal::EkmServiceDefaultOptions(connection_->options()))) {} +EkmServiceClient::~EkmServiceClient() = default; + +StreamRange +EkmServiceClient::ListEkmConnections(std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::kms::v1::ListEkmConnectionsRequest request; + request.set_parent(parent); + return connection_->ListEkmConnections(request); +} + +StreamRange +EkmServiceClient::ListEkmConnections( + google::cloud::kms::v1::ListEkmConnectionsRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListEkmConnections(std::move(request)); +} + +StatusOr +EkmServiceClient::GetEkmConnection(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::kms::v1::GetEkmConnectionRequest request; + request.set_name(name); + return connection_->GetEkmConnection(request); +} + +StatusOr +EkmServiceClient::GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetEkmConnection(request); +} + +StatusOr +EkmServiceClient::CreateEkmConnection( + std::string const& parent, std::string const& ekm_connection_id, + google::cloud::kms::v1::EkmConnection const& ekm_connection, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::kms::v1::CreateEkmConnectionRequest request; + request.set_parent(parent); + request.set_ekm_connection_id(ekm_connection_id); + *request.mutable_ekm_connection() = ekm_connection; + return connection_->CreateEkmConnection(request); +} + +StatusOr +EkmServiceClient::CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateEkmConnection(request); +} + +StatusOr +EkmServiceClient::UpdateEkmConnection( + google::cloud::kms::v1::EkmConnection const& ekm_connection, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::kms::v1::UpdateEkmConnectionRequest request; + *request.mutable_ekm_connection() = ekm_connection; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateEkmConnection(request); +} + +StatusOr +EkmServiceClient::UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateEkmConnection(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/ekm_client.h b/google/cloud/kms/ekm_client.h new file mode 100644 index 0000000000000..5ea1e194683b2 --- /dev/null +++ b/google/cloud/kms/ekm_client.h @@ -0,0 +1,268 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CLIENT_H + +#include "google/cloud/kms/ekm_connection.h" +#include "google/cloud/future.h" +#include "google/cloud/options.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace kms { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// Google Cloud Key Management EKM Service +/// +/// Manages external cryptographic keys and operations using those keys. +/// Implements a REST model with the following objects: +/// * [EkmConnection][google.cloud.kms.v1.EkmConnection] +/// +/// @par Equality +/// +/// Instances of this class created via copy-construction or copy-assignment +/// always compare equal. Instances created with equal +/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare +/// equal share the same underlying resources. +/// +/// @par Performance +/// +/// Creating a new instance of this class is a relatively expensive operation, +/// new objects establish new connections to the service. In contrast, +/// copy-construction, move-construction, and the corresponding assignment +/// operations are relatively efficient as the copies share all underlying +/// resources. +/// +/// @par Thread Safety +/// +/// Concurrent access to different instances of this class, even if they compare +/// equal, is guaranteed to work. Two or more threads operating on the same +/// instance of this class is not guaranteed to work. Since copy-construction +/// and move-construction is a relatively efficient operation, consider using +/// such a copy when using this class from multiple threads. +/// +class EkmServiceClient { + public: + explicit EkmServiceClient(std::shared_ptr connection, + Options opts = {}); + ~EkmServiceClient(); + + //@{ + // @name Copy and move support + EkmServiceClient(EkmServiceClient const&) = default; + EkmServiceClient& operator=(EkmServiceClient const&) = default; + EkmServiceClient(EkmServiceClient&&) = default; + EkmServiceClient& operator=(EkmServiceClient&&) = default; + //@} + + //@{ + // @name Equality + friend bool operator==(EkmServiceClient const& a, EkmServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(EkmServiceClient const& a, EkmServiceClient const& b) { + return !(a == b); + } + //@} + + /// + /// Lists [EkmConnections][google.cloud.kms.v1.EkmConnection]. + /// + /// @param parent Required. The resource name of the location associated with + /// the + /// [EkmConnections][google.cloud.kms.v1.EkmConnection] to list, in the + /// format `projects/*/locations/*`. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.ListEkmConnectionsRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L89} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StreamRange ListEkmConnections( + std::string const& parent, Options opts = {}); + + /// + /// Lists [EkmConnections][google.cloud.kms.v1.EkmConnection]. + /// + /// @param request + /// @googleapis_link{google::cloud::kms::v1::ListEkmConnectionsRequest,google/cloud/kms/v1/ekm_service.proto#L89} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.ListEkmConnectionsRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L89} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StreamRange ListEkmConnections( + google::cloud::kms::v1::ListEkmConnectionsRequest request, + Options opts = {}); + + /// + /// Returns metadata for a given + /// [EkmConnection][google.cloud.kms.v1.EkmConnection]. + /// + /// @param name Required. The [name][google.cloud.kms.v1.EkmConnection.name] + /// of the + /// [EkmConnection][google.cloud.kms.v1.EkmConnection] to get. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.GetEkmConnectionRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L142} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StatusOr GetEkmConnection( + std::string const& name, Options opts = {}); + + /// + /// Returns metadata for a given + /// [EkmConnection][google.cloud.kms.v1.EkmConnection]. + /// + /// @param request + /// @googleapis_link{google::cloud::kms::v1::GetEkmConnectionRequest,google/cloud/kms/v1/ekm_service.proto#L142} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.GetEkmConnectionRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L142} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StatusOr GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const& request, + Options opts = {}); + + /// + /// Creates a new [EkmConnection][google.cloud.kms.v1.EkmConnection] in a + /// given Project and Location. + /// + /// @param parent Required. The resource name of the location associated with + /// the + /// [EkmConnection][google.cloud.kms.v1.EkmConnection], in the format + /// `projects/*/locations/*`. + /// @param ekm_connection_id Required. It must be unique within a location + /// and match the regular + /// expression `[a-zA-Z0-9_-]{1,63}`. + /// @param ekm_connection Required. An + /// [EkmConnection][google.cloud.kms.v1.EkmConnection] with + /// initial field values. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.CreateEkmConnectionRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L154} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StatusOr CreateEkmConnection( + std::string const& parent, std::string const& ekm_connection_id, + google::cloud::kms::v1::EkmConnection const& ekm_connection, + Options opts = {}); + + /// + /// Creates a new [EkmConnection][google.cloud.kms.v1.EkmConnection] in a + /// given Project and Location. + /// + /// @param request + /// @googleapis_link{google::cloud::kms::v1::CreateEkmConnectionRequest,google/cloud/kms/v1/ekm_service.proto#L154} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.CreateEkmConnectionRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L154} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StatusOr CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const& request, + Options opts = {}); + + /// + /// Updates an [EkmConnection][google.cloud.kms.v1.EkmConnection]'s metadata. + /// + /// @param ekm_connection Required. + /// [EkmConnection][google.cloud.kms.v1.EkmConnection] with updated + /// values. + /// @param update_mask Required. List of fields to be updated in this + /// request. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.UpdateEkmConnectionRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L175} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StatusOr UpdateEkmConnection( + google::cloud::kms::v1::EkmConnection const& ekm_connection, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + /// + /// Updates an [EkmConnection][google.cloud.kms.v1.EkmConnection]'s metadata. + /// + /// @param request + /// @googleapis_link{google::cloud::kms::v1::UpdateEkmConnectionRequest,google/cloud/kms/v1/ekm_service.proto#L175} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::EkmConnection,google/cloud/kms/v1/ekm_service.proto#L234} + /// + /// [google.cloud.kms.v1.UpdateEkmConnectionRequest]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L175} + /// [google.cloud.kms.v1.EkmConnection]: + /// @googleapis_reference_link{google/cloud/kms/v1/ekm_service.proto#L234} + /// + StatusOr UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CLIENT_H diff --git a/google/cloud/kms/ekm_connection.cc b/google/cloud/kms/ekm_connection.cc new file mode 100644 index 0000000000000..3bb9435f47259 --- /dev/null +++ b/google/cloud/kms/ekm_connection.cc @@ -0,0 +1,96 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/ekm_connection.h" +#include "google/cloud/kms/ekm_options.h" +#include "google/cloud/kms/internal/ekm_connection_impl.h" +#include "google/cloud/kms/internal/ekm_option_defaults.h" +#include "google/cloud/kms/internal/ekm_stub_factory.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include + +namespace google { +namespace cloud { +namespace kms { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +EkmServiceConnection::~EkmServiceConnection() = default; + +StreamRange + EkmServiceConnection::ListEkmConnections( + google::cloud::kms::v1:: + ListEkmConnectionsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr +EkmServiceConnection::GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +EkmServiceConnection::CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +EkmServiceConnection::UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +std::shared_ptr MakeEkmServiceConnection( + Options options) { + internal::CheckExpectedOptions(options, __func__); + options = kms_internal::EkmServiceDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto stub = + kms_internal::CreateDefaultEkmServiceStub(background->cq(), options); + return std::make_shared( + std::move(background), std::move(stub), std::move(options)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms +} // namespace cloud +} // namespace google + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeEkmServiceConnection( + std::shared_ptr stub, Options options) { + options = EkmServiceDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + return std::make_shared( + std::move(background), std::move(stub), std::move(options)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/ekm_connection.h b/google/cloud/kms/ekm_connection.h new file mode 100644 index 0000000000000..aaf752e517c04 --- /dev/null +++ b/google/cloud/kms/ekm_connection.h @@ -0,0 +1,88 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CONNECTION_H + +#include "google/cloud/kms/ekm_connection_idempotency_policy.h" +#include "google/cloud/kms/internal/ekm_retry_traits.h" +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace kms { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using EkmServiceRetryPolicy = ::google::cloud::internal::TraitBasedRetryPolicy< + kms_internal::EkmServiceRetryTraits>; + +using EkmServiceLimitedTimeRetryPolicy = + ::google::cloud::internal::LimitedTimeRetryPolicy< + kms_internal::EkmServiceRetryTraits>; + +using EkmServiceLimitedErrorCountRetryPolicy = + ::google::cloud::internal::LimitedErrorCountRetryPolicy< + kms_internal::EkmServiceRetryTraits>; + +class EkmServiceConnection { + public: + virtual ~EkmServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StreamRange ListEkmConnections( + google::cloud::kms::v1::ListEkmConnectionsRequest request); + + virtual StatusOr GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const& request); + + virtual StatusOr CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const& request); + + virtual StatusOr UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request); +}; + +std::shared_ptr MakeEkmServiceConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms +} // namespace cloud +} // namespace google + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeEkmServiceConnection( + std::shared_ptr stub, Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CONNECTION_H diff --git a/google/cloud/kms/ekm_connection_idempotency_policy.cc b/google/cloud/kms/ekm_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..1c4e1f24792b6 --- /dev/null +++ b/google/cloud/kms/ekm_connection_idempotency_policy.cc @@ -0,0 +1,76 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/ekm_connection_idempotency_policy.h" +#include "absl/memory/memory.h" +#include + +namespace google { +namespace cloud { +namespace kms { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +EkmServiceConnectionIdempotencyPolicy:: + ~EkmServiceConnectionIdempotencyPolicy() = default; + +namespace { +class DefaultEkmServiceConnectionIdempotencyPolicy + : public EkmServiceConnectionIdempotencyPolicy { + public: + ~DefaultEkmServiceConnectionIdempotencyPolicy() override = default; + + /// Create a new copy of this object. + std::unique_ptr clone() + const override { + return absl::make_unique( + *this); + } + + Idempotency ListEkmConnections( + google::cloud::kms::v1::ListEkmConnectionsRequest) override { + return Idempotency::kIdempotent; + } + + Idempotency GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const&) override { + return Idempotency::kIdempotent; + } + + Idempotency CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const&) override { + return Idempotency::kNonIdempotent; + } + + Idempotency UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const&) override { + return Idempotency::kNonIdempotent; + } +}; +} // namespace + +std::unique_ptr +MakeDefaultEkmServiceConnectionIdempotencyPolicy() { + return absl::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/ekm_connection_idempotency_policy.h b/google/cloud/kms/ekm_connection_idempotency_policy.h new file mode 100644 index 0000000000000..e81da48f5a07e --- /dev/null +++ b/google/cloud/kms/ekm_connection_idempotency_policy.h @@ -0,0 +1,62 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/internal/retry_policy.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class EkmServiceConnectionIdempotencyPolicy { + public: + virtual ~EkmServiceConnectionIdempotencyPolicy() = 0; + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const = 0; + + virtual google::cloud::Idempotency ListEkmConnections( + google::cloud::kms::v1::ListEkmConnectionsRequest request) = 0; + + virtual google::cloud::Idempotency GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const& request) = 0; + + virtual google::cloud::Idempotency CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) = 0; + + virtual google::cloud::Idempotency UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) = 0; +}; + +std::unique_ptr +MakeDefaultEkmServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/kms/ekm_options.h b/google/cloud/kms/ekm_options.h new file mode 100644 index 0000000000000..8b3f934325fc3 --- /dev/null +++ b/google/cloud/kms/ekm_options.h @@ -0,0 +1,58 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_OPTIONS_H + +#include "google/cloud/kms/ekm_connection.h" +#include "google/cloud/kms/ekm_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace kms { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Option to use with `google::cloud::Options`. +struct EkmServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/// Option to use with `google::cloud::Options`. +struct EkmServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/// Option to use with `google::cloud::Options`. +struct EkmServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +using EkmServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_EKM_OPTIONS_H diff --git a/google/cloud/kms/internal/ekm_auth_decorator.cc b/google/cloud/kms/internal/ekm_auth_decorator.cc new file mode 100644 index 0000000000000..925eb5c13ec71 --- /dev/null +++ b/google/cloud/kms/internal/ekm_auth_decorator.cc @@ -0,0 +1,72 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/internal/ekm_auth_decorator.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +EkmServiceAuth::EkmServiceAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +EkmServiceAuth::ListEkmConnections( + grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListEkmConnections(context, request); +} + +StatusOr +EkmServiceAuth::GetEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetEkmConnection(context, request); +} + +StatusOr +EkmServiceAuth::CreateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateEkmConnection(context, request); +} + +StatusOr +EkmServiceAuth::UpdateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateEkmConnection(context, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/internal/ekm_auth_decorator.h b/google/cloud/kms/internal/ekm_auth_decorator.h new file mode 100644 index 0000000000000..0f73d95daab50 --- /dev/null +++ b/google/cloud/kms/internal/ekm_auth_decorator.h @@ -0,0 +1,70 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_AUTH_DECORATOR_H + +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class EkmServiceAuth : public EkmServiceStub { + public: + ~EkmServiceAuth() override = default; + EkmServiceAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr + ListEkmConnections(grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& + request) override; + + StatusOr GetEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) override; + + StatusOr CreateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) + override; + + StatusOr UpdateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) + override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_AUTH_DECORATOR_H diff --git a/google/cloud/kms/internal/ekm_connection_impl.cc b/google/cloud/kms/internal/ekm_connection_impl.cc new file mode 100644 index 0000000000000..3dd9e1ce52404 --- /dev/null +++ b/google/cloud/kms/internal/ekm_connection_impl.cc @@ -0,0 +1,119 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/internal/ekm_connection_impl.h" +#include "google/cloud/kms/internal/ekm_option_defaults.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/retry_loop.h" +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +EkmServiceConnectionImpl::EkmServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + kms_internal::EkmServiceDefaultOptions( + EkmServiceConnection::options()))) {} + +StreamRange +EkmServiceConnectionImpl::ListEkmConnections( + google::cloud::kms::v1::ListEkmConnectionsRequest request) { + request.clear_page_token(); + auto stub = stub_; + auto retry = + std::shared_ptr(retry_policy()); + auto backoff = std::shared_ptr(backoff_policy()); + auto idempotency = idempotency_policy()->ListEkmConnections(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + std::move(request), + [stub, retry, backoff, idempotency, function_name]( + google::cloud::kms::v1::ListEkmConnectionsRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& + request) { + return stub->ListEkmConnections(context, request); + }, + r, function_name); + }, + [](google::cloud::kms::v1::ListEkmConnectionsResponse r) { + std::vector result( + r.ekm_connections().size()); + auto& messages = *r.mutable_ekm_connections(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +EkmServiceConnectionImpl::GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const& request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->GetEkmConnection(request), + [this](grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) { + return stub_->GetEkmConnection(context, request); + }, + request, __func__); +} + +StatusOr +EkmServiceConnectionImpl::CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->CreateEkmConnection(request), + [this]( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) { + return stub_->CreateEkmConnection(context, request); + }, + request, __func__); +} + +StatusOr +EkmServiceConnectionImpl::UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->UpdateEkmConnection(request), + [this]( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) { + return stub_->UpdateEkmConnection(context, request); + }, + request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/internal/ekm_connection_impl.h b/google/cloud/kms/internal/ekm_connection_impl.h new file mode 100644 index 0000000000000..93add564d727f --- /dev/null +++ b/google/cloud/kms/internal/ekm_connection_impl.h @@ -0,0 +1,102 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_CONNECTION_IMPL_H + +#include "google/cloud/kms/ekm_connection.h" +#include "google/cloud/kms/ekm_connection_idempotency_policy.h" +#include "google/cloud/kms/ekm_options.h" +#include "google/cloud/kms/internal/ekm_retry_traits.h" +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class EkmServiceConnectionImpl : public kms::EkmServiceConnection { + public: + ~EkmServiceConnectionImpl() override = default; + + EkmServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, Options options); + + Options options() override { return options_; } + + StreamRange ListEkmConnections( + google::cloud::kms::v1::ListEkmConnectionsRequest request) override; + + StatusOr GetEkmConnection( + google::cloud::kms::v1::GetEkmConnectionRequest const& request) override; + + StatusOr CreateEkmConnection( + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) + override; + + StatusOr UpdateEkmConnection( + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) + override; + + private: + std::unique_ptr retry_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has()) { + return options.get()->clone(); + } + return options_.get()->clone(); + } + + std::unique_ptr backoff_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has()) { + return options.get()->clone(); + } + return options_.get()->clone(); + } + + std::unique_ptr + idempotency_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has()) { + return options.get() + ->clone(); + } + return options_.get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_CONNECTION_IMPL_H diff --git a/google/cloud/kms/internal/ekm_logging_decorator.cc b/google/cloud/kms/internal/ekm_logging_decorator.cc new file mode 100644 index 0000000000000..7e865789d9979 --- /dev/null +++ b/google/cloud/kms/internal/ekm_logging_decorator.cc @@ -0,0 +1,90 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/internal/ekm_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +EkmServiceLogging::EkmServiceLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components) + : child_(std::move(child)), + tracing_options_(std::move(tracing_options)), + components_(std::move(components)) {} + +StatusOr +EkmServiceLogging::ListEkmConnections( + grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& request) { + return child_->ListEkmConnections(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +EkmServiceLogging::GetEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) { + return child_->GetEkmConnection(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +EkmServiceLogging::CreateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) { + return child_->CreateEkmConnection(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +EkmServiceLogging::UpdateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) { + return child_->UpdateEkmConnection(context, request); + }, + context, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/internal/ekm_logging_decorator.h b/google/cloud/kms/internal/ekm_logging_decorator.h new file mode 100644 index 0000000000000..904d617ea1022 --- /dev/null +++ b/google/cloud/kms/internal/ekm_logging_decorator.h @@ -0,0 +1,71 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_LOGGING_DECORATOR_H + +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class EkmServiceLogging : public EkmServiceStub { + public: + ~EkmServiceLogging() override = default; + EkmServiceLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr + ListEkmConnections(grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& + request) override; + + StatusOr GetEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) override; + + StatusOr CreateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) + override; + + StatusOr UpdateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) + override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; // EkmServiceLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_LOGGING_DECORATOR_H diff --git a/google/cloud/kms/internal/ekm_metadata_decorator.cc b/google/cloud/kms/internal/ekm_metadata_decorator.cc new file mode 100644 index 0000000000000..777859b78bf06 --- /dev/null +++ b/google/cloud/kms/internal/ekm_metadata_decorator.cc @@ -0,0 +1,90 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/internal/ekm_metadata_decorator.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +EkmServiceMetadata::EkmServiceMetadata(std::shared_ptr child) + : child_(std::move(child)), + api_client_header_( + google::cloud::internal::ApiClientHeader("generator")) {} + +StatusOr +EkmServiceMetadata::ListEkmConnections( + grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& request) { + SetMetadata(context, "parent=" + request.parent()); + return child_->ListEkmConnections(context, request); +} + +StatusOr +EkmServiceMetadata::GetEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) { + SetMetadata(context, "name=" + request.name()); + return child_->GetEkmConnection(context, request); +} + +StatusOr +EkmServiceMetadata::CreateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) { + SetMetadata(context, "parent=" + request.parent()); + return child_->CreateEkmConnection(context, request); +} + +StatusOr +EkmServiceMetadata::UpdateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) { + SetMetadata(context, + "ekm_connection.name=" + request.ekm_connection().name()); + return child_->UpdateEkmConnection(context, request); +} + +void EkmServiceMetadata::SetMetadata(grpc::ClientContext& context, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context); +} + +void EkmServiceMetadata::SetMetadata(grpc::ClientContext& context) { + context.AddMetadata("x-goog-api-client", api_client_header_); + auto const& options = internal::CurrentOptions(); + if (options.has()) { + context.AddMetadata("x-goog-user-project", + options.get()); + } + if (options.has()) { + context.set_authority(options.get()); + } +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/internal/ekm_metadata_decorator.h b/google/cloud/kms/internal/ekm_metadata_decorator.h new file mode 100644 index 0000000000000..b90759365b09e --- /dev/null +++ b/google/cloud/kms/internal/ekm_metadata_decorator.h @@ -0,0 +1,70 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_METADATA_DECORATOR_H + +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class EkmServiceMetadata : public EkmServiceStub { + public: + ~EkmServiceMetadata() override = default; + explicit EkmServiceMetadata(std::shared_ptr child); + + StatusOr + ListEkmConnections(grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& + request) override; + + StatusOr GetEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) override; + + StatusOr CreateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) + override; + + StatusOr UpdateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) + override; + + private: + void SetMetadata(grpc::ClientContext& context, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_METADATA_DECORATOR_H diff --git a/google/cloud/kms/internal/ekm_option_defaults.cc b/google/cloud/kms/internal/ekm_option_defaults.cc new file mode 100644 index 0000000000000..c076c4a5629ef --- /dev/null +++ b/google/cloud/kms/internal/ekm_option_defaults.cc @@ -0,0 +1,63 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/internal/ekm_option_defaults.h" +#include "google/cloud/kms/ekm_connection.h" +#include "google/cloud/kms/ekm_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options EkmServiceDefaultOptions(Options options) { + options = google::cloud::internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_EKM_SERVICE_ENDPOINT", "", + "cloudkms.googleapis.com"); + options = + google::cloud::internal::PopulateGrpcOptions(std::move(options), ""); + if (!options.has()) { + options.set( + kms::EkmServiceLimitedTimeRetryPolicy(std::chrono::minutes(30)) + .clone()); + } + if (!options.has()) { + options.set( + ExponentialBackoffPolicy(std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling) + .clone()); + } + if (!options.has()) { + options.set( + kms::MakeDefaultEkmServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/internal/ekm_option_defaults.h b/google/cloud/kms/internal/ekm_option_defaults.h new file mode 100644 index 0000000000000..9bf93694a054d --- /dev/null +++ b/google/cloud/kms/internal/ekm_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options EkmServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_OPTION_DEFAULTS_H diff --git a/google/cloud/kms/internal/ekm_retry_traits.h b/google/cloud/kms/internal/ekm_retry_traits.h new file mode 100644 index 0000000000000..f48b1beec29bc --- /dev/null +++ b/google/cloud/kms/internal/ekm_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct EkmServiceRetryTraits { + static inline bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_RETRY_TRAITS_H diff --git a/google/cloud/kms/internal/ekm_stub.cc b/google/cloud/kms/internal/ekm_stub.cc new file mode 100644 index 0000000000000..c3bb96cde67ac --- /dev/null +++ b/google/cloud/kms/internal/ekm_stub.cc @@ -0,0 +1,87 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +EkmServiceStub::~EkmServiceStub() = default; + +StatusOr +DefaultEkmServiceStub::ListEkmConnections( + grpc::ClientContext& client_context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& request) { + google::cloud::kms::v1::ListEkmConnectionsResponse response; + auto status = + grpc_stub_->ListEkmConnections(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultEkmServiceStub::GetEkmConnection( + grpc::ClientContext& client_context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) { + google::cloud::kms::v1::EkmConnection response; + auto status = + grpc_stub_->GetEkmConnection(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultEkmServiceStub::CreateEkmConnection( + grpc::ClientContext& client_context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) { + google::cloud::kms::v1::EkmConnection response; + auto status = + grpc_stub_->CreateEkmConnection(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultEkmServiceStub::UpdateEkmConnection( + grpc::ClientContext& client_context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) { + google::cloud::kms::v1::EkmConnection response; + auto status = + grpc_stub_->UpdateEkmConnection(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/internal/ekm_stub.h b/google/cloud/kms/internal/ekm_stub.h new file mode 100644 index 0000000000000..387c4a6fd4f4e --- /dev/null +++ b/google/cloud/kms/internal/ekm_stub.h @@ -0,0 +1,89 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_STUB_H + +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class EkmServiceStub { + public: + virtual ~EkmServiceStub() = 0; + + virtual StatusOr + ListEkmConnections( + grpc::ClientContext& context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& request) = 0; + + virtual StatusOr GetEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) = 0; + + virtual StatusOr CreateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) = 0; + + virtual StatusOr UpdateEkmConnection( + grpc::ClientContext& context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) = 0; +}; + +class DefaultEkmServiceStub : public EkmServiceStub { + public: + explicit DefaultEkmServiceStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr + ListEkmConnections(grpc::ClientContext& client_context, + google::cloud::kms::v1::ListEkmConnectionsRequest const& + request) override; + + StatusOr GetEkmConnection( + grpc::ClientContext& client_context, + google::cloud::kms::v1::GetEkmConnectionRequest const& request) override; + + StatusOr CreateEkmConnection( + grpc::ClientContext& client_context, + google::cloud::kms::v1::CreateEkmConnectionRequest const& request) + override; + + StatusOr UpdateEkmConnection( + grpc::ClientContext& client_context, + google::cloud::kms::v1::UpdateEkmConnectionRequest const& request) + override; + + private: + std::unique_ptr grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_STUB_H diff --git a/google/cloud/kms/internal/ekm_stub_factory.cc b/google/cloud/kms/internal/ekm_stub_factory.cc new file mode 100644 index 0000000000000..99c75c688f219 --- /dev/null +++ b/google/cloud/kms/internal/ekm_stub_factory.cc @@ -0,0 +1,63 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#include "google/cloud/kms/internal/ekm_stub_factory.h" +#include "google/cloud/kms/internal/ekm_auth_decorator.h" +#include "google/cloud/kms/internal/ekm_logging_decorator.h" +#include "google/cloud/kms/internal/ekm_metadata_decorator.h" +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultEkmServiceStub( + google::cloud::CompletionQueue cq, Options const& options) { + auto auth = google::cloud::internal::CreateAuthenticationStrategy( + std::move(cq), options); + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = google::cloud::kms::v1::EkmService::NewStub(channel); + std::shared_ptr stub = + std::make_shared(std::move(service_grpc_stub)); + + if (auth->RequiresConfigureContext()) { + stub = std::make_shared(std::move(auth), std::move(stub)); + } + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for gRPC calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/internal/ekm_stub_factory.h b/google/cloud/kms/internal/ekm_stub_factory.h new file mode 100644 index 0000000000000..97dab2efb4ece --- /dev/null +++ b/google/cloud/kms/internal/ekm_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_STUB_FACTORY_H + +#include "google/cloud/kms/internal/ekm_stub.h" +#include "google/cloud/completion_queue.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace kms_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultEkmServiceStub( + google::cloud::CompletionQueue cq, Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INTERNAL_EKM_STUB_FACTORY_H diff --git a/google/cloud/kms/mocks/mock_ekm_connection.h b/google/cloud/kms/mocks/mock_ekm_connection.h new file mode 100644 index 0000000000000..f5e02be6436cd --- /dev/null +++ b/google/cloud/kms/mocks/mock_ekm_connection.h @@ -0,0 +1,59 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/kms/v1/ekm_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_MOCKS_MOCK_EKM_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_MOCKS_MOCK_EKM_CONNECTION_H + +#include "google/cloud/kms/ekm_connection.h" +#include + +namespace google { +namespace cloud { +namespace kms_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class MockEkmServiceConnection : public kms::EkmServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StreamRange, + ListEkmConnections, + (google::cloud::kms::v1::ListEkmConnectionsRequest request), + (override)); + + MOCK_METHOD(StatusOr, GetEkmConnection, + (google::cloud::kms::v1::GetEkmConnectionRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, CreateEkmConnection, + (google::cloud::kms::v1::CreateEkmConnectionRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateEkmConnection, + (google::cloud::kms::v1::UpdateEkmConnectionRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_MOCKS_MOCK_EKM_CONNECTION_H From 8dc851a0578d16336174cdd00b1a279799891eaa Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 10 Mar 2022 18:11:41 +0000 Subject: [PATCH 3/3] Address review comments --- CHANGELOG.md | 6 ++++++ google/cloud/kms/doc/main.dox | 3 +++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b41e37286a631..22ec5e6a6f04a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,12 @@ https://github.com/googleapis/google-cloud-cpp/issues/8234. ## v1.39.0 - TBD +### [KMS](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/kms/README.md) + +The library has been expanded to include the following services: + +* [External Key Manager](https://cloud.google.com/kms/docs/ekm) + ## v1.38.0 - 2022-03 ### [Service Management API](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/servicemanagement/README.md) diff --git a/google/cloud/kms/doc/main.dox b/google/cloud/kms/doc/main.dox index 81c991d4d7563..7506fe2f8ac27 100644 --- a/google/cloud/kms/doc/main.dox +++ b/google/cloud/kms/doc/main.dox @@ -41,6 +41,9 @@ which should give you a taste of the KMS C++ client library API. ## Environment Variables +- `GOOGLE_CLOUD_CPP_EKM_SERVICE_ENDPOINT=...` changes the default endpoint + (cloudkms.googleapis.com) used by `EkmServiceConnection`. + - `GOOGLE_CLOUD_CPP_KEY_MANAGEMENT_SERVICE_ENDPOINT=...` changes the default endpoint (cloudkms.googleapis.com) used by `KeyManagementServiceConnection`.