diff --git a/ci/etc/expected_install_directories b/ci/etc/expected_install_directories index 63d9b1bf527de..c4cebec14a5be 100644 --- a/ci/etc/expected_install_directories +++ b/ci/etc/expected_install_directories @@ -845,6 +845,10 @@ ./include/google/cloud/policysimulator/v1/internal ./include/google/cloud/policysimulator/v1/mocks ./include/google/cloud/policytroubleshooter +./include/google/cloud/policytroubleshooter/iam +./include/google/cloud/policytroubleshooter/iam/v3 +./include/google/cloud/policytroubleshooter/iam/v3/internal +./include/google/cloud/policytroubleshooter/iam/v3/mocks ./include/google/cloud/policytroubleshooter/mocks ./include/google/cloud/policytroubleshooter/v1 ./include/google/cloud/policytroubleshooter/v1/internal diff --git a/external/googleapis/CMakeLists.txt b/external/googleapis/CMakeLists.txt index 24f6765eeea0d..315d8cd4ecf71 100644 --- a/external/googleapis/CMakeLists.txt +++ b/external/googleapis/CMakeLists.txt @@ -222,6 +222,8 @@ set(external_googleapis_installed_libraries_list google_cloud_cpp_iam_v1_iam_policy_protos google_cloud_cpp_iam_v1_options_protos google_cloud_cpp_iam_v1_policy_protos + google_cloud_cpp_iam_v2_deny_protos + google_cloud_cpp_iam_v2_policy_protos google_cloud_cpp_logging_protos google_cloud_cpp_longrunning_operations_protos) @@ -321,6 +323,10 @@ external_googleapis_add_library("google/iam/v1/policy.proto" external_googleapis_add_library("google/rpc/status.proto" rpc_error_details_protos) +external_googleapis_add_library( + "google/longrunning/operations.proto" api_annotations_protos + api_client_protos rpc_status_protos) + external_googleapis_add_library( "google/iam/v1/iam_policy.proto" api_annotations_protos @@ -330,9 +336,11 @@ external_googleapis_add_library( iam_v1_options_protos iam_v1_policy_protos) +external_googleapis_add_library("google/iam/v2/deny.proto" type_expr_protos) + external_googleapis_add_library( - "google/longrunning/operations.proto" api_annotations_protos - api_client_protos rpc_status_protos) + "google/iam/v2/policy.proto" api_annotations_protos api_client_protos + api_field_behavior_protos iam_v2_deny_protos longrunning_operations_protos) google_cloud_cpp_load_protolist(cloud_common_list "protolists/common.list") google_cloud_cpp_load_protodeps(cloud_common_deps "protodeps/common.deps") diff --git a/external/googleapis/protodeps/policytroubleshooter.deps b/external/googleapis/protodeps/policytroubleshooter.deps index 7460521e5b519..b814dcc68cf04 100644 --- a/external/googleapis/protodeps/policytroubleshooter.deps +++ b/external/googleapis/protodeps/policytroubleshooter.deps @@ -4,5 +4,7 @@ @com_google_googleapis//google/api:http_proto @com_google_googleapis//google/api:launch_stage_proto @com_google_googleapis//google/iam/v1:policy_proto +@com_google_googleapis//google/iam/v2:policy_proto +@com_google_googleapis//google/longrunning:operations_proto @com_google_googleapis//google/rpc:status_proto @com_google_googleapis//google/type:expr_proto diff --git a/external/googleapis/protolists/policytroubleshooter.list b/external/googleapis/protolists/policytroubleshooter.list index 5f8e0f93568e2..d1eee16bdb7a6 100644 --- a/external/googleapis/protolists/policytroubleshooter.list +++ b/external/googleapis/protolists/policytroubleshooter.list @@ -1,2 +1,3 @@ +@com_google_googleapis//google/cloud/policytroubleshooter/iam/v3:troubleshooter.proto @com_google_googleapis//google/cloud/policytroubleshooter/v1:checker.proto @com_google_googleapis//google/cloud/policytroubleshooter/v1:explanations.proto diff --git a/external/googleapis/update_libraries.sh b/external/googleapis/update_libraries.sh index 652209745e8c6..00d782e2000b1 100755 --- a/external/googleapis/update_libraries.sh +++ b/external/googleapis/update_libraries.sh @@ -211,7 +211,11 @@ declare -A -r LIBRARIES=( "@com_google_googleapis//google/cloud/oslogin/common:common_cc_grpc" )" ["policysimulator"]="@com_google_googleapis//google/cloud/policysimulator/v1:policysimulator_cc_grpc" - ["policytroubleshooter"]="@com_google_googleapis//google/cloud/policytroubleshooter/v1:policytroubleshooter_cc_grpc" + ["policytroubleshooter"]="$( + printf ",%s" \ + "@com_google_googleapis//google/cloud/policytroubleshooter/v1:policytroubleshooter_cc_grpc" \ + "@com_google_googleapis//google/cloud/policytroubleshooter/iam/v3:iam_cc_grpc" + )" ["privateca"]="@com_google_googleapis//google/cloud/security/privateca/v1:privateca_cc_grpc" ["profiler"]="@com_google_googleapis//google/devtools/cloudprofiler/v2:cloudprofiler_cc_grpc" ["pubsub"]="@com_google_googleapis//google/pubsub/v1:pubsub_cc_grpc" diff --git a/generator/generator_config.textproto b/generator/generator_config.textproto index 5196bd31541e8..8ebe21d6ec544 100644 --- a/generator/generator_config.textproto +++ b/generator/generator_config.textproto @@ -2253,6 +2253,13 @@ service { retryable_status_codes: ["kUnavailable"] } +service { + service_proto_path: "google/cloud/policytroubleshooter/iam/v3/troubleshooter.proto" + product_path: "google/cloud/policytroubleshooter/iam/v3" + initial_copyright_year: "2023" + retryable_status_codes: ["kUnavailable"] +} + # IDS (Cloud Intrusion Detection System) service { service_proto_path: "google/cloud/ids/v1/ids.proto" diff --git a/google/cloud/policytroubleshooter/BUILD.bazel b/google/cloud/policytroubleshooter/BUILD.bazel index 5aab26c3e6d6e..bd80edf5483cb 100644 --- a/google/cloud/policytroubleshooter/BUILD.bazel +++ b/google/cloud/policytroubleshooter/BUILD.bazel @@ -19,6 +19,7 @@ licenses(["notice"]) # Apache 2.0 service_dirs = [ "", "v1/", + "iam/v3/", ] src_dirs = service_dirs + [d + "internal/" for d in service_dirs] @@ -46,7 +47,9 @@ cc_library( deps = [ "//:common", "//:grpc_utils", + "@com_google_googleapis//google/cloud/policytroubleshooter/iam/v3:iam_cc_grpc", "@com_google_googleapis//google/cloud/policytroubleshooter/v1:policytroubleshooter_cc_grpc", + "@com_google_googleapis//google/iam/v2:iam_cc_grpc", ], ) diff --git a/google/cloud/policytroubleshooter/CMakeLists.txt b/google/cloud/policytroubleshooter/CMakeLists.txt index 46403a5910e0b..8ec5c7205ac84 100644 --- a/google/cloud/policytroubleshooter/CMakeLists.txt +++ b/google/cloud/policytroubleshooter/CMakeLists.txt @@ -16,10 +16,14 @@ include(GoogleCloudCppLibrary) -set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/") +set(GOOGLE_CLOUD_CPP_SERVICE_DIRS "" "v1/" "iam/v3/") -google_cloud_cpp_add_ga_grpc_library(policytroubleshooter - "Policy Troubleshooter API") +set(GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES + "${PROJECT_BINARY_DIR}/google/cloud/iam_policy") + +google_cloud_cpp_add_ga_grpc_library( + policytroubleshooter "Policy Troubleshooter API" CROSS_LIB_DEPS + "iam_policy") if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) add_executable(policytroubleshooter_quickstart "quickstart/quickstart.cc") diff --git a/google/cloud/policytroubleshooter/doc/environment-variables.dox b/google/cloud/policytroubleshooter/doc/environment-variables.dox index fac7906503508..417bae8ca5d26 100644 --- a/google/cloud/policytroubleshooter/doc/environment-variables.dox +++ b/google/cloud/policytroubleshooter/doc/environment-variables.dox @@ -14,6 +14,14 @@ environment variables are convenient when troubleshooting problems. `EndpointOption` (which defaults to "policytroubleshooter.googleapis.com") used by `MakeIamCheckerConnection()`. +- `GOOGLE_CLOUD_CPP_POLICIES_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "iam.googleapis.com") + used by `MakePoliciesConnection()`. + +- `GOOGLE_CLOUD_CPP_POLICY_TROUBLESHOOTER_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "policytroubleshooter.googleapis.com") + used by `MakePolicyTroubleshooterConnection()`. + @see google::cloud::EndpointOption diff --git a/google/cloud/policytroubleshooter/doc/main.dox b/google/cloud/policytroubleshooter/doc/main.dox index 521880ad814dc..ae69c26d166c9 100644 --- a/google/cloud/policytroubleshooter/doc/main.dox +++ b/google/cloud/policytroubleshooter/doc/main.dox @@ -22,12 +22,19 @@ which should give you a taste of the Policy Troubleshooter API C++ client librar ## Main classes -The main class in this library is -[`policytroubleshooter_v1::IamCheckerClient`](@ref google::cloud::policytroubleshooter_v1::IamCheckerClient). All RPCs are exposed -as member functions of this class. Other classes provide helpers, configuration -parameters, and infrastructure to mock -[`policytroubleshooter_v1::IamCheckerClient`](@ref google::cloud::policytroubleshooter_v1::IamCheckerClient) when testing your +This library offers multiple `*Client` classes, which are listed below. Each one +of these classes exposes all the RPCs for a service as member functions of the +class. This library groups multiple services because they are part of the same +product or are often used together. A typical example may be the administrative +and data plane operations for a single product. + +The library also has other classes that provide helpers, configuration +parameters, and infrastructure to mock the `*Client` classes when testing your application. + +- [\c policytroubleshooter_iam_v3::PoliciesClient](@ref google::cloud::policytroubleshooter_iam_v3::PoliciesClient) +- [\c policytroubleshooter_iam_v3::PolicyTroubleshooterClient](@ref google::cloud::policytroubleshooter_iam_v3::PolicyTroubleshooterClient) +- [\c policytroubleshooter_v1::IamCheckerClient](@ref google::cloud::policytroubleshooter_v1::IamCheckerClient) ## More Information diff --git a/google/cloud/policytroubleshooter/doc/override-authentication.dox b/google/cloud/policytroubleshooter/doc/override-authentication.dox index eaf90c4c27832..bfe735c38f56f 100644 --- a/google/cloud/policytroubleshooter/doc/override-authentication.dox +++ b/google/cloud/policytroubleshooter/doc/override-authentication.dox @@ -9,7 +9,13 @@ this default. You can do so by providing the The following example shows how to explicitly load a service account key file: -@snippet iam_checker_client_samples.cc with-service-account +@snippet policies_client_samples.cc with-service-account + +Follow these links to find examples for other \c *Client classes: + +- [\c policytroubleshooter_iam_v3::PoliciesClient](@ref policytroubleshooter_iam_v3::PoliciesClient-service-account-snippet) +- [\c policytroubleshooter_iam_v3::PolicyTroubleshooterClient](@ref policytroubleshooter_iam_v3::PolicyTroubleshooterClient-service-account-snippet) +- [\c policytroubleshooter_v1::IamCheckerClient](@ref policytroubleshooter_v1::IamCheckerClient-service-account-snippet) @@ -27,6 +33,18 @@ guide for more details. // +/*! @page policytroubleshooter_iam_v3::PoliciesClient-service-account-snippet Override policytroubleshooter_iam_v3::PoliciesClient Authentication Defaults + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policies_client_samples.cc with-service-account + +*/ + +/*! @page policytroubleshooter_iam_v3::PolicyTroubleshooterClient-service-account-snippet Override policytroubleshooter_iam_v3::PolicyTroubleshooterClient Authentication Defaults + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policy_troubleshooter_client_samples.cc with-service-account + +*/ + /*! @page policytroubleshooter_v1::IamCheckerClient-service-account-snippet Override policytroubleshooter_v1::IamCheckerClient Authentication Defaults @snippet google/cloud/policytroubleshooter/v1/samples/iam_checker_client_samples.cc with-service-account diff --git a/google/cloud/policytroubleshooter/doc/override-endpoint.dox b/google/cloud/policytroubleshooter/doc/override-endpoint.dox index 9ae63212697b7..f1fcad20f5708 100644 --- a/google/cloud/policytroubleshooter/doc/override-endpoint.dox +++ b/google/cloud/policytroubleshooter/doc/override-endpoint.dox @@ -7,9 +7,15 @@ library. Use the client library to change this default. -For example, this will override the default endpoint for `policytroubleshooter_v1::IamCheckerClient`: +For example, this will override the default endpoint for `policytroubleshooter_iam_v3::PoliciesClient`: -@snippet iam_checker_client_samples.cc set-client-endpoint +@snippet policies_client_samples.cc set-client-endpoint + +Follow these links to find examples for other \c *Client classes: + +- [\c policytroubleshooter_iam_v3::PoliciesClient](@ref policytroubleshooter_iam_v3::PoliciesClient-endpoint-snippet) +- [\c policytroubleshooter_iam_v3::PolicyTroubleshooterClient](@ref policytroubleshooter_iam_v3::PolicyTroubleshooterClient-endpoint-snippet) +- [\c policytroubleshooter_v1::IamCheckerClient](@ref policytroubleshooter_v1::IamCheckerClient-endpoint-snippet) @@ -17,6 +23,18 @@ For example, this will override the default endpoint for `policytroubleshooter_v // +/*! @page policytroubleshooter_iam_v3::PoliciesClient-endpoint-snippet Override policytroubleshooter_iam_v3::PoliciesClient Endpoint Configuration + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policies_client_samples.cc set-client-endpoint + +*/ + +/*! @page policytroubleshooter_iam_v3::PolicyTroubleshooterClient-endpoint-snippet Override policytroubleshooter_iam_v3::PolicyTroubleshooterClient Endpoint Configuration + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policy_troubleshooter_client_samples.cc set-client-endpoint + +*/ + /*! @page policytroubleshooter_v1::IamCheckerClient-endpoint-snippet Override policytroubleshooter_v1::IamCheckerClient Endpoint Configuration @snippet google/cloud/policytroubleshooter/v1/samples/iam_checker_client_samples.cc set-client-endpoint diff --git a/google/cloud/policytroubleshooter/doc/override-retry-policies.dox b/google/cloud/policytroubleshooter/doc/override-retry-policies.dox index bd7ef7e120110..f7ed3bbf2724e 100644 --- a/google/cloud/policytroubleshooter/doc/override-retry-policies.dox +++ b/google/cloud/policytroubleshooter/doc/override-retry-policies.dox @@ -68,15 +68,21 @@ will use `FooBarIdempotencyPolicy`. This policy is very conservative. @section policytroubleshooter-override-retry-example Example -For example, this will override the retry policies for `policytroubleshooter_v1::IamCheckerClient`: +For example, this will override the retry policies for `policytroubleshooter_iam_v3::PoliciesClient`: -@snippet iam_checker_client_samples.cc set-retry-policy +@snippet policies_client_samples.cc set-retry-policy This assumes you have created a custom idempotency policy. Such as: -@snippet iam_checker_client_samples.cc custom-idempotency-policy +@snippet policies_client_samples.cc custom-idempotency-policy +Follow these links to find examples for other \c *Client classes: + +- [\c policytroubleshooter_iam_v3::PoliciesClient](@ref policytroubleshooter_iam_v3::PoliciesClient-retry-snippet) +- [\c policytroubleshooter_iam_v3::PolicyTroubleshooterClient](@ref policytroubleshooter_iam_v3::PolicyTroubleshooterClient-retry-snippet) +- [\c policytroubleshooter_v1::IamCheckerClient](@ref policytroubleshooter_v1::IamCheckerClient-retry-snippet) + @section policytroubleshooter-override-retry-more-information More Information @@ -91,6 +97,30 @@ This assumes you have created a custom idempotency policy. Such as: // +/*! @page policytroubleshooter_iam_v3::PoliciesClient-retry-snippet Override policytroubleshooter_iam_v3::PoliciesClient Retry Policies + +This shows how to override the retry policies for policytroubleshooter_iam_v3::PoliciesClient: + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policies_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policies_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page policytroubleshooter_iam_v3::PolicyTroubleshooterClient-retry-snippet Override policytroubleshooter_iam_v3::PolicyTroubleshooterClient Retry Policies + +This shows how to override the retry policies for policytroubleshooter_iam_v3::PolicyTroubleshooterClient: + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policy_troubleshooter_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/policytroubleshooter/iam/v3/samples/policy_troubleshooter_client_samples.cc custom-idempotency-policy + +*/ + /*! @page policytroubleshooter_v1::IamCheckerClient-retry-snippet Override policytroubleshooter_v1::IamCheckerClient Retry Policies This shows how to override the retry policies for policytroubleshooter_v1::IamCheckerClient: diff --git a/google/cloud/policytroubleshooter/iam/v3/.repo-metadata.json b/google/cloud/policytroubleshooter/iam/v3/.repo-metadata.json new file mode 100644 index 0000000000000..c2d9debb3a015 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/.repo-metadata.json @@ -0,0 +1,14 @@ +{ + "api_id": "policytroubleshooter.googleapis.com", + "api_shortname": "policytroubleshooter", + "client_documentation": "https://cloud.google.com/cpp/docs/reference/policytroubleshooter/latest", + "distribution_name": "google-cloud-cpp", + "issue_tracker": "https://issuetracker.google.com/issues?q=componentid:690790%20status=open", + "language": "cpp", + "library_type": "GAPIC_AUTO", + "name_pretty": "Policy Troubleshooter API", + "product_documentation": "https://cloud.google.com/policy-intelligence/docs/troubleshoot-access", + "release_level": "stable", + "repo": "googleapis/google-cloud-cpp", + "requires_billing": true +} diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.cc new file mode 100644 index 0000000000000..225d929220c0f --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.cc @@ -0,0 +1,143 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PoliciesAuth::PoliciesAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr PoliciesAuth::ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListPolicies(context, request); +} + +StatusOr PoliciesAuth::GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetPolicy(context, request); +} + +future> +PoliciesAuth::AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) { + using ReturnType = StatusOr; + auto& child = child_; + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child, + request](future>> + f) mutable { + auto context = f.get(); + if (!context) { + return make_ready_future(ReturnType(std::move(context).status())); + } + return child->AsyncCreatePolicy(cq, *std::move(context), request); + }); +} + +future> +PoliciesAuth::AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) { + using ReturnType = StatusOr; + auto& child = child_; + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child, + request](future>> + f) mutable { + auto context = f.get(); + if (!context) { + return make_ready_future(ReturnType(std::move(context).status())); + } + return child->AsyncUpdatePolicy(cq, *std::move(context), request); + }); +} + +future> +PoliciesAuth::AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) { + using ReturnType = StatusOr; + auto& child = child_; + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child, + request](future>> + f) mutable { + auto context = f.get(); + if (!context) { + return make_ready_future(ReturnType(std::move(context).status())); + } + return child->AsyncDeletePolicy(cq, *std::move(context), request); + }); +} + +future> +PoliciesAuth::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + using ReturnType = StatusOr; + auto& child = child_; + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child, + request](future>> + f) mutable { + auto context = f.get(); + if (!context) { + return make_ready_future(ReturnType(std::move(context).status())); + } + return child->AsyncGetOperation(cq, *std::move(context), request); + }); +} + +future PoliciesAuth::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + auto& child = child_; + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child, + request](future>> + f) mutable { + auto context = f.get(); + if (!context) return make_ready_future(std::move(context).status()); + return child->AsyncCancelOperation(cq, *std::move(context), request); + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.h new file mode 100644 index 0000000000000..5336d3f8afa40 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.h @@ -0,0 +1,85 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_AUTH_DECORATOR_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PoliciesAuth : public PoliciesStub { + public: + ~PoliciesAuth() override = default; + PoliciesAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) override; + + StatusOr GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) override; + + future> AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) override; + + future> AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) override; + + future> AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_AUTH_DECORATOR_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.cc new file mode 100644 index 0000000000000..a252e42a2d6bd --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.cc @@ -0,0 +1,170 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_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/async_long_running_operation.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/retry_loop.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PoliciesConnectionImpl::PoliciesConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + PoliciesConnection::options())) {} + +StreamRange PoliciesConnectionImpl::ListPolicies( + google::iam::v2::ListPoliciesRequest 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()->ListPolicies(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + std::move(request), + [stub, retry, backoff, idempotency, + function_name](google::iam::v2::ListPoliciesRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) { + return stub->ListPolicies(context, request); + }, + r, function_name); + }, + [](google::iam::v2::ListPoliciesResponse r) { + std::vector result(r.policies().size()); + auto& messages = *r.mutable_policies(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr PoliciesConnectionImpl::GetPolicy( + google::iam::v2::GetPolicyRequest const& request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->GetPolicy(request), + [this](grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) { + return stub_->GetPolicy(context, request); + }, + request, __func__); +} + +future> PoliciesConnectionImpl::CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request) { + auto& stub = stub_; + return google::cloud::internal::AsyncLongRunningOperation< + google::iam::v2::Policy>( + background_->cq(), request, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) { + return stub->AsyncCreatePolicy(cq, std::move(context), request); + }, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + return stub->AsyncGetOperation(cq, std::move(context), request); + }, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + return stub->AsyncCancelOperation(cq, std::move(context), request); + }, + &google::cloud::internal::ExtractLongRunningResultResponse< + google::iam::v2::Policy>, + retry_policy(), backoff_policy(), + idempotency_policy()->CreatePolicy(request), polling_policy(), __func__); +} + +future> PoliciesConnectionImpl::UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request) { + auto& stub = stub_; + return google::cloud::internal::AsyncLongRunningOperation< + google::iam::v2::Policy>( + background_->cq(), request, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) { + return stub->AsyncUpdatePolicy(cq, std::move(context), request); + }, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + return stub->AsyncGetOperation(cq, std::move(context), request); + }, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + return stub->AsyncCancelOperation(cq, std::move(context), request); + }, + &google::cloud::internal::ExtractLongRunningResultResponse< + google::iam::v2::Policy>, + retry_policy(), backoff_policy(), + idempotency_policy()->UpdatePolicy(request), polling_policy(), __func__); +} + +future> PoliciesConnectionImpl::DeletePolicy( + google::iam::v2::DeletePolicyRequest const& request) { + auto& stub = stub_; + return google::cloud::internal::AsyncLongRunningOperation< + google::iam::v2::Policy>( + background_->cq(), request, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) { + return stub->AsyncDeletePolicy(cq, std::move(context), request); + }, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + return stub->AsyncGetOperation(cq, std::move(context), request); + }, + [stub](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + return stub->AsyncCancelOperation(cq, std::move(context), request); + }, + &google::cloud::internal::ExtractLongRunningResultResponse< + google::iam::v2::Policy>, + retry_policy(), backoff_policy(), + idempotency_policy()->DeletePolicy(request), polling_policy(), __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.h new file mode 100644 index 0000000000000..7562428be89cc --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.h @@ -0,0 +1,137 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_CONNECTION_IMPL_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_retry_traits.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_options.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.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/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PoliciesConnectionImpl + : public policytroubleshooter_iam_v3::PoliciesConnection { + public: + ~PoliciesConnectionImpl() override = default; + + PoliciesConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StreamRange ListPolicies( + google::iam::v2::ListPoliciesRequest request) override; + + StatusOr GetPolicy( + google::iam::v2::GetPolicyRequest const& request) override; + + future> CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request) override; + + future> UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request) override; + + future> DeletePolicy( + google::iam::v2::DeletePolicyRequest const& request) override; + + private: + std::unique_ptr + retry_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has()) { + return options + .get() + ->clone(); + } + return options_ + .get() + ->clone(); + } + + std::unique_ptr backoff_policy() { + auto const& options = internal::CurrentOptions(); + if (options + .has()) { + return options + .get() + ->clone(); + } + return options_ + .get() + ->clone(); + } + + std::unique_ptr< + policytroubleshooter_iam_v3::PoliciesConnectionIdempotencyPolicy> + idempotency_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has()) { + return options + .get() + ->clone(); + } + return options_ + .get() + ->clone(); + } + + std::unique_ptr polling_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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_CONNECTION_IMPL_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.cc new file mode 100644 index 0000000000000..b7b6c47cf5a81 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.cc @@ -0,0 +1,131 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PoliciesLogging::PoliciesLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components) + : child_(std::move(child)), + tracing_options_(std::move(tracing_options)), + stream_logging_(components.find("rpc-streams") != components.end()) {} + +StatusOr PoliciesLogging::ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) { + return child_->ListPolicies(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr PoliciesLogging::GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) { + return child_->GetPolicy(context, request); + }, + context, request, __func__, tracing_options_); +} + +future> +PoliciesLogging::AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) { + return child_->AsyncCreatePolicy(cq, std::move(context), request); + }, + cq, std::move(context), request, __func__, tracing_options_); +} + +future> +PoliciesLogging::AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) { + return child_->AsyncUpdatePolicy(cq, std::move(context), request); + }, + cq, std::move(context), request, __func__, tracing_options_); +} + +future> +PoliciesLogging::AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) { + return child_->AsyncDeletePolicy(cq, std::move(context), request); + }, + cq, std::move(context), request, __func__, tracing_options_); +} + +future> +PoliciesLogging::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + return child_->AsyncGetOperation(cq, std::move(context), request); + }, + cq, std::move(context), request, __func__, tracing_options_); +} + +future PoliciesLogging::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + return child_->AsyncCancelOperation(cq, std::move(context), request); + }, + cq, std::move(context), request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.h new file mode 100644 index 0000000000000..78b80dfd2548f --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.h @@ -0,0 +1,86 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_LOGGING_DECORATOR_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PoliciesLogging : public PoliciesStub { + public: + ~PoliciesLogging() override = default; + PoliciesLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components); + + StatusOr ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) override; + + StatusOr GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) override; + + future> AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) override; + + future> AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) override; + + future> AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + bool stream_logging_; +}; // PoliciesLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_LOGGING_DECORATOR_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.cc new file mode 100644 index 0000000000000..151e54be93d12 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.cc @@ -0,0 +1,121 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PoliciesMetadata::PoliciesMetadata( + std::shared_ptr child, + std::multimap fixed_metadata) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + google::cloud::internal::ApiClientHeader("generator")) {} + +StatusOr PoliciesMetadata::ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) { + SetMetadata(context, absl::StrCat("parent=", request.parent())); + return child_->ListPolicies(context, request); +} + +StatusOr PoliciesMetadata::GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) { + SetMetadata(context, absl::StrCat("name=", request.name())); + return child_->GetPolicy(context, request); +} + +future> +PoliciesMetadata::AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) { + SetMetadata(*context, absl::StrCat("parent=", request.parent())); + return child_->AsyncCreatePolicy(cq, std::move(context), request); +} + +future> +PoliciesMetadata::AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) { + SetMetadata(*context, absl::StrCat("policy.name=", request.policy().name())); + return child_->AsyncUpdatePolicy(cq, std::move(context), request); +} + +future> +PoliciesMetadata::AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) { + SetMetadata(*context, absl::StrCat("name=", request.name())); + return child_->AsyncDeletePolicy(cq, std::move(context), request); +} + +future> +PoliciesMetadata::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + SetMetadata(*context, "name=" + request.name()); + return child_->AsyncGetOperation(cq, std::move(context), request); +} + +future PoliciesMetadata::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + SetMetadata(*context, "name=" + request.name()); + return child_->AsyncCancelOperation(cq, std::move(context), request); +} + +void PoliciesMetadata::SetMetadata(grpc::ClientContext& context, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context); +} + +void PoliciesMetadata::SetMetadata(grpc::ClientContext& context) { + for (auto const& kv : fixed_metadata_) { + context.AddMetadata(kv.first, kv.second); + } + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.h new file mode 100644 index 0000000000000..9bd95eb121115 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.h @@ -0,0 +1,88 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_METADATA_DECORATOR_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PoliciesMetadata : public PoliciesStub { + public: + ~PoliciesMetadata() override = default; + PoliciesMetadata(std::shared_ptr child, + std::multimap fixed_metadata); + + StatusOr ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) override; + + StatusOr GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) override; + + future> AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) override; + + future> AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) override; + + future> AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) override; + + private: + void SetMetadata(grpc::ClientContext& context, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_METADATA_DECORATOR_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_option_defaults.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_option_defaults.cc new file mode 100644 index 0000000000000..35aca3e1aa388 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_option_defaults.cc @@ -0,0 +1,83 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_option_defaults.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options PoliciesDefaultOptions(Options options) { + options = google::cloud::internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_POLICIES_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_POLICIES_AUTHORITY", "iam.googleapis.com"); + options = + google::cloud::internal::PopulateGrpcOptions(std::move(options), ""); + if (!options.has()) { + options.set( + policytroubleshooter_iam_v3::PoliciesLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options + .has()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options + .has()) { + options.set( + GenericPollingPolicy< + policytroubleshooter_iam_v3::PoliciesRetryPolicyOption::Type, + policytroubleshooter_iam_v3::PoliciesBackoffPolicyOption::Type>( + options + .get() + ->clone(), + ExponentialBackoffPolicy(std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling) + .clone()) + .clone()); + } + if (!options.has()) { + options.set< + policytroubleshooter_iam_v3::PoliciesConnectionIdempotencyPolicyOption>( + policytroubleshooter_iam_v3:: + MakeDefaultPoliciesConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_option_defaults.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_option_defaults.h new file mode 100644 index 0000000000000..000574672a8fb --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options PoliciesDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_OPTION_DEFAULTS_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_retry_traits.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_retry_traits.h new file mode 100644 index 0000000000000..d18696566edc9 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct PoliciesRetryTraits { + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_RETRY_TRAITS_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.cc new file mode 100644 index 0000000000000..738cab5e93947 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.cc @@ -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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PoliciesStub::~PoliciesStub() = default; + +StatusOr +DefaultPoliciesStub::ListPolicies( + grpc::ClientContext& client_context, + google::iam::v2::ListPoliciesRequest const& request) { + google::iam::v2::ListPoliciesResponse response; + auto status = grpc_stub_->ListPolicies(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultPoliciesStub::GetPolicy( + grpc::ClientContext& client_context, + google::iam::v2::GetPolicyRequest const& request) { + google::iam::v2::Policy response; + auto status = grpc_stub_->GetPolicy(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +future> +DefaultPoliciesStub::AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) { + return internal::MakeUnaryRpcImpl( + cq, + [this](grpc::ClientContext* context, + google::iam::v2::CreatePolicyRequest const& request, + grpc::CompletionQueue* cq) { + return grpc_stub_->AsyncCreatePolicy(context, request, cq); + }, + request, std::move(context)); +} + +future> +DefaultPoliciesStub::AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) { + return internal::MakeUnaryRpcImpl( + cq, + [this](grpc::ClientContext* context, + google::iam::v2::UpdatePolicyRequest const& request, + grpc::CompletionQueue* cq) { + return grpc_stub_->AsyncUpdatePolicy(context, request, cq); + }, + request, std::move(context)); +} + +future> +DefaultPoliciesStub::AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) { + return internal::MakeUnaryRpcImpl( + cq, + [this](grpc::ClientContext* context, + google::iam::v2::DeletePolicyRequest const& request, + grpc::CompletionQueue* cq) { + return grpc_stub_->AsyncDeletePolicy(context, request, cq); + }, + request, std::move(context)); +} + +future> +DefaultPoliciesStub::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + return internal::MakeUnaryRpcImpl( + cq, + [this](grpc::ClientContext* context, + google::longrunning::GetOperationRequest const& request, + grpc::CompletionQueue* cq) { + return operations_->AsyncGetOperation(context, request, cq); + }, + request, std::move(context)); +} + +future DefaultPoliciesStub::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + return internal::MakeUnaryRpcImpl( + cq, + [this](grpc::ClientContext* context, + google::longrunning::CancelOperationRequest const& request, + grpc::CompletionQueue* cq) { + return operations_->AsyncCancelOperation(context, request, cq); + }, + request, std::move(context)) + .then([](future> f) { + return f.get().status(); + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h new file mode 100644 index 0000000000000..0fc4f8d44f90a --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h @@ -0,0 +1,125 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/future.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PoliciesStub { + public: + virtual ~PoliciesStub() = 0; + + virtual StatusOr ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) = 0; + + virtual StatusOr GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) = 0; + + virtual future> AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) = 0; + + virtual future> AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) = 0; + + virtual future> AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) = 0; + + virtual future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) = 0; + + virtual future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) = 0; +}; + +class DefaultPoliciesStub : public PoliciesStub { + public: + DefaultPoliciesStub( + std::unique_ptr grpc_stub, + std::unique_ptr + operations) + : grpc_stub_(std::move(grpc_stub)), operations_(std::move(operations)) {} + + StatusOr ListPolicies( + grpc::ClientContext& client_context, + google::iam::v2::ListPoliciesRequest const& request) override; + + StatusOr GetPolicy( + grpc::ClientContext& client_context, + google::iam::v2::GetPolicyRequest const& request) override; + + future> AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) override; + + future> AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) override; + + future> AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) override; + + private: + std::unique_ptr grpc_stub_; + std::unique_ptr operations_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_STUB_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub_factory.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub_factory.cc new file mode 100644 index 0000000000000..9de8de85d208e --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub_factory.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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub_factory.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_auth_decorator.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_logging_decorator.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_metadata_decorator.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_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 policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultPoliciesStub( + 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::iam::v2::Policies::NewStub(channel); + std::shared_ptr stub = std::make_shared( + std::move(service_grpc_stub), + google::longrunning::Operations::NewStub(channel)); + + if (auth->RequiresConfigureContext()) { + stub = std::make_shared(std::move(auth), std::move(stub)); + } + stub = std::make_shared( + std::move(stub), std::multimap{}); + 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 = MakePoliciesTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub_factory.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_stub_factory.h new file mode 100644 index 0000000000000..fb10e51c5e11c --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_STUB_FACTORY_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_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 policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultPoliciesStub( + google::cloud::CompletionQueue cq, Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_STUB_FACTORY_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.cc new file mode 100644 index 0000000000000..069eb906b3baf --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.cc @@ -0,0 +1,96 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +PoliciesTracingConnection::PoliciesTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StreamRange PoliciesTracingConnection::ListPolicies( + google::iam::v2::ListPoliciesRequest request) { + auto span = internal::MakeSpan( + "policytroubleshooter_iam_v3::PoliciesConnection::ListPolicies"); + auto scope = opentelemetry::trace::Scope(span); + auto sr = child_->ListPolicies(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +StatusOr PoliciesTracingConnection::GetPolicy( + google::iam::v2::GetPolicyRequest const& request) { + auto span = internal::MakeSpan( + "policytroubleshooter_iam_v3::PoliciesConnection::GetPolicy"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetPolicy(request)); +} + +future> +PoliciesTracingConnection::CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request) { + auto span = internal::MakeSpan( + "policytroubleshooter_iam_v3::PoliciesConnection::CreatePolicy"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(std::move(span), child_->CreatePolicy(request)); +} + +future> +PoliciesTracingConnection::UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request) { + auto span = internal::MakeSpan( + "policytroubleshooter_iam_v3::PoliciesConnection::UpdatePolicy"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(std::move(span), child_->UpdatePolicy(request)); +} + +future> +PoliciesTracingConnection::DeletePolicy( + google::iam::v2::DeletePolicyRequest const& request) { + auto span = internal::MakeSpan( + "policytroubleshooter_iam_v3::PoliciesConnection::DeletePolicy"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(std::move(span), child_->DeletePolicy(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakePoliciesTracingConnection( + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.h new file mode 100644 index 0000000000000..00732194e66e0 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.h @@ -0,0 +1,79 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_TRACING_CONNECTION_H + +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class PoliciesTracingConnection + : public policytroubleshooter_iam_v3::PoliciesConnection { + public: + ~PoliciesTracingConnection() override = default; + + explicit PoliciesTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StreamRange ListPolicies( + google::iam::v2::ListPoliciesRequest request) override; + + StatusOr GetPolicy( + google::iam::v2::GetPolicyRequest const& request) override; + + future> CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request) override; + + future> UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request) override; + + future> DeletePolicy( + google::iam::v2::DeletePolicyRequest const& 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 +MakePoliciesTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_TRACING_CONNECTION_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_stub.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_stub.cc new file mode 100644 index 0000000000000..1f45d6d5cdb56 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_stub.cc @@ -0,0 +1,137 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +PoliciesTracingStub::PoliciesTracingStub(std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +PoliciesTracingStub::ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) { + auto span = internal::MakeSpanGrpc("google.iam.v2.Policies", "ListPolicies"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, internal::CurrentOptions()); + return internal::EndSpan(context, *span, + child_->ListPolicies(context, request)); +} + +StatusOr PoliciesTracingStub::GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) { + auto span = internal::MakeSpanGrpc("google.iam.v2.Policies", "GetPolicy"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, internal::CurrentOptions()); + return internal::EndSpan(context, *span, child_->GetPolicy(context, request)); +} + +future> +PoliciesTracingStub::AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) { + auto span = internal::MakeSpanGrpc("google.iam.v2.Policies", "CreatePolicy"); + { + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(*context, internal::CurrentOptions()); + } + auto f = child_->AsyncCreatePolicy(cq, context, request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +future> +PoliciesTracingStub::AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) { + auto span = internal::MakeSpanGrpc("google.iam.v2.Policies", "UpdatePolicy"); + { + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(*context, internal::CurrentOptions()); + } + auto f = child_->AsyncUpdatePolicy(cq, context, request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +future> +PoliciesTracingStub::AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) { + auto span = internal::MakeSpanGrpc("google.iam.v2.Policies", "DeletePolicy"); + { + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(*context, internal::CurrentOptions()); + } + auto f = child_->AsyncDeletePolicy(cq, context, request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +future> +PoliciesTracingStub::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.longrunning.Operations", "GetOperation"); + { + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(*context, internal::CurrentOptions()); + } + auto f = child_->AsyncGetOperation(cq, context, request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +future PoliciesTracingStub::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest const& request) { + auto span = internal::MakeSpanGrpc("google.longrunning.Operations", + "CancelOperation"); + { + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(*context, internal::CurrentOptions()); + } + auto f = child_->AsyncCancelOperation(cq, context, request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakePoliciesTracingStub( + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_stub.h b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_stub.h new file mode 100644 index 0000000000000..6b63ba703963a --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_stub.h @@ -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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_TRACING_STUB_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class PoliciesTracingStub : public PoliciesStub { + public: + ~PoliciesTracingStub() override = default; + + explicit PoliciesTracingStub(std::shared_ptr child); + + StatusOr ListPolicies( + grpc::ClientContext& context, + google::iam::v2::ListPoliciesRequest const& request) override; + + StatusOr GetPolicy( + grpc::ClientContext& context, + google::iam::v2::GetPolicyRequest const& request) override; + + future> AsyncCreatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::CreatePolicyRequest const& request) override; + + future> AsyncUpdatePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::UpdatePolicyRequest const& request) override; + + future> AsyncDeletePolicy( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::iam::v2::DeletePolicyRequest const& request) override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::longrunning::CancelOperationRequest 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 MakePoliciesTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICIES_TRACING_STUB_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.cc new file mode 100644 index 0000000000000..1977a5923b7a1 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PolicyTroubleshooterAuth::PolicyTroubleshooterAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterAuth::TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->TroubleshootIamPolicy(context, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.h new file mode 100644 index 0000000000000..2823e0bf9c6f8 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_AUTH_DECORATOR_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PolicyTroubleshooterAuth : public PolicyTroubleshooterStub { + public: + ~PolicyTroubleshooterAuth() override = default; + PolicyTroubleshooterAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr + TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_AUTH_DECORATOR_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.cc new file mode 100644 index 0000000000000..ec89736ef2384 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.cc @@ -0,0 +1,89 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_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/retry_loop.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN +namespace { + +std::unique_ptr +retry_policy(Options const& options) { + return options + .get() + ->clone(); +} + +std::unique_ptr backoff_policy(Options const& options) { + return options + .get() + ->clone(); +} + +std::unique_ptr +idempotency_policy(Options const& options) { + return options + .get() + ->clone(); +} + +} // namespace + +PolicyTroubleshooterConnectionImpl::PolicyTroubleshooterConnectionImpl( + std::unique_ptr background, + std::shared_ptr< + policytroubleshooter_iam_v3_internal::PolicyTroubleshooterStub> + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions( + std::move(options), PolicyTroubleshooterConnection::options())) {} + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterConnectionImpl::TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->TroubleshootIamPolicy(request), + [this](grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + return stub_->TroubleshootIamPolicy(context, request); + }, + request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.h new file mode 100644 index 0000000000000..a1d649229b233 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_CONNECTION_IMPL_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_retry_traits.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_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/version.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PolicyTroubleshooterConnectionImpl + : public policytroubleshooter_iam_v3::PolicyTroubleshooterConnection { + public: + ~PolicyTroubleshooterConnectionImpl() override = default; + + PolicyTroubleshooterConnectionImpl( + std::unique_ptr background, + std::shared_ptr< + policytroubleshooter_iam_v3_internal::PolicyTroubleshooterStub> + stub, + Options options); + + Options options() override { return options_; } + + StatusOr + TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) override; + + private: + std::unique_ptr background_; + std::shared_ptr< + policytroubleshooter_iam_v3_internal::PolicyTroubleshooterStub> + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_CONNECTION_IMPL_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.cc new file mode 100644 index 0000000000000..57925653bf9d1 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.cc @@ -0,0 +1,55 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PolicyTroubleshooterLogging::PolicyTroubleshooterLogging( + std::shared_ptr child, + TracingOptions tracing_options, std::set const& components) + : child_(std::move(child)), + tracing_options_(std::move(tracing_options)), + stream_logging_(components.find("rpc-streams") != components.end()) {} + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterLogging::TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + return child_->TroubleshootIamPolicy(context, request); + }, + context, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.h new file mode 100644 index 0000000000000..e8a320f03d09e --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.h @@ -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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_LOGGING_DECORATOR_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PolicyTroubleshooterLogging : public PolicyTroubleshooterStub { + public: + ~PolicyTroubleshooterLogging() override = default; + PolicyTroubleshooterLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components); + + StatusOr + TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + bool stream_logging_; +}; // PolicyTroubleshooterLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_LOGGING_DECORATOR_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.cc new file mode 100644 index 0000000000000..b75bc4a5dec7e --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.cc @@ -0,0 +1,73 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PolicyTroubleshooterMetadata::PolicyTroubleshooterMetadata( + std::shared_ptr child, + std::multimap fixed_metadata) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + google::cloud::internal::ApiClientHeader("generator")) {} + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterMetadata::TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + SetMetadata(context); + return child_->TroubleshootIamPolicy(context, request); +} + +void PolicyTroubleshooterMetadata::SetMetadata( + grpc::ClientContext& context, std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context); +} + +void PolicyTroubleshooterMetadata::SetMetadata(grpc::ClientContext& context) { + for (auto const& kv : fixed_metadata_) { + context.AddMetadata(kv.first, kv.second); + } + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.h new file mode 100644 index 0000000000000..b7380324604e3 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.h @@ -0,0 +1,62 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_METADATA_DECORATOR_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PolicyTroubleshooterMetadata : public PolicyTroubleshooterStub { + public: + ~PolicyTroubleshooterMetadata() override = default; + PolicyTroubleshooterMetadata( + std::shared_ptr child, + std::multimap fixed_metadata); + + StatusOr + TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) override; + + private: + void SetMetadata(grpc::ClientContext& context, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_METADATA_DECORATOR_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_option_defaults.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_option_defaults.cc new file mode 100644 index 0000000000000..e06f0f853ba56 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_option_defaults.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_option_defaults.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options PolicyTroubleshooterDefaultOptions(Options options) { + options = google::cloud::internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_POLICY_TROUBLESHOOTER_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_POLICY_TROUBLESHOOTER_AUTHORITY", + "policytroubleshooter.googleapis.com"); + options = + google::cloud::internal::PopulateGrpcOptions(std::move(options), ""); + if (!options.has()) { + options.set< + policytroubleshooter_iam_v3::PolicyTroubleshooterRetryPolicyOption>( + policytroubleshooter_iam_v3::PolicyTroubleshooterLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has()) { + options.set< + policytroubleshooter_iam_v3::PolicyTroubleshooterBackoffPolicyOption>( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options + .has()) { + options.set( + policytroubleshooter_iam_v3:: + MakeDefaultPolicyTroubleshooterConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_option_defaults.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_option_defaults.h new file mode 100644 index 0000000000000..a24376b06a535 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options PolicyTroubleshooterDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_OPTION_DEFAULTS_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_retry_traits.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_retry_traits.h new file mode 100644 index 0000000000000..df407fac5cb26 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct PolicyTroubleshooterRetryTraits { + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_RETRY_TRAITS_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.cc new file mode 100644 index 0000000000000..28ddc4ba1a5ef --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PolicyTroubleshooterStub::~PolicyTroubleshooterStub() = default; + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +DefaultPolicyTroubleshooterStub::TroubleshootIamPolicy( + grpc::ClientContext& client_context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse + response; + auto status = + grpc_stub_->TroubleshootIamPolicy(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h new file mode 100644 index 0000000000000..6d98cbb61c9f4 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h @@ -0,0 +1,69 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_STUB_H + +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PolicyTroubleshooterStub { + public: + virtual ~PolicyTroubleshooterStub() = 0; + + virtual StatusOr + TroubleshootIamPolicy(grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) = 0; +}; + +class DefaultPolicyTroubleshooterStub : public PolicyTroubleshooterStub { + public: + explicit DefaultPolicyTroubleshooterStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr + TroubleshootIamPolicy( + grpc::ClientContext& client_context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) override; + + private: + std::unique_ptr + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_STUB_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub_factory.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub_factory.cc new file mode 100644 index 0000000000000..9057a85e736ef --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub_factory.cc @@ -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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub_factory.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_auth_decorator.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_logging_decorator.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_metadata_decorator.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_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 policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultPolicyTroubleshooterStub( + 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::policytroubleshooter::iam::v3:: + PolicyTroubleshooter::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), std::multimap{}); + 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 = MakePolicyTroubleshooterTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub_factory.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub_factory.h new file mode 100644 index 0000000000000..cb1d60f0d816e --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_STUB_FACTORY_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_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 policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultPolicyTroubleshooterStub( + google::cloud::CompletionQueue cq, Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_STUB_FACTORY_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_connection.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_connection.cc new file mode 100644 index 0000000000000..04417c22c41a4 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_connection.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +PolicyTroubleshooterTracingConnection::PolicyTroubleshooterTracingConnection( + std::shared_ptr + child) + : child_(std::move(child)) {} + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterTracingConnection::TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + auto span = internal::MakeSpan( + "policytroubleshooter_iam_v3::PolicyTroubleshooterConnection::" + "TroubleshootIamPolicy"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->TroubleshootIamPolicy(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakePolicyTroubleshooterTracingConnection( + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_connection.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_connection.h new file mode 100644 index 0000000000000..6331a33018e7f --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_TRACING_CONNECTION_H + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class PolicyTroubleshooterTracingConnection + : public policytroubleshooter_iam_v3::PolicyTroubleshooterConnection { + public: + ~PolicyTroubleshooterTracingConnection() override = default; + + explicit PolicyTroubleshooterTracingConnection( + std::shared_ptr< + policytroubleshooter_iam_v3::PolicyTroubleshooterConnection> + child); + + Options options() override { return child_->options(); } + + StatusOr + TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& 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 +MakePolicyTroubleshooterTracingConnection( + std::shared_ptr + conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_TRACING_CONNECTION_H diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_stub.cc b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_stub.cc new file mode 100644 index 0000000000000..72770f475de08 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_stub.cc @@ -0,0 +1,62 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +PolicyTroubleshooterTracingStub::PolicyTroubleshooterTracingStub( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterTracingStub::TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.policytroubleshooter.iam.v3.PolicyTroubleshooter", + "TroubleshootIamPolicy"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, internal::CurrentOptions()); + return internal::EndSpan(context, *span, + child_->TroubleshootIamPolicy(context, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakePolicyTroubleshooterTracingStub( + 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 policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_stub.h b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_stub.h new file mode 100644 index 0000000000000..3f4b9f2b716a1 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_stub.h @@ -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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_TRACING_STUB_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class PolicyTroubleshooterTracingStub : public PolicyTroubleshooterStub { + public: + ~PolicyTroubleshooterTracingStub() override = default; + + explicit PolicyTroubleshooterTracingStub( + std::shared_ptr child); + + StatusOr + TroubleshootIamPolicy( + grpc::ClientContext& context, + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest 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 MakePolicyTroubleshooterTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_INTERNAL_POLICY_TROUBLESHOOTER_TRACING_STUB_H diff --git a/google/cloud/policytroubleshooter/iam/v3/mocks/mock_policies_connection.h b/google/cloud/policytroubleshooter/iam/v3/mocks/mock_policies_connection.h new file mode 100644 index 0000000000000..68f12c4cc57fc --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/mocks/mock_policies_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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_MOCKS_MOCK_POLICIES_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_MOCKS_MOCK_POLICIES_CONNECTION_H + +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `PoliciesConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `PoliciesClient`. To do so, + * construct an object of type `PoliciesClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockPoliciesConnection + : public policytroubleshooter_iam_v3::PoliciesConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StreamRange, ListPolicies, + (google::iam::v2::ListPoliciesRequest request), (override)); + + MOCK_METHOD(StatusOr, GetPolicy, + (google::iam::v2::GetPolicyRequest const& request), (override)); + + MOCK_METHOD(future>, CreatePolicy, + (google::iam::v2::CreatePolicyRequest const& request), + (override)); + + MOCK_METHOD(future>, UpdatePolicy, + (google::iam::v2::UpdatePolicyRequest const& request), + (override)); + + MOCK_METHOD(future>, DeletePolicy, + (google::iam::v2::DeletePolicyRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_MOCKS_MOCK_POLICIES_CONNECTION_H diff --git a/google/cloud/policytroubleshooter/iam/v3/mocks/mock_policy_troubleshooter_connection.h b/google/cloud/policytroubleshooter/iam/v3/mocks/mock_policy_troubleshooter_connection.h new file mode 100644 index 0000000000000..59e3156ad2de0 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/mocks/mock_policy_troubleshooter_connection.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_MOCKS_MOCK_POLICY_TROUBLESHOOTER_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_MOCKS_MOCK_POLICY_TROUBLESHOOTER_CONNECTION_H + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `PolicyTroubleshooterConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `PolicyTroubleshooterClient`. To do + * so, construct an object of type `PolicyTroubleshooterClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockPolicyTroubleshooterConnection + : public policytroubleshooter_iam_v3::PolicyTroubleshooterConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, + TroubleshootIamPolicy, + (google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_MOCKS_MOCK_POLICY_TROUBLESHOOTER_CONNECTION_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policies_client.cc b/google/cloud/policytroubleshooter/iam/v3/policies_client.cc new file mode 100644 index 0000000000000..3c2e8dce9f2e3 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policies_client.cc @@ -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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policies_client.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PoliciesClient::PoliciesClient(std::shared_ptr connection, + Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +PoliciesClient::~PoliciesClient() = default; + +StreamRange PoliciesClient::ListPolicies( + std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::iam::v2::ListPoliciesRequest request; + request.set_parent(parent); + return connection_->ListPolicies(request); +} + +StreamRange PoliciesClient::ListPolicies( + google::iam::v2::ListPoliciesRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListPolicies(std::move(request)); +} + +StatusOr PoliciesClient::GetPolicy( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::iam::v2::GetPolicyRequest request; + request.set_name(name); + return connection_->GetPolicy(request); +} + +StatusOr PoliciesClient::GetPolicy( + google::iam::v2::GetPolicyRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetPolicy(request); +} + +future> PoliciesClient::CreatePolicy( + std::string const& parent, google::iam::v2::Policy const& policy, + std::string const& policy_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::iam::v2::CreatePolicyRequest request; + request.set_parent(parent); + *request.mutable_policy() = policy; + request.set_policy_id(policy_id); + return connection_->CreatePolicy(request); +} + +future> PoliciesClient::CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreatePolicy(request); +} + +future> PoliciesClient::UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdatePolicy(request); +} + +future> PoliciesClient::DeletePolicy( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::iam::v2::DeletePolicyRequest request; + request.set_name(name); + return connection_->DeletePolicy(request); +} + +future> PoliciesClient::DeletePolicy( + google::iam::v2::DeletePolicyRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeletePolicy(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/policies_client.h b/google/cloud/policytroubleshooter/iam/v3/policies_client.h new file mode 100644 index 0000000000000..5487a7308f0c2 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policies_client.h @@ -0,0 +1,464 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CLIENT_H + +#include "google/cloud/policytroubleshooter/iam/v3/policies_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 +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// An interface for managing Identity and Access Management (IAM) policies. +/// +/// @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 PoliciesClient { + public: + explicit PoliciesClient(std::shared_ptr connection, + Options opts = {}); + ~PoliciesClient(); + + ///@{ + /// @name Copy and move support + PoliciesClient(PoliciesClient const&) = default; + PoliciesClient& operator=(PoliciesClient const&) = default; + PoliciesClient(PoliciesClient&&) = default; + PoliciesClient& operator=(PoliciesClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(PoliciesClient const& a, PoliciesClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(PoliciesClient const& a, PoliciesClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Retrieves the policies of the specified kind that are attached to a + /// resource. + /// + /// The response lists only policy metadata. In particular, policy rules are + /// omitted. + /// + /// @param parent Required. The resource that the policy is attached to, along with the kind of policy + /// to list. Format: + /// `policies/{attachment_point}/denypolicies` + /// @n + /// The attachment point is identified by its URL-encoded full resource name, + /// which means that the forward-slash character, `/`, must be written as + /// `%2F`. For example, + /// `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies`. + /// @n + /// For organizations and folders, use the numeric ID in the full resource + /// name. For projects, you can use the alphanumeric or the numeric ID. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.iam.v2.Policy], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.ListPoliciesRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L176} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + StreamRange ListPolicies(std::string const& parent, + Options opts = {}); + + // clang-format off + /// + /// Retrieves the policies of the specified kind that are attached to a + /// resource. + /// + /// The response lists only policy metadata. In particular, policy rules are + /// omitted. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.iam.v2.ListPoliciesRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.iam.v2.Policy], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.ListPoliciesRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L176} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + StreamRange ListPolicies( + google::iam::v2::ListPoliciesRequest request, Options opts = {}); + + // clang-format off + /// + /// Gets a policy. + /// + /// @param name Required. The resource name of the policy to retrieve. Format: + /// `policies/{attachment_point}/denypolicies/{policy_id}` + /// @n + /// Use the URL-encoded full resource name, which means that the forward-slash + /// character, `/`, must be written as `%2F`. For example, + /// `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies/my-policy`. + /// @n + /// For organizations and folders, use the numeric ID in the full resource + /// name. For projects, you can use the alphanumeric or the numeric ID. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.iam.v2.Policy]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.GetPolicyRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L211} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + StatusOr GetPolicy(std::string const& name, + Options opts = {}); + + // clang-format off + /// + /// Gets a policy. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.iam.v2.GetPolicyRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.iam.v2.Policy]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.GetPolicyRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L211} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + StatusOr GetPolicy( + google::iam::v2::GetPolicyRequest const& request, Options opts = {}); + + // clang-format off + /// + /// Creates a policy. + /// + /// @param parent Required. The resource that the policy is attached to, along with the kind of policy + /// to create. Format: `policies/{attachment_point}/denypolicies` + /// @n + /// The attachment point is identified by its URL-encoded full resource name, + /// which means that the forward-slash character, `/`, must be written as + /// `%2F`. For example, + /// `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies`. + /// @n + /// For organizations and folders, use the numeric ID in the full resource + /// name. For projects, you can use the alphanumeric or the numeric ID. + /// @param policy Required. The policy to create. + /// @param policy_id The ID to use for this policy, which will become the final component of + /// the policy's resource name. The ID must contain 3 to 63 characters. It can + /// contain lowercase letters and numbers, as well as dashes (`-`) and periods + /// (`.`). The first character must be a lowercase letter. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return A [`future`] that becomes satisfied when the LRO + /// ([Long Running Operation]) completes or the polling policy in effect + /// for this call is exhausted. The future is satisfied with an error if + /// the LRO completes with an error or the polling policy is exhausted. + /// In this case the [`StatusOr`] returned by the future contains the + /// error. If the LRO completes successfully the value of the future + /// contains the LRO's result. For this RPC the result is a + /// [google.iam.v2.Policy] proto message. + /// The C++ class representing this message is created by Protobuf, using + /// the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.CreatePolicyRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L226} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + future> CreatePolicy( + std::string const& parent, google::iam::v2::Policy const& policy, + std::string const& policy_id, Options opts = {}); + + // clang-format off + /// + /// Creates a policy. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.iam.v2.CreatePolicyRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return A [`future`] that becomes satisfied when the LRO + /// ([Long Running Operation]) completes or the polling policy in effect + /// for this call is exhausted. The future is satisfied with an error if + /// the LRO completes with an error or the polling policy is exhausted. + /// In this case the [`StatusOr`] returned by the future contains the + /// error. If the LRO completes successfully the value of the future + /// contains the LRO's result. For this RPC the result is a + /// [google.iam.v2.Policy] proto message. + /// The C++ class representing this message is created by Protobuf, using + /// the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.CreatePolicyRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L226} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + future> CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request, Options opts = {}); + + // clang-format off + /// + /// Updates the specified policy. + /// + /// You can update only the rules and the display name for the policy. + /// + /// To update a policy, you should use a read-modify-write loop: + /// + /// 1. Use [GetPolicy][google.iam.v2.Policies.GetPolicy] to read the current version of the policy. + /// 2. Modify the policy as needed. + /// 3. Use `UpdatePolicy` to write the updated policy. + /// + /// This pattern helps prevent conflicts between concurrent updates. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.iam.v2.UpdatePolicyRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return A [`future`] that becomes satisfied when the LRO + /// ([Long Running Operation]) completes or the polling policy in effect + /// for this call is exhausted. The future is satisfied with an error if + /// the LRO completes with an error or the polling policy is exhausted. + /// In this case the [`StatusOr`] returned by the future contains the + /// error. If the LRO completes successfully the value of the future + /// contains the LRO's result. For this RPC the result is a + /// [google.iam.v2.Policy] proto message. + /// The C++ class representing this message is created by Protobuf, using + /// the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.Policies.GetPolicy]: @googleapis_reference_link{google/iam/v2/policy.proto#L51} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// [google.iam.v2.UpdatePolicyRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L251} + /// + // clang-format on + future> UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request, Options opts = {}); + + // clang-format off + /// + /// Deletes a policy. This action is permanent. + /// + /// @param name Required. The resource name of the policy to delete. Format: + /// `policies/{attachment_point}/denypolicies/{policy_id}` + /// @n + /// Use the URL-encoded full resource name, which means that the forward-slash + /// character, `/`, must be written as `%2F`. For example, + /// `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies/my-policy`. + /// @n + /// For organizations and folders, use the numeric ID in the full resource + /// name. For projects, you can use the alphanumeric or the numeric ID. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return A [`future`] that becomes satisfied when the LRO + /// ([Long Running Operation]) completes or the polling policy in effect + /// for this call is exhausted. The future is satisfied with an error if + /// the LRO completes with an error or the polling policy is exhausted. + /// In this case the [`StatusOr`] returned by the future contains the + /// error. If the LRO completes successfully the value of the future + /// contains the LRO's result. For this RPC the result is a + /// [google.iam.v2.Policy] proto message. + /// The C++ class representing this message is created by Protobuf, using + /// the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.DeletePolicyRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L261} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + future> DeletePolicy( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Deletes a policy. This action is permanent. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.iam.v2.DeletePolicyRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return A [`future`] that becomes satisfied when the LRO + /// ([Long Running Operation]) completes or the polling policy in effect + /// for this call is exhausted. The future is satisfied with an error if + /// the LRO completes with an error or the polling policy is exhausted. + /// In this case the [`StatusOr`] returned by the future contains the + /// error. If the LRO completes successfully the value of the future + /// contains the LRO's result. For this RPC the result is a + /// [google.iam.v2.Policy] proto message. + /// The C++ class representing this message is created by Protobuf, using + /// the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.iam.v2.DeletePolicyRequest]: @googleapis_reference_link{google/iam/v2/policy.proto#L261} + /// [google.iam.v2.Policy]: @googleapis_reference_link{google/iam/v2/policy.proto#L107} + /// + // clang-format on + future> DeletePolicy( + google::iam::v2::DeletePolicyRequest const& request, Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CLIENT_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policies_connection.cc b/google/cloud/policytroubleshooter/iam/v3/policies_connection.cc new file mode 100644 index 0000000000000..53ccf4d06e6da --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policies_connection.cc @@ -0,0 +1,87 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_connection_impl.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_option_defaults.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_stub_factory.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_tracing_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_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 policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PoliciesConnection::~PoliciesConnection() = default; + +StreamRange PoliciesConnection::ListPolicies( + google::iam::v2:: + ListPoliciesRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr PoliciesConnection::GetPolicy( + google::iam::v2::GetPolicyRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +future> PoliciesConnection::CreatePolicy( + google::iam::v2::CreatePolicyRequest const&) { + return google::cloud::make_ready_future>( + Status(StatusCode::kUnimplemented, "not implemented")); +} + +future> PoliciesConnection::UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const&) { + return google::cloud::make_ready_future>( + Status(StatusCode::kUnimplemented, "not implemented")); +} + +future> PoliciesConnection::DeletePolicy( + google::iam::v2::DeletePolicyRequest const&) { + return google::cloud::make_ready_future>( + Status(StatusCode::kUnimplemented, "not implemented")); +} + +std::shared_ptr MakePoliciesConnection(Options options) { + internal::CheckExpectedOptions(options, __func__); + options = policytroubleshooter_iam_v3_internal::PoliciesDefaultOptions( + std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto stub = policytroubleshooter_iam_v3_internal::CreateDefaultPoliciesStub( + background->cq(), options); + return policytroubleshooter_iam_v3_internal::MakePoliciesTracingConnection( + std::make_shared< + policytroubleshooter_iam_v3_internal::PoliciesConnectionImpl>( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/policies_connection.h b/google/cloud/policytroubleshooter/iam/v3/policies_connection.h new file mode 100644 index 0000000000000..aa4f231576767 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policies_connection.h @@ -0,0 +1,230 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CONNECTION_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policies_retry_traits.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `PoliciesConnection`. +class PoliciesRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PoliciesConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PoliciesLimitedErrorCountRetryPolicy : public PoliciesRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PoliciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + PoliciesLimitedErrorCountRetryPolicy( + PoliciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : PoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + PoliciesLimitedErrorCountRetryPolicy( + PoliciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : PoliciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + policytroubleshooter_iam_v3_internal::PoliciesRetryTraits> + impl_; +}; + +/** + * A retry policy for `PoliciesConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PoliciesLimitedTimeRetryPolicy : public PoliciesRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PoliciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PoliciesLimitedTimeRetryPolicy(PoliciesLimitedTimeRetryPolicy&& rhs) noexcept + : PoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PoliciesLimitedTimeRetryPolicy( + PoliciesLimitedTimeRetryPolicy const& rhs) noexcept + : PoliciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique(maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PoliciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + policytroubleshooter_iam_v3_internal::PoliciesRetryTraits> + impl_; +}; + +/** + * The `PoliciesConnection` object for `PoliciesClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `PoliciesClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `PoliciesClient`. + * + * To create a concrete instance, see `MakePoliciesConnection()`. + * + * For mocking, see `policytroubleshooter_iam_v3_mocks::MockPoliciesConnection`. + */ +class PoliciesConnection { + public: + virtual ~PoliciesConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StreamRange ListPolicies( + google::iam::v2::ListPoliciesRequest request); + + virtual StatusOr GetPolicy( + google::iam::v2::GetPolicyRequest const& request); + + virtual future> CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request); + + virtual future> UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request); + + virtual future> DeletePolicy( + google::iam::v2::DeletePolicyRequest const& request); +}; + +/** + * A factory function to construct an object of type `PoliciesConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of PoliciesClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `PoliciesConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::policytroubleshooter_iam_v3::PoliciesPolicyOptionList` + * + * @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 `PoliciesConnection` created by + * this function. + */ +std::shared_ptr MakePoliciesConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CONNECTION_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.cc b/google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..5f544ab8aefea --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +PoliciesConnectionIdempotencyPolicy::~PoliciesConnectionIdempotencyPolicy() = + default; + +std::unique_ptr +PoliciesConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency PoliciesConnectionIdempotencyPolicy::ListPolicies( + google::iam::v2::ListPoliciesRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency PoliciesConnectionIdempotencyPolicy::GetPolicy( + google::iam::v2::GetPolicyRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency PoliciesConnectionIdempotencyPolicy::CreatePolicy( + google::iam::v2::CreatePolicyRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency PoliciesConnectionIdempotencyPolicy::UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency PoliciesConnectionIdempotencyPolicy::DeletePolicy( + google::iam::v2::DeletePolicyRequest const&) { + return Idempotency::kNonIdempotent; +} + +std::unique_ptr +MakeDefaultPoliciesConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.h b/google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.h new file mode 100644 index 0000000000000..788dd5ef66ed8 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PoliciesConnectionIdempotencyPolicy { + public: + virtual ~PoliciesConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() const; + + virtual google::cloud::Idempotency ListPolicies( + google::iam::v2::ListPoliciesRequest request); + + virtual google::cloud::Idempotency GetPolicy( + google::iam::v2::GetPolicyRequest const& request); + + virtual google::cloud::Idempotency CreatePolicy( + google::iam::v2::CreatePolicyRequest const& request); + + virtual google::cloud::Idempotency UpdatePolicy( + google::iam::v2::UpdatePolicyRequest const& request); + + virtual google::cloud::Idempotency DeletePolicy( + google::iam::v2::DeletePolicyRequest const& request); +}; + +std::unique_ptr +MakeDefaultPoliciesConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policies_options.h b/google/cloud/policytroubleshooter/iam/v3/policies_options.h new file mode 100644 index 0000000000000..adf4dcfca0524 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policies_options.h @@ -0,0 +1,86 @@ +// 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/iam/v2/policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_OPTIONS_H + +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_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 policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +struct PoliciesRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +struct PoliciesBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +struct PoliciesConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the long-running operations + * polling policy. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +struct PoliciesPollingPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to Policies. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +using PoliciesPolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICIES_OPTIONS_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.cc b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.cc new file mode 100644 index 0000000000000..2c7e416ea4db6 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PolicyTroubleshooterClient::PolicyTroubleshooterClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +PolicyTroubleshooterClient::~PolicyTroubleshooterClient() = default; + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterClient::TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->TroubleshootIamPolicy(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.h b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.h new file mode 100644 index 0000000000000..88af7c5ef91cf --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.h @@ -0,0 +1,138 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CLIENT_H + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_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 policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// IAM Policy Troubleshooter service. +/// +/// This service helps you troubleshoot access issues for Google Cloud +/// resources. +/// +/// @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 PolicyTroubleshooterClient { + public: + explicit PolicyTroubleshooterClient( + std::shared_ptr connection, + Options opts = {}); + ~PolicyTroubleshooterClient(); + + ///@{ + /// @name Copy and move support + PolicyTroubleshooterClient(PolicyTroubleshooterClient const&) = default; + PolicyTroubleshooterClient& operator=(PolicyTroubleshooterClient const&) = + default; + PolicyTroubleshooterClient(PolicyTroubleshooterClient&&) = default; + PolicyTroubleshooterClient& operator=(PolicyTroubleshooterClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(PolicyTroubleshooterClient const& a, + PolicyTroubleshooterClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(PolicyTroubleshooterClient const& a, + PolicyTroubleshooterClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Checks whether a principal has a specific permission for a specific + /// resource, and explains why the principal does or doesn't have that + /// permission. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.policytroubleshooter.iam.v3.TroubleshootIamPolicyRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.policytroubleshooter.iam.v3.TroubleshootIamPolicyResponse]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [Long Running Operation]: https://google.aip.dev/151 + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.policytroubleshooter.iam.v3.TroubleshootIamPolicyRequest]: @googleapis_reference_link{google/cloud/policytroubleshooter/iam/v3/troubleshooter.proto#L173} + /// [google.cloud.policytroubleshooter.iam.v3.TroubleshootIamPolicyResponse]: @googleapis_reference_link{google/cloud/policytroubleshooter/iam/v3/troubleshooter.proto#L181} + /// + // clang-format on + StatusOr + TroubleshootIamPolicy(google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CLIENT_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.cc b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.cc new file mode 100644 index 0000000000000..d6d7ada9514de --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_connection_impl.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_option_defaults.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_stub_factory.h" +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_tracing_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_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 + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +PolicyTroubleshooterConnection::~PolicyTroubleshooterConnection() = default; + +StatusOr< + google::cloud::policytroubleshooter::iam::v3::TroubleshootIamPolicyResponse> +PolicyTroubleshooterConnection::TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +std::shared_ptr +MakePolicyTroubleshooterConnection(Options options) { + internal::CheckExpectedOptions( + options, __func__); + options = + policytroubleshooter_iam_v3_internal::PolicyTroubleshooterDefaultOptions( + std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto stub = policytroubleshooter_iam_v3_internal:: + CreateDefaultPolicyTroubleshooterStub(background->cq(), options); + return policytroubleshooter_iam_v3_internal:: + MakePolicyTroubleshooterTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h new file mode 100644 index 0000000000000..c5ca4b7587b9e --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h @@ -0,0 +1,227 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CONNECTION_H + +#include "google/cloud/policytroubleshooter/iam/v3/internal/policy_troubleshooter_retry_traits.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `PolicyTroubleshooterConnection`. +class PolicyTroubleshooterRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `PolicyTroubleshooterConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PolicyTroubleshooterLimitedErrorCountRetryPolicy + : public PolicyTroubleshooterRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit PolicyTroubleshooterLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + PolicyTroubleshooterLimitedErrorCountRetryPolicy( + PolicyTroubleshooterLimitedErrorCountRetryPolicy&& rhs) noexcept + : PolicyTroubleshooterLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + PolicyTroubleshooterLimitedErrorCountRetryPolicy( + PolicyTroubleshooterLimitedErrorCountRetryPolicy const& rhs) noexcept + : PolicyTroubleshooterLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = PolicyTroubleshooterRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + policytroubleshooter_iam_v3_internal::PolicyTroubleshooterRetryTraits> + impl_; +}; + +/** + * A retry policy for `PolicyTroubleshooterConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class PolicyTroubleshooterLimitedTimeRetryPolicy + : public PolicyTroubleshooterRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit PolicyTroubleshooterLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + PolicyTroubleshooterLimitedTimeRetryPolicy( + PolicyTroubleshooterLimitedTimeRetryPolicy&& rhs) noexcept + : PolicyTroubleshooterLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + PolicyTroubleshooterLimitedTimeRetryPolicy( + PolicyTroubleshooterLimitedTimeRetryPolicy const& rhs) noexcept + : PolicyTroubleshooterLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = PolicyTroubleshooterRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + policytroubleshooter_iam_v3_internal::PolicyTroubleshooterRetryTraits> + impl_; +}; + +/** + * The `PolicyTroubleshooterConnection` object for `PolicyTroubleshooterClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `PolicyTroubleshooterClient`. This allows users to inject custom + * behavior (e.g., with a Google Mock object) when writing tests that use + * objects of type `PolicyTroubleshooterClient`. + * + * To create a concrete instance, see `MakePolicyTroubleshooterConnection()`. + * + * For mocking, see + * `policytroubleshooter_iam_v3_mocks::MockPolicyTroubleshooterConnection`. + */ +class PolicyTroubleshooterConnection { + public: + virtual ~PolicyTroubleshooterConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr + TroubleshootIamPolicy(google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request); +}; + +/** + * A factory function to construct an object of type + * `PolicyTroubleshooterConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of + * PolicyTroubleshooterClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `PolicyTroubleshooterConnection`. Expected options are any of the + * types in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - + * `google::cloud::policytroubleshooter_iam_v3::PolicyTroubleshooterPolicyOptionList` + * + * @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 `PolicyTroubleshooterConnection` + * created by this function. + */ +std::shared_ptr +MakePolicyTroubleshooterConnection(Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CONNECTION_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.cc b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..dc01984b49a52 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.cc @@ -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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +PolicyTroubleshooterConnectionIdempotencyPolicy:: + ~PolicyTroubleshooterConnectionIdempotencyPolicy() = default; + +std::unique_ptr +PolicyTroubleshooterConnectionIdempotencyPolicy::clone() const { + return std::make_unique( + *this); +} + +Idempotency +PolicyTroubleshooterConnectionIdempotencyPolicy::TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const&) { + return Idempotency::kNonIdempotent; +} + +std::unique_ptr +MakeDefaultPolicyTroubleshooterConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google diff --git a/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.h b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.h new file mode 100644 index 0000000000000..b62bc86a8d860 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class PolicyTroubleshooterConnectionIdempotencyPolicy { + public: + virtual ~PolicyTroubleshooterConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr + clone() const; + + virtual google::cloud::Idempotency TroubleshootIamPolicy( + google::cloud::policytroubleshooter::iam::v3:: + TroubleshootIamPolicyRequest const& request); +}; + +std::unique_ptr +MakeDefaultPolicyTroubleshooterConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_options.h b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_options.h new file mode 100644 index 0000000000000..6de80a187e0bf --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_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/policytroubleshooter/iam/v3/troubleshooter.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_OPTIONS_H + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_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 policytroubleshooter_iam_v3 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +struct PolicyTroubleshooterRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +struct PolicyTroubleshooterBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +struct PolicyTroubleshooterConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to PolicyTroubleshooter. + * + * @ingroup google-cloud-policytroubleshooter-options + */ +using PolicyTroubleshooterPolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace policytroubleshooter_iam_v3 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_POLICYTROUBLESHOOTER_IAM_V3_POLICY_TROUBLESHOOTER_OPTIONS_H diff --git a/google/cloud/policytroubleshooter/iam/v3/samples/policies_client_samples.cc b/google/cloud/policytroubleshooter/iam/v3/samples/policies_client_samples.cc new file mode 100644 index 0000000000000..7dfa94f2e3a45 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/samples/policies_client_samples.cc @@ -0,0 +1,164 @@ +// 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/iam/v2/policy.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policies_client.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_connection_idempotency_policy.h" +#include "google/cloud/policytroubleshooter/iam/v3/policies_options.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 + +// clang-format off +// main-dox-marker: policytroubleshooter_iam_v3::PoliciesClient +// clang-format on +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::policytroubleshooter_iam_v3::PoliciesClient( + google::cloud::policytroubleshooter_iam_v3::MakePoliciesConnection( + options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::policytroubleshooter_iam_v3:: + PoliciesConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::policytroubleshooter_iam_v3:: + PoliciesLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = + google::cloud::policytroubleshooter_iam_v3::MakePoliciesConnection( + options); + + // c1 and c2 share the same retry policies + auto c1 = + google::cloud::policytroubleshooter_iam_v3::PoliciesClient(connection); + auto c2 = + google::cloud::policytroubleshooter_iam_v3::PoliciesClient(connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::policytroubleshooter_iam_v3::PoliciesClient( + connection, + google::cloud::Options{} + .set( + google::cloud::policytroubleshooter_iam_v3:: + PoliciesLimitedTimeRetryPolicy(std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::policytroubleshooter_iam_v3::PoliciesLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +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::policytroubleshooter_iam_v3::PoliciesClient( + google::cloud::policytroubleshooter_iam_v3::MakePoliciesConnection( + 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 SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + 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}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/policytroubleshooter/iam/v3/samples/policy_troubleshooter_client_samples.cc b/google/cloud/policytroubleshooter/iam/v3/samples/policy_troubleshooter_client_samples.cc new file mode 100644 index 0000000000000..c015f1df02be5 --- /dev/null +++ b/google/cloud/policytroubleshooter/iam/v3/samples/policy_troubleshooter_client_samples.cc @@ -0,0 +1,169 @@ +// 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/policytroubleshooter/iam/v3/troubleshooter.proto + +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_client.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_connection_idempotency_policy.h" +#include "google/cloud/policytroubleshooter/iam/v3/policy_troubleshooter_options.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 + +// clang-format off +// main-dox-marker: policytroubleshooter_iam_v3::PolicyTroubleshooterClient +// clang-format on +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::policytroubleshooter_iam_v3::PolicyTroubleshooterClient( + google::cloud::policytroubleshooter_iam_v3:: + MakePolicyTroubleshooterConnection(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::policytroubleshooter_iam_v3:: + PolicyTroubleshooterConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = + google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::policytroubleshooter_iam_v3:: + PolicyTroubleshooterLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = google::cloud::policytroubleshooter_iam_v3:: + MakePolicyTroubleshooterConnection(options); + + // c1 and c2 share the same retry policies + auto c1 = + google::cloud::policytroubleshooter_iam_v3::PolicyTroubleshooterClient( + connection); + auto c2 = + google::cloud::policytroubleshooter_iam_v3::PolicyTroubleshooterClient( + connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = + google::cloud::policytroubleshooter_iam_v3::PolicyTroubleshooterClient( + connection, google::cloud::Options{} + .set( + google::cloud::policytroubleshooter_iam_v3:: + PolicyTroubleshooterLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::policytroubleshooter_iam_v3::PolicyTroubleshooterLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +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::policytroubleshooter_iam_v3:: + PolicyTroubleshooterClient( + google::cloud::policytroubleshooter_iam_v3:: + MakePolicyTroubleshooterConnection(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 SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + 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}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +}