diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca94234b407..f31183d899ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,6 +126,10 @@ the APIs in these libraries are stable, and are ready for production use. - [Advisory Notifications](/google/cloud/advisorynotifications/README.md) - [API Keys](/google/cloud/apikeys/README.md) +### [KMS](/google/cloud/kms/README.md) + +The library has been expanded to include the KMS Inventory API. + ### [TPU](/google/cloud/tpu/README.md) The library has been expanded to include the TPU v2 API. diff --git a/ci/etc/expected_install_directories b/ci/etc/expected_install_directories index a34abaaebc61..1da214add24f 100644 --- a/ci/etc/expected_install_directories +++ b/ci/etc/expected_install_directories @@ -296,6 +296,10 @@ ./include/google/cloud/iot/v1/internal ./include/google/cloud/iot/v1/mocks ./include/google/cloud/kms +./include/google/cloud/kms/inventory +./include/google/cloud/kms/inventory/v1 +./include/google/cloud/kms/inventory/v1/internal +./include/google/cloud/kms/inventory/v1/mocks ./include/google/cloud/kms/mocks ./include/google/cloud/kms/v1 ./include/google/cloud/kms/v1/internal diff --git a/cmake/CompileProtos.cmake b/cmake/CompileProtos.cmake index 0bf89deaf91c..9f1230094fbf 100644 --- a/cmake/CompileProtos.cmake +++ b/cmake/CompileProtos.cmake @@ -270,6 +270,7 @@ function (google_cloud_cpp_load_protodeps var file) # Omit a target from deps. set(targets_to_omit + "google-cloud-cpp::cloud_kms_v1_kms_protos" "google-cloud-cpp::cloud_orgpolicy_v1_orgpolicy_protos" "google-cloud-cpp::cloud_oslogin_common_common_protos" "google-cloud-cpp::cloud_recommender_v1_recommender_protos" diff --git a/external/googleapis/protodeps/kms.deps b/external/googleapis/protodeps/kms.deps index 2e749051efbb..47cb1717591e 100644 --- a/external/googleapis/protodeps/kms.deps +++ b/external/googleapis/protodeps/kms.deps @@ -4,3 +4,4 @@ @com_google_googleapis//google/api:http_proto @com_google_googleapis//google/api:launch_stage_proto @com_google_googleapis//google/api:resource_proto +@com_google_googleapis//google/cloud/kms/v1:kms_proto diff --git a/external/googleapis/protolists/kms.list b/external/googleapis/protolists/kms.list index 74e1de4d9d01..3d4bb75155e2 100644 --- a/external/googleapis/protolists/kms.list +++ b/external/googleapis/protolists/kms.list @@ -1,3 +1,5 @@ +@com_google_googleapis//google/cloud/kms/inventory/v1:key_dashboard_service.proto +@com_google_googleapis//google/cloud/kms/inventory/v1:key_tracking_service.proto @com_google_googleapis//google/cloud/kms/v1:ekm_service.proto @com_google_googleapis//google/cloud/kms/v1:resources.proto @com_google_googleapis//google/cloud/kms/v1:service.proto diff --git a/external/googleapis/update_libraries.sh b/external/googleapis/update_libraries.sh index a0eb404037b0..49f61d1612c4 100755 --- a/external/googleapis/update_libraries.sh +++ b/external/googleapis/update_libraries.sh @@ -133,7 +133,11 @@ declare -A -r LIBRARIES=( ["iap"]="@com_google_googleapis//google/cloud/iap/v1:iap_cc_grpc" ["ids"]="@com_google_googleapis//google/cloud/ids/v1:ids_cc_grpc" ["iot"]="@com_google_googleapis//google/cloud/iot/v1:iot_cc_grpc" - ["kms"]="@com_google_googleapis//google/cloud/kms/v1:kms_cc_grpc" + ["kms"]="$( + printf ",%s" \ + "@com_google_googleapis//google/cloud/kms/v1:kms_cc_grpc" \ + "@com_google_googleapis//google/cloud/kms/inventory/v1:inventory_cc_grpc" + )" ["language"]="@com_google_googleapis//google/cloud/language/v1:language_cc_grpc" ["logging_type"]="@com_google_googleapis//google/logging/type:type_cc_grpc" ["logging"]="@com_google_googleapis//google/logging/v2:logging_cc_grpc" diff --git a/generator/generator_config.textproto b/generator/generator_config.textproto index 74d7dd64ed78..b2d27930d289 100644 --- a/generator/generator_config.textproto +++ b/generator/generator_config.textproto @@ -1086,6 +1086,20 @@ service { retryable_status_codes: ["kUnavailable"] } +service { + service_proto_path: "google/cloud/kms/inventory/v1/key_dashboard_service.proto" + product_path: "google/cloud/kms/inventory/v1" + initial_copyright_year: "2023" + retryable_status_codes: ["kUnavailable"] +} + +service { + service_proto_path: "google/cloud/kms/inventory/v1/key_tracking_service.proto" + product_path: "google/cloud/kms/inventory/v1" + initial_copyright_year: "2023" + retryable_status_codes: ["kUnavailable"] +} + # Language service { service_proto_path: "google/cloud/language/v1/language_service.proto" diff --git a/google/cloud/kms/BUILD.bazel b/google/cloud/kms/BUILD.bazel index 0019c98a9b8d..a13fb257f0df 100644 --- a/google/cloud/kms/BUILD.bazel +++ b/google/cloud/kms/BUILD.bazel @@ -18,6 +18,7 @@ licenses(["notice"]) # Apache 2.0 service_dirs = [ "", + "inventory/v1/", "v1/", ] @@ -46,6 +47,7 @@ cc_library( deps = [ "//:common", "//:grpc_utils", + "@com_google_googleapis//google/cloud/kms/inventory/v1:inventory_cc_grpc", "@com_google_googleapis//google/cloud/kms/v1:kms_cc_grpc", ], ) diff --git a/google/cloud/kms/CMakeLists.txt b/google/cloud/kms/CMakeLists.txt index 41f1cbab68d0..e75f70cd7516 100644 --- a/google/cloud/kms/CMakeLists.txt +++ b/google/cloud/kms/CMakeLists.txt @@ -24,7 +24,7 @@ set(DOXYGEN_EXAMPLE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/quickstart") unset(mocks_globs) unset(source_globs) -set(service_dirs "" "v1/") +set(service_dirs "" "inventory/v1/" "v1/") foreach (dir IN LISTS service_dirs) string(REPLACE "/" "_" ns "${dir}") list(APPEND source_globs "${dir}*.h" "${dir}*.cc" "${dir}internal/*") diff --git a/google/cloud/kms/doc/main.dox b/google/cloud/kms/doc/main.dox index b06ce297f3ae..66b6c6b7b263 100644 --- a/google/cloud/kms/doc/main.dox +++ b/google/cloud/kms/doc/main.dox @@ -49,10 +49,18 @@ which should give you a taste of the KMS C++ client library API. `EndpointOption` (which defaults to "cloudkms.googleapis.com") used by `MakeEkmServiceConnection()`. +- `GOOGLE_CLOUD_CPP_KEY_DASHBOARD_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "kmsinventory.googleapis.com") + used by `MakeKeyDashboardServiceConnection()`. + - `GOOGLE_CLOUD_CPP_KEY_MANAGEMENT_SERVICE_ENDPOINT=...` overrides the `EndpointOption` (which defaults to "cloudkms.googleapis.com") used by `MakeKeyManagementServiceConnection()`. +- `GOOGLE_CLOUD_CPP_KEY_TRACKING_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "kmsinventory.googleapis.com") + used by `MakeKeyTrackingServiceConnection()`. + - `GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc` turns on tracing for most gRPC @@ -100,11 +108,13 @@ library. Use the `google::cloud::EndpointOption` when initializing the client library to change this default. -For example, this will override the default endpoint for `kms_v1::EkmServiceClient`: +For example, this will override the default endpoint for `kms_inventory_v1::KeyDashboardServiceClient`: -@snippet ekm_client_samples.cc set-client-endpoint +@snippet key_dashboard_client_samples.cc set-client-endpoint Follow these links to find examples for other \c *Client classes: + [kms_inventory_v1::KeyDashboardServiceClient](@ref kms_inventory_v1::KeyDashboardServiceClient-endpoint-snippet) + [kms_inventory_v1::KeyTrackingServiceClient](@ref kms_inventory_v1::KeyTrackingServiceClient-endpoint-snippet) [kms_v1::EkmServiceClient](@ref kms_v1::EkmServiceClient-endpoint-snippet) [kms_v1::KeyManagementServiceClient](@ref kms_v1::KeyManagementServiceClient-endpoint-snippet) @@ -118,9 +128,11 @@ Some applications cannot use the default authentication mechanism (known as to explicitly load a service account key file. -@snippet ekm_client_samples.cc with-service-account +@snippet key_dashboard_client_samples.cc with-service-account Follow these links to find examples for other \c *Client classes: + [kms_inventory_v1::KeyDashboardServiceClient](@ref kms_inventory_v1::KeyDashboardServiceClient-service-account-snippet) + [kms_inventory_v1::KeyTrackingServiceClient](@ref kms_inventory_v1::KeyTrackingServiceClient-service-account-snippet) [kms_v1::EkmServiceClient](@ref kms_v1::EkmServiceClient-service-account-snippet) [kms_v1::KeyManagementServiceClient](@ref kms_v1::KeyManagementServiceClient-service-account-snippet) @@ -152,6 +164,30 @@ can override the default policies. // +/*! @page kms_inventory_v1::KeyDashboardServiceClient-endpoint-snippet Override kms_inventory_v1::KeyDashboardServiceClient Endpoint Configuration + +@snippet google/cloud/kms/inventory/v1/samples/key_dashboard_client_samples.cc set-client-endpoint + +*/ + +/*! @page kms_inventory_v1::KeyDashboardServiceClient-service-account-snippet Override kms_inventory_v1::KeyDashboardServiceClient Authentication Defaults + +@snippet google/cloud/kms/inventory/v1/samples/key_dashboard_client_samples.cc with-service-account + +*/ + +/*! @page kms_inventory_v1::KeyTrackingServiceClient-endpoint-snippet Override kms_inventory_v1::KeyTrackingServiceClient Endpoint Configuration + +@snippet google/cloud/kms/inventory/v1/samples/key_tracking_client_samples.cc set-client-endpoint + +*/ + +/*! @page kms_inventory_v1::KeyTrackingServiceClient-service-account-snippet Override kms_inventory_v1::KeyTrackingServiceClient Authentication Defaults + +@snippet google/cloud/kms/inventory/v1/samples/key_tracking_client_samples.cc with-service-account + +*/ + /*! @page kms_v1::EkmServiceClient-endpoint-snippet Override kms_v1::EkmServiceClient Endpoint Configuration @snippet google/cloud/kms/v1/samples/ekm_client_samples.cc set-client-endpoint diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.cc new file mode 100644 index 000000000000..166c10060c68 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.cc @@ -0,0 +1,45 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyDashboardServiceAuth::KeyDashboardServiceAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +KeyDashboardServiceAuth::ListCryptoKeys( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListCryptoKeys(context, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.h new file mode 100644 index 000000000000..2c670954480d --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.h @@ -0,0 +1,56 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_AUTH_DECORATOR_H + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyDashboardServiceAuth : public KeyDashboardServiceStub { + public: + ~KeyDashboardServiceAuth() override = default; + KeyDashboardServiceAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr + ListCryptoKeys(grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& + request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_AUTH_DECORATOR_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.cc new file mode 100644 index 000000000000..e4a3c90961d3 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.cc @@ -0,0 +1,78 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyDashboardServiceConnectionImpl::KeyDashboardServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions( + std::move(options), KeyDashboardServiceConnection::options())) {} + +StreamRange +KeyDashboardServiceConnectionImpl::ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest 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()->ListCryptoKeys(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + std::move(request), + [stub, retry, backoff, idempotency, function_name]( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub]( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& + request) { return stub->ListCryptoKeys(context, request); }, + r, function_name); + }, + [](google::cloud::kms::inventory::v1::ListCryptoKeysResponse r) { + std::vector result( + r.crypto_keys().size()); + auto& messages = *r.mutable_crypto_keys(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.h new file mode 100644 index 000000000000..5fd683af0c3a --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.h @@ -0,0 +1,111 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_CONNECTION_IMPL_H + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_retry_traits.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_connection.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_options.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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyDashboardServiceConnectionImpl + : public kms_inventory_v1::KeyDashboardServiceConnection { + public: + ~KeyDashboardServiceConnectionImpl() override = default; + + KeyDashboardServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StreamRange ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest 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< + kms_inventory_v1::KeyDashboardServiceConnectionIdempotencyPolicy> + 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_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_CONNECTION_IMPL_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.cc new file mode 100644 index 000000000000..46b9668261f4 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.cc @@ -0,0 +1,51 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyDashboardServiceLogging::KeyDashboardServiceLogging( + 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 +KeyDashboardServiceLogging::ListCryptoKeys( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& + request) { return child_->ListCryptoKeys(context, request); }, + context, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.h new file mode 100644 index 000000000000..dc533712627a --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.h @@ -0,0 +1,57 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_LOGGING_DECORATOR_H + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyDashboardServiceLogging : public KeyDashboardServiceStub { + public: + ~KeyDashboardServiceLogging() override = default; + KeyDashboardServiceLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr + ListCryptoKeys(grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& + request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; // KeyDashboardServiceLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_LOGGING_DECORATOR_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_metadata_decorator.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_metadata_decorator.cc new file mode 100644 index 000000000000..d3827c8c09bf --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_metadata_decorator.cc @@ -0,0 +1,65 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyDashboardServiceMetadata::KeyDashboardServiceMetadata( + std::shared_ptr child) + : child_(std::move(child)), + api_client_header_( + google::cloud::internal::ApiClientHeader("generator")) {} + +StatusOr +KeyDashboardServiceMetadata::ListCryptoKeys( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& request) { + SetMetadata(context, "parent=" + request.parent()); + return child_->ListCryptoKeys(context, request); +} + +void KeyDashboardServiceMetadata::SetMetadata( + grpc::ClientContext& context, std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context); +} + +void KeyDashboardServiceMetadata::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()); + } + auto const& authority = options.get(); + if (!authority.empty()) context.set_authority(authority); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_metadata_decorator.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_metadata_decorator.h new file mode 100644 index 000000000000..0a1882f83094 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_metadata_decorator.h @@ -0,0 +1,57 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_METADATA_DECORATOR_H + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyDashboardServiceMetadata : public KeyDashboardServiceStub { + public: + ~KeyDashboardServiceMetadata() override = default; + explicit KeyDashboardServiceMetadata( + std::shared_ptr child); + + StatusOr + ListCryptoKeys(grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest 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_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_METADATA_DECORATOR_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.cc new file mode 100644 index 000000000000..19571b292b8c --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.cc @@ -0,0 +1,70 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_connection.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options KeyDashboardServiceDefaultOptions(Options options) { + options = google::cloud::internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_KEY_DASHBOARD_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_KEY_DASHBOARD_SERVICE_AUTHORITY", + "kmsinventory.googleapis.com"); + options = + google::cloud::internal::PopulateGrpcOptions(std::move(options), ""); + if (!options.has()) { + options.set( + kms_inventory_v1::KeyDashboardServiceLimitedTimeRetryPolicy( + 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_inventory_v1::KeyDashboardServiceConnectionIdempotencyPolicyOption>( + kms_inventory_v1:: + MakeDefaultKeyDashboardServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.h new file mode 100644 index 000000000000..c1618cf712f3 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options KeyDashboardServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_OPTION_DEFAULTS_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_retry_traits.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_retry_traits.h new file mode 100644 index 000000000000..e29be77e8b99 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct KeyDashboardServiceRetryTraits { + 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_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_RETRY_TRAITS_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_stub.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub.cc new file mode 100644 index 000000000000..92ee35fdce07 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub.cc @@ -0,0 +1,47 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyDashboardServiceStub::~KeyDashboardServiceStub() = default; + +StatusOr +DefaultKeyDashboardServiceStub::ListCryptoKeys( + grpc::ClientContext& client_context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& request) { + google::cloud::kms::inventory::v1::ListCryptoKeysResponse response; + auto status = grpc_stub_->ListCryptoKeys(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h new file mode 100644 index 000000000000..e69a33f3bf04 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h @@ -0,0 +1,66 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_STUB_H + +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyDashboardServiceStub { + public: + virtual ~KeyDashboardServiceStub() = 0; + + virtual StatusOr + ListCryptoKeys(grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& + request) = 0; +}; + +class DefaultKeyDashboardServiceStub : public KeyDashboardServiceStub { + public: + explicit DefaultKeyDashboardServiceStub( + std::unique_ptr< + google::cloud::kms::inventory::v1::KeyDashboardService::StubInterface> + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr + ListCryptoKeys(grpc::ClientContext& client_context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& + request) override; + + private: + std::unique_ptr< + google::cloud::kms::inventory::v1::KeyDashboardService::StubInterface> + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_STUB_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.cc new file mode 100644 index 000000000000..f369c36fefa3 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.cc @@ -0,0 +1,71 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_auth_decorator.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_logging_decorator.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_metadata_decorator.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultKeyDashboardServiceStub( + 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::inventory::v1::KeyDashboardService::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()); + } + if (internal::TracingEnabled(options)) { + stub = MakeKeyDashboardServiceTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.h new file mode 100644 index 000000000000..7b8c5e30fa45 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_STUB_FACTORY_H + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultKeyDashboardServiceStub( + google::cloud::CompletionQueue cq, Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_STUB_FACTORY_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.cc new file mode 100644 index 000000000000..baada7a8a56c --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.cc @@ -0,0 +1,63 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +KeyDashboardServiceTracingConnection::KeyDashboardServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StreamRange +KeyDashboardServiceTracingConnection::ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest request) { + auto span = internal::MakeSpan( + "kms_inventory_v1::KeyDashboardServiceConnection::ListCryptoKeys"); + auto scope = opentelemetry::trace::Scope(span); + auto sr = child_->ListCryptoKeys(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeKeyDashboardServiceTracingConnection( + std::shared_ptr conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = + std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.h new file mode 100644 index 000000000000..38f943c238a3 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.h @@ -0,0 +1,68 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_TRACING_CONNECTION_H + +#include "google/cloud/kms/inventory/v1/key_dashboard_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class KeyDashboardServiceTracingConnection + : public kms_inventory_v1::KeyDashboardServiceConnection { + public: + ~KeyDashboardServiceTracingConnection() override = default; + + explicit KeyDashboardServiceTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StreamRange ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest request) + override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeKeyDashboardServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_TRACING_CONNECTION_H diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.cc b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.cc new file mode 100644 index 000000000000..d6f543046338 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.cc @@ -0,0 +1,59 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +KeyDashboardServiceTracingStub::KeyDashboardServiceTracingStub( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +KeyDashboardServiceTracingStub::ListCryptoKeys( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.kms.inventory.v1.KeyDashboardService", "ListCryptoKeys"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, internal::CurrentOptions()); + return internal::EndSpan(context, *span, + child_->ListCryptoKeys(context, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeKeyDashboardServiceTracingStub( + std::shared_ptr stub) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return std::make_shared(std::move(stub)); +#else + return stub; +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.h b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.h new file mode 100644 index 000000000000..13f0d916259c --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_stub.h @@ -0,0 +1,65 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_TRACING_STUB_H + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class KeyDashboardServiceTracingStub : public KeyDashboardServiceStub { + public: + ~KeyDashboardServiceTracingStub() override = default; + + explicit KeyDashboardServiceTracingStub( + std::shared_ptr child); + + StatusOr + ListCryptoKeys(grpc::ClientContext& context, + google::cloud::kms::inventory::v1::ListCryptoKeysRequest const& + request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Applies the tracing decorator to the given stub. + * + * The stub is only decorated if the library has been compiled with + * OpenTelemetry. + */ +std::shared_ptr MakeKeyDashboardServiceTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_DASHBOARD_TRACING_STUB_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.cc new file mode 100644 index 000000000000..8d49b95a07f6 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.cc @@ -0,0 +1,56 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyTrackingServiceAuth::KeyTrackingServiceAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +KeyTrackingServiceAuth::GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetProtectedResourcesSummary(context, request); +} + +StatusOr +KeyTrackingServiceAuth::SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->SearchProtectedResources(context, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.h b/google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.h new file mode 100644 index 000000000000..899245bd0aa4 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.h @@ -0,0 +1,63 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_AUTH_DECORATOR_H + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyTrackingServiceAuth : public KeyTrackingServiceStub { + public: + ~KeyTrackingServiceAuth() override = default; + KeyTrackingServiceAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr + GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) override; + + StatusOr + SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_AUTH_DECORATOR_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.cc new file mode 100644 index 000000000000..2e47201b300d --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.cc @@ -0,0 +1,97 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyTrackingServiceConnectionImpl::KeyTrackingServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions( + std::move(options), KeyTrackingServiceConnection::options())) {} + +StatusOr +KeyTrackingServiceConnectionImpl::GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->GetProtectedResourcesSummary(request), + [this](grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + return stub_->GetProtectedResourcesSummary(context, request); + }, + request, __func__); +} + +StreamRange +KeyTrackingServiceConnectionImpl::SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + 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()->SearchProtectedResources(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + std::move(request), + [stub, retry, backoff, idempotency, + function_name](google::cloud::kms::inventory::v1:: + SearchProtectedResourcesRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + SearchProtectedResourcesRequest const& request) { + return stub->SearchProtectedResources(context, request); + }, + r, function_name); + }, + [](google::cloud::kms::inventory::v1::SearchProtectedResourcesResponse + r) { + std::vector + result(r.protected_resources().size()); + auto& messages = *r.mutable_protected_resources(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.h b/google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.h new file mode 100644 index 000000000000..2cb51ff6e16a --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.h @@ -0,0 +1,117 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_CONNECTION_IMPL_H + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_retry_traits.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/kms/inventory/v1/key_tracking_connection.h" +#include "google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.h" +#include "google/cloud/kms/inventory/v1/key_tracking_options.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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyTrackingServiceConnectionImpl + : public kms_inventory_v1::KeyTrackingServiceConnection { + public: + ~KeyTrackingServiceConnectionImpl() override = default; + + KeyTrackingServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StatusOr + GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) override; + + StreamRange + SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + 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< + kms_inventory_v1::KeyTrackingServiceConnectionIdempotencyPolicy> + 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_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_CONNECTION_IMPL_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.cc new file mode 100644 index 000000000000..00fddfafca86 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.cc @@ -0,0 +1,68 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyTrackingServiceLogging::KeyTrackingServiceLogging( + 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 +KeyTrackingServiceLogging::GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + return child_->GetProtectedResourcesSummary(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +KeyTrackingServiceLogging::SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + SearchProtectedResourcesRequest const& request) { + return child_->SearchProtectedResources(context, request); + }, + context, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.h b/google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.h new file mode 100644 index 000000000000..6a96427f0cbf --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.h @@ -0,0 +1,64 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_LOGGING_DECORATOR_H + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyTrackingServiceLogging : public KeyTrackingServiceStub { + public: + ~KeyTrackingServiceLogging() override = default; + KeyTrackingServiceLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr + GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) override; + + StatusOr + SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; // KeyTrackingServiceLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_LOGGING_DECORATOR_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_metadata_decorator.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_metadata_decorator.cc new file mode 100644 index 000000000000..64f760841de5 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_metadata_decorator.cc @@ -0,0 +1,75 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyTrackingServiceMetadata::KeyTrackingServiceMetadata( + std::shared_ptr child) + : child_(std::move(child)), + api_client_header_( + google::cloud::internal::ApiClientHeader("generator")) {} + +StatusOr +KeyTrackingServiceMetadata::GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + SetMetadata(context, "name=" + request.name()); + return child_->GetProtectedResourcesSummary(context, request); +} + +StatusOr +KeyTrackingServiceMetadata::SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) { + SetMetadata(context, "scope=" + request.scope()); + return child_->SearchProtectedResources(context, request); +} + +void KeyTrackingServiceMetadata::SetMetadata( + grpc::ClientContext& context, std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context); +} + +void KeyTrackingServiceMetadata::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()); + } + auto const& authority = options.get(); + if (!authority.empty()) context.set_authority(authority); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_metadata_decorator.h b/google/cloud/kms/inventory/v1/internal/key_tracking_metadata_decorator.h new file mode 100644 index 000000000000..6a9ed426e7f4 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_metadata_decorator.h @@ -0,0 +1,64 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_METADATA_DECORATOR_H + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyTrackingServiceMetadata : public KeyTrackingServiceStub { + public: + ~KeyTrackingServiceMetadata() override = default; + explicit KeyTrackingServiceMetadata( + std::shared_ptr child); + + StatusOr + GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) override; + + StatusOr + SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest 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_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_METADATA_DECORATOR_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.cc new file mode 100644 index 000000000000..6af8d54d726b --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.cc @@ -0,0 +1,68 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.h" +#include "google/cloud/kms/inventory/v1/key_tracking_connection.h" +#include "google/cloud/kms/inventory/v1/key_tracking_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options KeyTrackingServiceDefaultOptions(Options options) { + options = google::cloud::internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_KEY_TRACKING_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_KEY_TRACKING_SERVICE_AUTHORITY", + "kmsinventory.googleapis.com"); + options = + google::cloud::internal::PopulateGrpcOptions(std::move(options), ""); + if (!options.has()) { + options.set( + kms_inventory_v1::KeyTrackingServiceLimitedTimeRetryPolicy( + 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_inventory_v1::KeyTrackingServiceConnectionIdempotencyPolicyOption>( + kms_inventory_v1:: + MakeDefaultKeyTrackingServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.h b/google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.h new file mode 100644 index 000000000000..5b21e5d41f92 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options KeyTrackingServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_OPTION_DEFAULTS_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_retry_traits.h b/google/cloud/kms/inventory/v1/internal/key_tracking_retry_traits.h new file mode 100644 index 000000000000..30884366c5a0 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct KeyTrackingServiceRetryTraits { + 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_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_RETRY_TRAITS_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_stub.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_stub.cc new file mode 100644 index 000000000000..2901c93b3ebd --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_stub.cc @@ -0,0 +1,63 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyTrackingServiceStub::~KeyTrackingServiceStub() = default; + +StatusOr +DefaultKeyTrackingServiceStub::GetProtectedResourcesSummary( + grpc::ClientContext& client_context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + google::cloud::kms::inventory::v1::ProtectedResourcesSummary response; + auto status = grpc_stub_->GetProtectedResourcesSummary(&client_context, + request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultKeyTrackingServiceStub::SearchProtectedResources( + grpc::ClientContext& client_context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) { + google::cloud::kms::inventory::v1::SearchProtectedResourcesResponse response; + auto status = + grpc_stub_->SearchProtectedResources(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_stub.h b/google/cloud/kms/inventory/v1/internal/key_tracking_stub.h new file mode 100644 index 000000000000..e2eabfbad19b --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_stub.h @@ -0,0 +1,81 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_STUB_H + +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyTrackingServiceStub { + public: + virtual ~KeyTrackingServiceStub() = 0; + + virtual StatusOr + GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) = 0; + + virtual StatusOr< + google::cloud::kms::inventory::v1::SearchProtectedResourcesResponse> + SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) = 0; +}; + +class DefaultKeyTrackingServiceStub : public KeyTrackingServiceStub { + public: + explicit DefaultKeyTrackingServiceStub( + std::unique_ptr< + google::cloud::kms::inventory::v1::KeyTrackingService::StubInterface> + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr + GetProtectedResourcesSummary( + grpc::ClientContext& client_context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) override; + + StatusOr + SearchProtectedResources( + grpc::ClientContext& client_context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) override; + + private: + std::unique_ptr< + google::cloud::kms::inventory::v1::KeyTrackingService::StubInterface> + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_STUB_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.cc new file mode 100644 index 000000000000..2d86ecf1908a --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.cc @@ -0,0 +1,71 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_auth_decorator.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_logging_decorator.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_metadata_decorator.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultKeyTrackingServiceStub( + 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::inventory::v1::KeyTrackingService::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()); + } + if (internal::TracingEnabled(options)) { + stub = MakeKeyTrackingServiceTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.h b/google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.h new file mode 100644 index 000000000000..2b7da608e40f --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_STUB_FACTORY_H + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_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_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultKeyTrackingServiceStub( + google::cloud::CompletionQueue cq, Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_STUB_FACTORY_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.cc new file mode 100644 index 000000000000..bfa542f042f2 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.cc @@ -0,0 +1,78 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +KeyTrackingServiceTracingConnection::KeyTrackingServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +KeyTrackingServiceTracingConnection::GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + auto span = internal::MakeSpan( + "kms_inventory_v1::KeyTrackingServiceConnection::" + "GetProtectedResourcesSummary"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, + child_->GetProtectedResourcesSummary(request)); +} + +StreamRange +KeyTrackingServiceTracingConnection::SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + request) { + auto span = internal::MakeSpan( + "kms_inventory_v1::KeyTrackingServiceConnection::" + "SearchProtectedResources"); + auto scope = opentelemetry::trace::Scope(span); + auto sr = child_->SearchProtectedResources(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::kms::inventory::v1::ProtectedResource>(std::move(span), + std::move(sr)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeKeyTrackingServiceTracingConnection( + std::shared_ptr conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = + std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.h b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.h new file mode 100644 index 000000000000..cfbd2f896bd2 --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.h @@ -0,0 +1,74 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_TRACING_CONNECTION_H + +#include "google/cloud/kms/inventory/v1/key_tracking_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class KeyTrackingServiceTracingConnection + : public kms_inventory_v1::KeyTrackingServiceConnection { + public: + ~KeyTrackingServiceTracingConnection() override = default; + + explicit KeyTrackingServiceTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr + GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) override; + + StreamRange + SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeKeyTrackingServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_TRACING_CONNECTION_H diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.cc b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.cc new file mode 100644 index 000000000000..caea952e302b --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.cc @@ -0,0 +1,75 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +KeyTrackingServiceTracingStub::KeyTrackingServiceTracingStub( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +KeyTrackingServiceTracingStub::GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.kms.inventory.v1.KeyTrackingService", + "GetProtectedResourcesSummary"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, internal::CurrentOptions()); + return internal::EndSpan( + context, *span, child_->GetProtectedResourcesSummary(context, request)); +} + +StatusOr +KeyTrackingServiceTracingStub::SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) { + auto span = + internal::MakeSpanGrpc("google.cloud.kms.inventory.v1.KeyTrackingService", + "SearchProtectedResources"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, internal::CurrentOptions()); + return internal::EndSpan(context, *span, + child_->SearchProtectedResources(context, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeKeyTrackingServiceTracingStub( + std::shared_ptr stub) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return std::make_shared(std::move(stub)); +#else + return stub; +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.h b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.h new file mode 100644 index 000000000000..091fd383383f --- /dev/null +++ b/google/cloud/kms/inventory/v1/internal/key_tracking_tracing_stub.h @@ -0,0 +1,72 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_TRACING_STUB_H + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace kms_inventory_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class KeyTrackingServiceTracingStub : public KeyTrackingServiceStub { + public: + ~KeyTrackingServiceTracingStub() override = default; + + explicit KeyTrackingServiceTracingStub( + std::shared_ptr child); + + StatusOr + GetProtectedResourcesSummary( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request) override; + + StatusOr + SearchProtectedResources( + grpc::ClientContext& context, + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest const& + request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Applies the tracing decorator to the given stub. + * + * The stub is only decorated if the library has been compiled with + * OpenTelemetry. + */ +std::shared_ptr MakeKeyTrackingServiceTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_INTERNAL_KEY_TRACKING_TRACING_STUB_H diff --git a/google/cloud/kms/inventory/v1/key_dashboard_client.cc b/google/cloud/kms/inventory/v1/key_dashboard_client.cc new file mode 100644 index 000000000000..e8fcbee30703 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_dashboard_client.cc @@ -0,0 +1,54 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/key_dashboard_client.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyDashboardServiceClient::KeyDashboardServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +KeyDashboardServiceClient::~KeyDashboardServiceClient() = default; + +StreamRange +KeyDashboardServiceClient::ListCryptoKeys(std::string const& parent, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::kms::inventory::v1::ListCryptoKeysRequest request; + request.set_parent(parent); + return connection_->ListCryptoKeys(request); +} + +StreamRange +KeyDashboardServiceClient::ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListCryptoKeys(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/key_dashboard_client.h b/google/cloud/kms/inventory/v1/key_dashboard_client.h new file mode 100644 index 000000000000..7c3577524b71 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_dashboard_client.h @@ -0,0 +1,141 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CLIENT_H + +#include "google/cloud/kms/inventory/v1/key_dashboard_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_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// Provides a cross-region view of all Cloud KMS keys in a given Cloud project. +/// +/// @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 KeyDashboardServiceClient { + public: + explicit KeyDashboardServiceClient( + std::shared_ptr connection, + Options opts = {}); + ~KeyDashboardServiceClient(); + + ///@{ + /// @name Copy and move support + KeyDashboardServiceClient(KeyDashboardServiceClient const&) = default; + KeyDashboardServiceClient& operator=(KeyDashboardServiceClient const&) = + default; + KeyDashboardServiceClient(KeyDashboardServiceClient&&) = default; + KeyDashboardServiceClient& operator=(KeyDashboardServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(KeyDashboardServiceClient const& a, + KeyDashboardServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(KeyDashboardServiceClient const& a, + KeyDashboardServiceClient const& b) { + return !(a == b); + } + ///@} + + /// + /// Returns cryptographic keys managed by Cloud KMS in a given Cloud project. + /// Note that this data is sourced from snapshots, meaning it may not + /// completely reflect the actual state of key metadata at call time. + /// + /// @param parent Required. The Google Cloud project for which to retrieve + /// key metadata, in + /// the format `projects/*` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::CryptoKey,google/cloud/kms/v1/resources.proto#L58} + /// + /// [google.cloud.kms.inventory.v1.ListCryptoKeysRequest]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_dashboard_service.proto#L52} + /// [google.cloud.kms.v1.CryptoKey]: + /// @googleapis_reference_link{google/cloud/kms/v1/resources.proto#L58} + /// + StreamRange ListCryptoKeys( + std::string const& parent, Options opts = {}); + + /// + /// Returns cryptographic keys managed by Cloud KMS in a given Cloud project. + /// Note that this data is sourced from snapshots, meaning it may not + /// completely reflect the actual state of key metadata at call time. + /// + /// @param request + /// @googleapis_link{google::cloud::kms::inventory::v1::ListCryptoKeysRequest,google/cloud/kms/inventory/v1/key_dashboard_service.proto#L52} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::v1::CryptoKey,google/cloud/kms/v1/resources.proto#L58} + /// + /// [google.cloud.kms.inventory.v1.ListCryptoKeysRequest]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_dashboard_service.proto#L52} + /// [google.cloud.kms.v1.CryptoKey]: + /// @googleapis_reference_link{google/cloud/kms/v1/resources.proto#L58} + /// + StreamRange ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CLIENT_H diff --git a/google/cloud/kms/inventory/v1/key_dashboard_connection.cc b/google/cloud/kms/inventory/v1/key_dashboard_connection.cc new file mode 100644 index 000000000000..ee88d866c77a --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_dashboard_connection.cc @@ -0,0 +1,67 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/key_dashboard_connection.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_connection_impl.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_option_defaults.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub_factory.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_tracing_connection.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_options.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyDashboardServiceConnection::~KeyDashboardServiceConnection() = default; + +StreamRange +KeyDashboardServiceConnection::ListCryptoKeys( + google::cloud::kms::inventory::v1:: + ListCryptoKeysRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +std::shared_ptr +MakeKeyDashboardServiceConnection(Options options) { + internal::CheckExpectedOptions(options, + __func__); + options = kms_inventory_v1_internal::KeyDashboardServiceDefaultOptions( + std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto stub = kms_inventory_v1_internal::CreateDefaultKeyDashboardServiceStub( + background->cq(), options); + return kms_inventory_v1_internal::MakeKeyDashboardServiceTracingConnection( + std::make_shared< + kms_inventory_v1_internal::KeyDashboardServiceConnectionImpl>( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/key_dashboard_connection.h b/google/cloud/kms/inventory/v1/key_dashboard_connection.h new file mode 100644 index 000000000000..e8e251603882 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_dashboard_connection.h @@ -0,0 +1,102 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CONNECTION_H + +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_retry_traits.h" +#include "google/cloud/kms/inventory/v1/internal/key_dashboard_stub.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.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_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using KeyDashboardServiceRetryPolicy = + ::google::cloud::internal::TraitBasedRetryPolicy< + kms_inventory_v1_internal::KeyDashboardServiceRetryTraits>; + +using KeyDashboardServiceLimitedTimeRetryPolicy = + ::google::cloud::internal::LimitedTimeRetryPolicy< + kms_inventory_v1_internal::KeyDashboardServiceRetryTraits>; + +using KeyDashboardServiceLimitedErrorCountRetryPolicy = + ::google::cloud::internal::LimitedErrorCountRetryPolicy< + kms_inventory_v1_internal::KeyDashboardServiceRetryTraits>; + +/** + * The `KeyDashboardServiceConnection` object for `KeyDashboardServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `KeyDashboardServiceClient`. This allows users to inject custom + * behavior (e.g., with a Google Mock object) when writing tests that use + * objects of type `KeyDashboardServiceClient`. + * + * To create a concrete instance, see `MakeKeyDashboardServiceConnection()`. + * + * For mocking, see `kms_inventory_v1_mocks::MockKeyDashboardServiceConnection`. + */ +class KeyDashboardServiceConnection { + public: + virtual ~KeyDashboardServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StreamRange ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest request); +}; + +/** + * A factory function to construct an object of type + * `KeyDashboardServiceConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of + * KeyDashboardServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `KeyDashboardServiceConnection`. Expected options are any of the + * types in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::kms_inventory_v1::KeyDashboardServicePolicyOptionList` + * + * @note Unexpected options will be ignored. To log unexpected options instead, + * set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment. + * + * @param options (optional) Configure the `KeyDashboardServiceConnection` + * created by this function. + */ +std::shared_ptr +MakeKeyDashboardServiceConnection(Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CONNECTION_H diff --git a/google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.cc b/google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.cc new file mode 100644 index 000000000000..adbefc604f62 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.cc @@ -0,0 +1,52 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.h" +#include "absl/memory/memory.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +KeyDashboardServiceConnectionIdempotencyPolicy:: + ~KeyDashboardServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +KeyDashboardServiceConnectionIdempotencyPolicy::clone() const { + return absl::make_unique( + *this); +} + +Idempotency KeyDashboardServiceConnectionIdempotencyPolicy::ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultKeyDashboardServiceConnectionIdempotencyPolicy() { + return absl::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.h b/google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.h new file mode 100644 index 000000000000..8163ea8d7e2a --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_dashboard_connection_idempotency_policy.h @@ -0,0 +1,53 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_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_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyDashboardServiceConnectionIdempotencyPolicy { + public: + virtual ~KeyDashboardServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr + clone() const; + + virtual google::cloud::Idempotency ListCryptoKeys( + google::cloud::kms::inventory::v1::ListCryptoKeysRequest request); +}; + +std::unique_ptr +MakeDefaultKeyDashboardServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/kms/inventory/v1/key_dashboard_options.h b/google/cloud/kms/inventory/v1/key_dashboard_options.h new file mode 100644 index 000000000000..2a945263e665 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_dashboard_options.h @@ -0,0 +1,76 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_OPTIONS_H + +#include "google/cloud/kms/inventory/v1/key_dashboard_connection.h" +#include "google/cloud/kms/inventory/v1/key_dashboard_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_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-kms-options + */ +struct KeyDashboardServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-kms-options + */ +struct KeyDashboardServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-kms-options + */ +struct KeyDashboardServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to KeyDashboardService. + * + * @ingroup google-cloud-kms-options + */ +using KeyDashboardServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_DASHBOARD_OPTIONS_H diff --git a/google/cloud/kms/inventory/v1/key_tracking_client.cc b/google/cloud/kms/inventory/v1/key_tracking_client.cc new file mode 100644 index 000000000000..573522abeddf --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_tracking_client.cc @@ -0,0 +1,74 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/key_tracking_client.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyTrackingServiceClient::KeyTrackingServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +KeyTrackingServiceClient::~KeyTrackingServiceClient() = default; + +StatusOr +KeyTrackingServiceClient::GetProtectedResourcesSummary(std::string const& name, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::kms::inventory::v1::GetProtectedResourcesSummaryRequest + request; + request.set_name(name); + return connection_->GetProtectedResourcesSummary(request); +} + +StatusOr +KeyTrackingServiceClient::GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetProtectedResourcesSummary(request); +} + +StreamRange +KeyTrackingServiceClient::SearchProtectedResources( + std::string const& scope, std::string const& crypto_key, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest request; + request.set_scope(scope); + request.set_crypto_key(crypto_key); + return connection_->SearchProtectedResources(request); +} + +StreamRange +KeyTrackingServiceClient::SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->SearchProtectedResources(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/key_tracking_client.h b/google/cloud/kms/inventory/v1/key_tracking_client.h new file mode 100644 index 000000000000..0a2e23b98e67 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_tracking_client.h @@ -0,0 +1,194 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CLIENT_H + +#include "google/cloud/kms/inventory/v1/key_tracking_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 +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// Returns information about the resources in an org that are protected by a +/// given Cloud KMS key via CMEK. +/// +/// @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 KeyTrackingServiceClient { + public: + explicit KeyTrackingServiceClient( + std::shared_ptr connection, + Options opts = {}); + ~KeyTrackingServiceClient(); + + ///@{ + /// @name Copy and move support + KeyTrackingServiceClient(KeyTrackingServiceClient const&) = default; + KeyTrackingServiceClient& operator=(KeyTrackingServiceClient const&) = + default; + KeyTrackingServiceClient(KeyTrackingServiceClient&&) = default; + KeyTrackingServiceClient& operator=(KeyTrackingServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(KeyTrackingServiceClient const& a, + KeyTrackingServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(KeyTrackingServiceClient const& a, + KeyTrackingServiceClient const& b) { + return !(a == b); + } + ///@} + + /// + /// Returns aggregate information about the resources protected by the given + /// Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. Only resources + /// within the same Cloud organization as the key will be returned. The + /// project that holds the key must be part of an organization in order for + /// this call to succeed. + /// + /// @param name Required. The resource name of the + /// [CryptoKey][google.cloud.kms.v1.CryptoKey]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::inventory::v1::ProtectedResourcesSummary,google/cloud/kms/inventory/v1/key_tracking_service.proto#L79} + /// + /// [google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L66} + /// [google.cloud.kms.inventory.v1.ProtectedResourcesSummary]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L79} + /// + StatusOr + GetProtectedResourcesSummary(std::string const& name, Options opts = {}); + + /// + /// Returns aggregate information about the resources protected by the given + /// Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. Only resources + /// within the same Cloud organization as the key will be returned. The + /// project that holds the key must be part of an organization in order for + /// this call to succeed. + /// + /// @param request + /// @googleapis_link{google::cloud::kms::inventory::v1::GetProtectedResourcesSummaryRequest,google/cloud/kms/inventory/v1/key_tracking_service.proto#L66} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::inventory::v1::ProtectedResourcesSummary,google/cloud/kms/inventory/v1/key_tracking_service.proto#L79} + /// + /// [google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L66} + /// [google.cloud.kms.inventory.v1.ProtectedResourcesSummary]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L79} + /// + StatusOr + GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request, + Options opts = {}); + + /// + /// Returns metadata about the resources protected by the given Cloud KMS + /// [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud + /// organization. + /// + /// @param scope Required. Resource name of the organization. + /// Example: organizations/123 + /// @param crypto_key Required. The resource name of the + /// [CryptoKey][google.cloud.kms.v1.CryptoKey]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::inventory::v1::ProtectedResource,google/cloud/kms/inventory/v1/key_tracking_service.proto#L156} + /// + /// [google.cloud.kms.inventory.v1.ProtectedResource]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L156} + /// [google.cloud.kms.inventory.v1.SearchProtectedResourcesRequest]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L111} + /// + StreamRange + SearchProtectedResources(std::string const& scope, + std::string const& crypto_key, Options opts = {}); + + /// + /// Returns metadata about the resources protected by the given Cloud KMS + /// [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud + /// organization. + /// + /// @param request + /// @googleapis_link{google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest,google/cloud/kms/inventory/v1/key_tracking_service.proto#L111} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::kms::inventory::v1::ProtectedResource,google/cloud/kms/inventory/v1/key_tracking_service.proto#L156} + /// + /// [google.cloud.kms.inventory.v1.ProtectedResource]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L156} + /// [google.cloud.kms.inventory.v1.SearchProtectedResourcesRequest]: + /// @googleapis_reference_link{google/cloud/kms/inventory/v1/key_tracking_service.proto#L111} + /// + StreamRange + SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CLIENT_H diff --git a/google/cloud/kms/inventory/v1/key_tracking_connection.cc b/google/cloud/kms/inventory/v1/key_tracking_connection.cc new file mode 100644 index 000000000000..b882970fec99 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_tracking_connection.cc @@ -0,0 +1,74 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/key_tracking_connection.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_connection_impl.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_option_defaults.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub_factory.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_tracing_connection.h" +#include "google/cloud/kms/inventory/v1/key_tracking_options.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +KeyTrackingServiceConnection::~KeyTrackingServiceConnection() = default; + +StatusOr +KeyTrackingServiceConnection::GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +KeyTrackingServiceConnection::SearchProtectedResources( + google::cloud::kms::inventory::v1:: + SearchProtectedResourcesRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +std::shared_ptr MakeKeyTrackingServiceConnection( + Options options) { + internal::CheckExpectedOptions(options, + __func__); + options = kms_inventory_v1_internal::KeyTrackingServiceDefaultOptions( + std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto stub = kms_inventory_v1_internal::CreateDefaultKeyTrackingServiceStub( + background->cq(), options); + return kms_inventory_v1_internal::MakeKeyTrackingServiceTracingConnection( + std::make_shared< + kms_inventory_v1_internal::KeyTrackingServiceConnectionImpl>( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/key_tracking_connection.h b/google/cloud/kms/inventory/v1/key_tracking_connection.h new file mode 100644 index 000000000000..03924c769c81 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_tracking_connection.h @@ -0,0 +1,109 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CONNECTION_H + +#include "google/cloud/kms/inventory/v1/internal/key_tracking_retry_traits.h" +#include "google/cloud/kms/inventory/v1/internal/key_tracking_stub.h" +#include "google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.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_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using KeyTrackingServiceRetryPolicy = + ::google::cloud::internal::TraitBasedRetryPolicy< + kms_inventory_v1_internal::KeyTrackingServiceRetryTraits>; + +using KeyTrackingServiceLimitedTimeRetryPolicy = + ::google::cloud::internal::LimitedTimeRetryPolicy< + kms_inventory_v1_internal::KeyTrackingServiceRetryTraits>; + +using KeyTrackingServiceLimitedErrorCountRetryPolicy = + ::google::cloud::internal::LimitedErrorCountRetryPolicy< + kms_inventory_v1_internal::KeyTrackingServiceRetryTraits>; + +/** + * The `KeyTrackingServiceConnection` object for `KeyTrackingServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `KeyTrackingServiceClient`. This allows users to inject custom + * behavior (e.g., with a Google Mock object) when writing tests that use + * objects of type `KeyTrackingServiceClient`. + * + * To create a concrete instance, see `MakeKeyTrackingServiceConnection()`. + * + * For mocking, see `kms_inventory_v1_mocks::MockKeyTrackingServiceConnection`. + */ +class KeyTrackingServiceConnection { + public: + virtual ~KeyTrackingServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr + GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request); + + virtual StreamRange + SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + request); +}; + +/** + * A factory function to construct an object of type + * `KeyTrackingServiceConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of + * KeyTrackingServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `KeyTrackingServiceConnection`. Expected options are any of the + * types in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::kms_inventory_v1::KeyTrackingServicePolicyOptionList` + * + * @note Unexpected options will be ignored. To log unexpected options instead, + * set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment. + * + * @param options (optional) Configure the `KeyTrackingServiceConnection` + * created by this function. + */ +std::shared_ptr MakeKeyTrackingServiceConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CONNECTION_H diff --git a/google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.cc b/google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.cc new file mode 100644 index 000000000000..171dd425cdf5 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.cc @@ -0,0 +1,61 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.h" +#include "absl/memory/memory.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +KeyTrackingServiceConnectionIdempotencyPolicy:: + ~KeyTrackingServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +KeyTrackingServiceConnectionIdempotencyPolicy::clone() const { + return absl::make_unique( + *this); +} + +Idempotency +KeyTrackingServiceConnectionIdempotencyPolicy::GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency +KeyTrackingServiceConnectionIdempotencyPolicy::SearchProtectedResources( + google::cloud::kms::inventory::v1:: + SearchProtectedResourcesRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultKeyTrackingServiceConnectionIdempotencyPolicy() { + return absl::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.h b/google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.h new file mode 100644 index 000000000000..21eee6d1b767 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_tracking_connection_idempotency_policy.h @@ -0,0 +1,58 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_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_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class KeyTrackingServiceConnectionIdempotencyPolicy { + public: + virtual ~KeyTrackingServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetProtectedResourcesSummary( + google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request); + + virtual google::cloud::Idempotency SearchProtectedResources( + google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + request); +}; + +std::unique_ptr +MakeDefaultKeyTrackingServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/kms/inventory/v1/key_tracking_options.h b/google/cloud/kms/inventory/v1/key_tracking_options.h new file mode 100644 index 000000000000..6dd6088c3bb2 --- /dev/null +++ b/google/cloud/kms/inventory/v1/key_tracking_options.h @@ -0,0 +1,76 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_OPTIONS_H + +#include "google/cloud/kms/inventory/v1/key_tracking_connection.h" +#include "google/cloud/kms/inventory/v1/key_tracking_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_inventory_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-kms-options + */ +struct KeyTrackingServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-kms-options + */ +struct KeyTrackingServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-kms-options + */ +struct KeyTrackingServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to KeyTrackingService. + * + * @ingroup google-cloud-kms-options + */ +using KeyTrackingServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_KEY_TRACKING_OPTIONS_H diff --git a/google/cloud/kms/inventory/v1/mocks/mock_key_dashboard_connection.h b/google/cloud/kms/inventory/v1/mocks/mock_key_dashboard_connection.h new file mode 100644 index 000000000000..c1469857374f --- /dev/null +++ b/google/cloud/kms/inventory/v1/mocks/mock_key_dashboard_connection.h @@ -0,0 +1,61 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_MOCKS_MOCK_KEY_DASHBOARD_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_MOCKS_MOCK_KEY_DASHBOARD_CONNECTION_H + +#include "google/cloud/kms/inventory/v1/key_dashboard_connection.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `KeyDashboardServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `KeyDashboardServiceClient`. To do + * so, construct an object of type `KeyDashboardServiceClient` with an instance + * of this class. Then use the Google Test framework functions to program the + * behavior of this mock. + * + * @see [This example][bq-mock] for how to test your application with GoogleTest. + * While the example showcases types from the BigQuery library, the underlying + * principles apply for any pair of `*Client` and `*Connection`. + * + * [bq-mock]: @googleapis_dev_link{bigquery,bigquery-read-mock.html} + */ +class MockKeyDashboardServiceConnection + : public kms_inventory_v1::KeyDashboardServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + StreamRange, ListCryptoKeys, + (google::cloud::kms::inventory::v1::ListCryptoKeysRequest request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_MOCKS_MOCK_KEY_DASHBOARD_CONNECTION_H diff --git a/google/cloud/kms/inventory/v1/mocks/mock_key_tracking_connection.h b/google/cloud/kms/inventory/v1/mocks/mock_key_tracking_connection.h new file mode 100644 index 000000000000..566fcb67ec8a --- /dev/null +++ b/google/cloud/kms/inventory/v1/mocks/mock_key_tracking_connection.h @@ -0,0 +1,70 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_MOCKS_MOCK_KEY_TRACKING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_MOCKS_MOCK_KEY_TRACKING_CONNECTION_H + +#include "google/cloud/kms/inventory/v1/key_tracking_connection.h" +#include + +namespace google { +namespace cloud { +namespace kms_inventory_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `KeyTrackingServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `KeyTrackingServiceClient`. To do + * so, construct an object of type `KeyTrackingServiceClient` with an instance + * of this class. Then use the Google Test framework functions to program the + * behavior of this mock. + * + * @see [This example][bq-mock] for how to test your application with GoogleTest. + * While the example showcases types from the BigQuery library, the underlying + * principles apply for any pair of `*Client` and `*Connection`. + * + * [bq-mock]: @googleapis_dev_link{bigquery,bigquery-read-mock.html} + */ +class MockKeyTrackingServiceConnection + : public kms_inventory_v1::KeyTrackingServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + StatusOr, + GetProtectedResourcesSummary, + (google::cloud::kms::inventory::v1:: + GetProtectedResourcesSummaryRequest const& request), + (override)); + + MOCK_METHOD( + StreamRange, + SearchProtectedResources, + (google::cloud::kms::inventory::v1::SearchProtectedResourcesRequest + request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace kms_inventory_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_KMS_INVENTORY_V1_MOCKS_MOCK_KEY_TRACKING_CONNECTION_H diff --git a/google/cloud/kms/inventory/v1/samples/key_dashboard_client_samples.cc b/google/cloud/kms/inventory/v1/samples/key_dashboard_client_samples.cc new file mode 100644 index 000000000000..7abe92d67b56 --- /dev/null +++ b/google/cloud/kms/inventory/v1/samples/key_dashboard_client_samples.cc @@ -0,0 +1,92 @@ +// Copyright 2023 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/inventory/v1/key_dashboard_service.proto + +#include "google/cloud/kms/inventory/v1/key_dashboard_client.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// main-dox-marker: kms_inventory_v1::KeyDashboardServiceClient +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::kms_inventory_v1::KeyDashboardServiceClient( + google::cloud::kms_inventory_v1::MakeKeyDashboardServiceConnection( + options)); + //! [set-client-endpoint] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::kms_inventory_v1::KeyDashboardServiceClient( + google::cloud::kms_inventory_v1::MakeKeyDashboardServiceConnection( + options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/kms/inventory/v1/samples/key_tracking_client_samples.cc b/google/cloud/kms/inventory/v1/samples/key_tracking_client_samples.cc new file mode 100644 index 000000000000..89f5d0588fb1 --- /dev/null +++ b/google/cloud/kms/inventory/v1/samples/key_tracking_client_samples.cc @@ -0,0 +1,92 @@ +// Copyright 2023 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/inventory/v1/key_tracking_service.proto + +#include "google/cloud/kms/inventory/v1/key_tracking_client.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// main-dox-marker: kms_inventory_v1::KeyTrackingServiceClient +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::kms_inventory_v1::KeyTrackingServiceClient( + google::cloud::kms_inventory_v1::MakeKeyTrackingServiceConnection( + options)); + //! [set-client-endpoint] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::kms_inventory_v1::KeyTrackingServiceClient( + google::cloud::kms_inventory_v1::MakeKeyTrackingServiceConnection( + options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +}