diff --git a/CHANGELOG.md b/CHANGELOG.md index cd31f8dc7ec9e..cab4f749e0f30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ breaking changes in the upcoming 3.x release. This release is scheduled for ## v2.28.0 - TBD +### New Libraries + +We are happy to announce the following GA libraries. Unless specifically noted, +the APIs in these libraries are stable, and are ready for production use. + +- [ApiHub API](/google/cloud/apihub/README.md) + ## v2.27.0 - 2024-08 - We now link our mocking libraries against GoogleTest in CMake. diff --git a/README.md b/README.md index dc7ec8066eb2c..3e625b0f1f110 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,9 @@ See each library's `README.md` file for more information about: - [Apigee Connect API](google/cloud/apigeeconnect/README.md) [\[quickstart\]](google/cloud/apigeeconnect/quickstart/README.md) [\[reference\]](https://cloud.google.com/cpp/docs/reference/apigeeconnect/latest) +- [API hub API](google/cloud/apihub/README.md) + [\[quickstart\]](google/cloud/apihub/quickstart/README.md) + [\[reference\]](https://cloud.google.com/cpp/docs/reference/apihub/latest) - [API Keys API](google/cloud/apikeys/README.md) [\[quickstart\]](google/cloud/apikeys/quickstart/README.md) [\[reference\]](https://cloud.google.com/cpp/docs/reference/apikeys/latest) diff --git a/ci/abi-dumps/google_cloud_cpp_apihub.expected.abi.dump.gz b/ci/abi-dumps/google_cloud_cpp_apihub.expected.abi.dump.gz new file mode 100644 index 0000000000000..093728253d535 Binary files /dev/null and b/ci/abi-dumps/google_cloud_cpp_apihub.expected.abi.dump.gz differ diff --git a/ci/etc/expected_install_directories b/ci/etc/expected_install_directories index cc150fa8a603e..295dafff3c03e 100644 --- a/ci/etc/expected_install_directories +++ b/ci/etc/expected_install_directories @@ -52,6 +52,10 @@ ./include/google/cloud/apigeeconnect/v1 ./include/google/cloud/apigeeconnect/v1/internal ./include/google/cloud/apigeeconnect/v1/mocks +./include/google/cloud/apihub +./include/google/cloud/apihub/v1 +./include/google/cloud/apihub/v1/internal +./include/google/cloud/apihub/v1/mocks ./include/google/cloud/apikeys ./include/google/cloud/apikeys/mocks ./include/google/cloud/apikeys/v2 @@ -1261,6 +1265,8 @@ ./lib64/cmake/google_cloud_cpp_apigateway_mocks ./lib64/cmake/google_cloud_cpp_apigeeconnect ./lib64/cmake/google_cloud_cpp_apigeeconnect_mocks +./lib64/cmake/google_cloud_cpp_apihub +./lib64/cmake/google_cloud_cpp_apihub_mocks ./lib64/cmake/google_cloud_cpp_apikeys ./lib64/cmake/google_cloud_cpp_apikeys_mocks ./lib64/cmake/google_cloud_cpp_appengine diff --git a/cmake/GoogleCloudCppFeatures.cmake b/cmake/GoogleCloudCppFeatures.cmake index 2360cdbf67f33..9e9ad2e8c33ff 100644 --- a/cmake/GoogleCloudCppFeatures.cmake +++ b/cmake/GoogleCloudCppFeatures.cmake @@ -49,6 +49,7 @@ set(GOOGLE_CLOUD_CPP_GA_LIBRARIES "alloydb" "apigateway" "apigeeconnect" + "apihub" "apikeys" "appengine" "apphub" diff --git a/external/googleapis/protodeps/apihub.deps b/external/googleapis/protodeps/apihub.deps new file mode 100644 index 0000000000000..6ef8f9ccdeb73 --- /dev/null +++ b/external/googleapis/protodeps/apihub.deps @@ -0,0 +1,8 @@ +@com_google_googleapis//google/api:annotations_proto +@com_google_googleapis//google/api:client_proto +@com_google_googleapis//google/api:field_behavior_proto +@com_google_googleapis//google/api:http_proto +@com_google_googleapis//google/api:launch_stage_proto +@com_google_googleapis//google/api:resource_proto +@com_google_googleapis//google/longrunning:operations_proto +@com_google_googleapis//google/rpc:status_proto diff --git a/external/googleapis/protolists/apihub.list b/external/googleapis/protolists/apihub.list new file mode 100644 index 0000000000000..a06e860c62dd9 --- /dev/null +++ b/external/googleapis/protolists/apihub.list @@ -0,0 +1,7 @@ +@com_google_googleapis//google/cloud/apihub/v1:apihub_service.proto +@com_google_googleapis//google/cloud/apihub/v1:common_fields.proto +@com_google_googleapis//google/cloud/apihub/v1:host_project_registration_service.proto +@com_google_googleapis//google/cloud/apihub/v1:linting_service.proto +@com_google_googleapis//google/cloud/apihub/v1:plugin_service.proto +@com_google_googleapis//google/cloud/apihub/v1:provisioning_service.proto +@com_google_googleapis//google/cloud/apihub/v1:runtime_project_attachment_service.proto diff --git a/external/googleapis/update_libraries.sh b/external/googleapis/update_libraries.sh index 916b01273d575..b5cad20264a1d 100755 --- a/external/googleapis/update_libraries.sh +++ b/external/googleapis/update_libraries.sh @@ -35,6 +35,7 @@ declare -A -r LIBRARIES=( ["alloydb"]="@com_google_googleapis//google/cloud/alloydb/v1:alloydb_cc_grpc" ["apigateway"]="@com_google_googleapis//google/cloud/apigateway/v1:apigateway_cc_grpc" ["apigeeconnect"]="@com_google_googleapis//google/cloud/apigeeconnect/v1:apigeeconnect_cc_grpc" + ["apihub"]="@com_google_googleapis//google/cloud/apihub/v1:apihub_cc_grpc" ["apikeys"]="@com_google_googleapis//google/api/apikeys/v2:apikeys_cc_grpc" ["appengine"]="$( printf ",%s" \ diff --git a/generator/generator_config.textproto b/generator/generator_config.textproto index 211159029ae4a..95310a55f391c 100644 --- a/generator/generator_config.textproto +++ b/generator/generator_config.textproto @@ -278,6 +278,49 @@ service { retryable_status_codes: ["kUnavailable", "kUnknown"] } +# API Hub +service { + service_proto_path: "google/cloud/apihub/v1/apihub_service.proto" + product_path: "google/cloud/apihub/v1" + initial_copyright_year: "2024" + retryable_status_codes: ["kUnavailable"] +} + +service { + service_proto_path: "google/cloud/apihub/v1/host_project_registration_service.proto" + product_path: "google/cloud/apihub/v1" + initial_copyright_year: "2024" + retryable_status_codes: ["kUnavailable"] +} + +service { + service_proto_path: "google/cloud/apihub/v1/linting_service.proto" + product_path: "google/cloud/apihub/v1" + initial_copyright_year: "2024" + retryable_status_codes: ["kUnavailable"] +} + +service { + service_proto_path: "google/cloud/apihub/v1/plugin_service.proto" + product_path: "google/cloud/apihub/v1" + initial_copyright_year: "2024" + retryable_status_codes: ["kUnavailable"] +} + +service { + service_proto_path: "google/cloud/apihub/v1/provisioning_service.proto" + product_path: "google/cloud/apihub/v1" + initial_copyright_year: "2024" + retryable_status_codes: ["kUnavailable"] +} + +service { + service_proto_path: "google/cloud/apihub/v1/runtime_project_attachment_service.proto" + product_path: "google/cloud/apihub/v1" + initial_copyright_year: "2024" + retryable_status_codes: ["kUnavailable"] +} + # API Keys service { service_proto_path: "google/api/apikeys/v2/apikeys.proto" diff --git a/google/cloud/apihub/BUILD.bazel b/google/cloud/apihub/BUILD.bazel new file mode 100644 index 0000000000000..b7cd97271495c --- /dev/null +++ b/google/cloud/apihub/BUILD.bazel @@ -0,0 +1,31 @@ +# Copyright 2024 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. + +load("//bazel:gapic.bzl", "cc_gapic_library") + +package(default_visibility = ["//visibility:private"]) + +licenses(["notice"]) # Apache 2.0 + +service_dirs = ["v1/"] + +googleapis_deps = [ + "@com_google_googleapis//google/cloud/apihub/v1:apihub_cc_grpc", +] + +cc_gapic_library( + name = "apihub", + googleapis_deps = googleapis_deps, + service_dirs = service_dirs, +) diff --git a/google/cloud/apihub/CMakeLists.txt b/google/cloud/apihub/CMakeLists.txt new file mode 100644 index 0000000000000..61e3e11ae8d97 --- /dev/null +++ b/google/cloud/apihub/CMakeLists.txt @@ -0,0 +1,33 @@ +# ~~~ +# Copyright 2024 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. +# ~~~ + +include(GoogleCloudCppLibrary) + +google_cloud_cpp_add_gapic_library(apihub "API hub API" SERVICE_DIRS "v1/") + +if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) + add_executable(apihub_quickstart "quickstart/quickstart.cc") + target_link_libraries(apihub_quickstart PRIVATE google-cloud-cpp::apihub) + google_cloud_cpp_add_common_options(apihub_quickstart) + add_test( + NAME apihub_quickstart + COMMAND + cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake" + $ GOOGLE_CLOUD_PROJECT + GOOGLE_CLOUD_CPP_TEST_REGION) + set_tests_properties(apihub_quickstart + PROPERTIES LABELS "integration-test;quickstart") +endif () diff --git a/google/cloud/apihub/README.md b/google/cloud/apihub/README.md new file mode 100644 index 0000000000000..bf3cb09bbad6c --- /dev/null +++ b/google/cloud/apihub/README.md @@ -0,0 +1,57 @@ +# API hub API C++ Client Library + +This directory contains an idiomatic C++ client library for the +[API hub API][cloud-service-docs]. + +While this library is **GA**, please note that the Google Cloud C++ client +libraries do **not** follow [Semantic Versioning](https://semver.org/). + +## Quickstart + +The [quickstart/](quickstart/README.md) directory contains a minimal environment +to get started using this client library in a larger project. The following +"Hello World" program is used in this quickstart, and should give you a taste of +this library. + + + +```cc +#include "google/cloud/apihub/v1/api_hub_client.h" +#include "google/cloud/location.h" +#include + +int main(int argc, char* argv[]) try { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " project-id location-id\n"; + return 1; + } + + auto const location = google::cloud::Location(argv[1], argv[2]); + + namespace apihub = ::google::cloud::apihub_v1; + auto client = apihub::ApiHubClient(apihub::MakeApiHubConnection()); + + for (auto r : client.ListApis(location.FullName())) { + if (!r) throw std::move(r).status(); + std::cout << r->DebugString() << "\n"; + } + + return 0; +} catch (google::cloud::Status const& status) { + std::cerr << "google::cloud::Status thrown: " << status << "\n"; + return 1; +} +``` + + + +## More Information + +- Official documentation about the [API hub API][cloud-service-docs] service +- [Reference doxygen documentation][doxygen-link] for each release of this + client library +- Detailed header comments in our [public `.h`][source-link] files + +[cloud-service-docs]: https://cloud.google.com/apigee/docs/apihub/what-is-api-hub +[doxygen-link]: https://cloud.google.com/cpp/docs/reference/apihub/latest/ +[source-link]: https://github.com/googleapis/google-cloud-cpp/tree/main/google/cloud/apihub diff --git a/google/cloud/apihub/doc/environment-variables.dox b/google/cloud/apihub/doc/environment-variables.dox new file mode 100644 index 0000000000000..58e2c323cdf80 --- /dev/null +++ b/google/cloud/apihub/doc/environment-variables.dox @@ -0,0 +1,74 @@ +/*! + +@page apihub-env Environment Variables + +A number of environment variables can be used to configure the behavior of +the library. There are also functions to configure this behavior in code. The +environment variables are convenient when troubleshooting problems. + +@section apihub-env-endpoint Endpoint Overrides + + + +- `GOOGLE_CLOUD_CPP_API_HUB_DEPENDENCIES_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "apihub.googleapis.com") + used by `MakeApiHubDependenciesConnection()`. + +- `GOOGLE_CLOUD_CPP_API_HUB_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "apihub.googleapis.com") + used by `MakeApiHubConnection()`. + +- `GOOGLE_CLOUD_CPP_API_HUB_PLUGIN_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "apihub.googleapis.com") + used by `MakeApiHubPluginConnection()`. + +- `GOOGLE_CLOUD_CPP_HOST_PROJECT_REGISTRATION_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "apihub.googleapis.com") + used by `MakeHostProjectRegistrationServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_LINTING_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "apihub.googleapis.com") + used by `MakeLintingServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_PROVISIONING_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "apihub.googleapis.com") + used by `MakeProvisioningConnection()`. + +- `GOOGLE_CLOUD_CPP_RUNTIME_PROJECT_ATTACHMENT_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "apihub.googleapis.com") + used by `MakeRuntimeProjectAttachmentServiceConnection()`. + + + +@see google::cloud::EndpointOption + +@section apihub-env-logging Logging + +`GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc`: turns on tracing for most gRPC +calls. The library injects an additional Stub decorator that prints each gRPC +request and response. Unless you have configured your own logging backend, +you should also set `GOOGLE_CLOUD_CPP_ENABLE_CLOG` to produce any output on +the program's console. + +@see google::cloud::LoggingComponentsOption + +`GOOGLE_CLOUD_CPP_TRACING_OPTIONS=...`: modifies the behavior of gRPC tracing, +including whether messages will be output on multiple lines, or whether +string/bytes fields will be truncated. + +@see google::cloud::GrpcTracingOptionsOption + +`GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes`: turns on logging in the library, basically +the library always "logs" but the logging infrastructure has no backend to +actually print anything until the application sets a backend or they set this +environment variable. + +@see google::cloud::LogBackend +@see google::cloud::LogSink + +@section apihub-env-project Setting the Default Project + +`GOOGLE_CLOUD_PROJECT=...`: is used in examples and integration tests to +configure the GCP project. This has no effect in the library. + +*/ diff --git a/google/cloud/apihub/doc/main.dox b/google/cloud/apihub/doc/main.dox new file mode 100644 index 0000000000000..8a276f46c3b6b --- /dev/null +++ b/google/cloud/apihub/doc/main.dox @@ -0,0 +1,56 @@ +/*! + +@mainpage API hub API C++ Client Library + +An idiomatic C++ client library for the [API hub API][cloud-service-docs]. + +While this library is **GA**, please note that the Google Cloud C++ client libraries do **not** follow +[Semantic Versioning](https://semver.org/). + +@tableofcontents{HTML:2} + +## Quickstart + +The following shows the code that you'll run in the +`google/cloud/apihub/quickstart/` directory, +which should give you a taste of the API hub API C++ client library API. + +@snippet quickstart.cc all + +## Main classes + + +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 apihub_v1::ApiHubClient](@ref google::cloud::apihub_v1::ApiHubClient) +- [\c apihub_v1::ApiHubDependenciesClient](@ref google::cloud::apihub_v1::ApiHubDependenciesClient) +- [\c apihub_v1::ApiHubPluginClient](@ref google::cloud::apihub_v1::ApiHubPluginClient) +- [\c apihub_v1::HostProjectRegistrationServiceClient](@ref google::cloud::apihub_v1::HostProjectRegistrationServiceClient) +- [\c apihub_v1::LintingServiceClient](@ref google::cloud::apihub_v1::LintingServiceClient) +- [\c apihub_v1::ProvisioningClient](@ref google::cloud::apihub_v1::ProvisioningClient) +- [\c apihub_v1::RuntimeProjectAttachmentServiceClient](@ref google::cloud::apihub_v1::RuntimeProjectAttachmentServiceClient) + + +## More Information + +- @ref common-error-handling - describes how the library reports errors. +- @ref apihub-override-endpoint - describes how to override the default + endpoint. +- @ref apihub-override-authentication - describes how to change the + authentication credentials used by the library. +- @ref apihub-override-retry - describes how to change the default retry + policies. +- @ref apihub-env - describes environment variables that can configure the + behavior of the library. + +[cloud-service-docs]: https://cloud.google.com/apigee/docs/apihub/what-is-api-hub + +*/ diff --git a/google/cloud/apihub/doc/options.dox b/google/cloud/apihub/doc/options.dox new file mode 100644 index 0000000000000..4f0261c5d5b42 --- /dev/null +++ b/google/cloud/apihub/doc/options.dox @@ -0,0 +1,10 @@ +/*! +@defgroup google-cloud-apihub-options API hub API Configuration Options + +This library uses the same mechanism (`google::cloud::Options`) and the common +[options](@ref options) as all other C++ client libraries for its configuration. +Some `*Option` classes, which are only used in this library, are documented in +this page. + +@see @ref options - for an overview of client library configuration. +*/ diff --git a/google/cloud/apihub/doc/override-authentication.dox b/google/cloud/apihub/doc/override-authentication.dox new file mode 100644 index 0000000000000..415b9aa2184e1 --- /dev/null +++ b/google/cloud/apihub/doc/override-authentication.dox @@ -0,0 +1,81 @@ +/*! +@page apihub-override-authentication How to Override the Authentication Credentials + +Unless otherwise configured, the client libraries use +[Application Default Credentials] to authenticate with Google Cloud Services. +While this works for most applications, in some cases you may need to override +this default. You can do so by providing the +[UnifiedCredentialsOption](@ref google::cloud::UnifiedCredentialsOption) +The following example shows how to explicitly load a service account key file: + + +@snippet api_hub_client_samples.cc with-service-account + +Follow these links to find examples for other \c *Client classes: + +- [\c apihub_v1::ApiHubClient](@ref apihub_v1::ApiHubClient-service-account-snippet) +- [\c apihub_v1::ApiHubDependenciesClient](@ref apihub_v1::ApiHubDependenciesClient-service-account-snippet) +- [\c apihub_v1::ApiHubPluginClient](@ref apihub_v1::ApiHubPluginClient-service-account-snippet) +- [\c apihub_v1::HostProjectRegistrationServiceClient](@ref apihub_v1::HostProjectRegistrationServiceClient-service-account-snippet) +- [\c apihub_v1::LintingServiceClient](@ref apihub_v1::LintingServiceClient-service-account-snippet) +- [\c apihub_v1::ProvisioningClient](@ref apihub_v1::ProvisioningClient-service-account-snippet) +- [\c apihub_v1::RuntimeProjectAttachmentServiceClient](@ref apihub_v1::RuntimeProjectAttachmentServiceClient-service-account-snippet) + + + +Keep in mind that we chose this as an example because it is relatively easy to +understand. Consult the [Best practices for managing service account keys] +guide for more details. + +@see @ref guac - for more information on the factory functions to create +`google::cloud::Credentials` objects. + +[Best practices for managing service account keys]: https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys +[Application Default Credentials]: https://cloud.google.com/docs/authentication#adc + +*/ + +// + +/*! @page apihub_v1::ApiHubClient-service-account-snippet Override apihub_v1::ApiHubClient Authentication Defaults + +@snippet google/cloud/apihub/v1/samples/api_hub_client_samples.cc with-service-account + +*/ + +/*! @page apihub_v1::ApiHubDependenciesClient-service-account-snippet Override apihub_v1::ApiHubDependenciesClient Authentication Defaults + +@snippet google/cloud/apihub/v1/samples/api_hub_dependencies_client_samples.cc with-service-account + +*/ + +/*! @page apihub_v1::ApiHubPluginClient-service-account-snippet Override apihub_v1::ApiHubPluginClient Authentication Defaults + +@snippet google/cloud/apihub/v1/samples/api_hub_plugin_client_samples.cc with-service-account + +*/ + +/*! @page apihub_v1::HostProjectRegistrationServiceClient-service-account-snippet Override apihub_v1::HostProjectRegistrationServiceClient Authentication Defaults + +@snippet google/cloud/apihub/v1/samples/host_project_registration_client_samples.cc with-service-account + +*/ + +/*! @page apihub_v1::LintingServiceClient-service-account-snippet Override apihub_v1::LintingServiceClient Authentication Defaults + +@snippet google/cloud/apihub/v1/samples/linting_client_samples.cc with-service-account + +*/ + +/*! @page apihub_v1::ProvisioningClient-service-account-snippet Override apihub_v1::ProvisioningClient Authentication Defaults + +@snippet google/cloud/apihub/v1/samples/provisioning_client_samples.cc with-service-account + +*/ + +/*! @page apihub_v1::RuntimeProjectAttachmentServiceClient-service-account-snippet Override apihub_v1::RuntimeProjectAttachmentServiceClient Authentication Defaults + +@snippet google/cloud/apihub/v1/samples/runtime_project_attachment_client_samples.cc with-service-account + +*/ +// diff --git a/google/cloud/apihub/doc/override-endpoint.dox b/google/cloud/apihub/doc/override-endpoint.dox new file mode 100644 index 0000000000000..0866dab41ebc2 --- /dev/null +++ b/google/cloud/apihub/doc/override-endpoint.dox @@ -0,0 +1,71 @@ +/*! +@page apihub-override-endpoint How to Override the Default Endpoint + +In some cases, you may need to override the default endpoint used by the client +library. Use the +[EndpointOption](@ref google::cloud::EndpointOption) when initializing the +client library to change this default. + + +For example, this will override the default endpoint for `apihub_v1::ApiHubClient`: + +@snippet api_hub_client_samples.cc set-client-endpoint + +Follow these links to find examples for other \c *Client classes: + +- [\c apihub_v1::ApiHubClient](@ref apihub_v1::ApiHubClient-endpoint-snippet) +- [\c apihub_v1::ApiHubDependenciesClient](@ref apihub_v1::ApiHubDependenciesClient-endpoint-snippet) +- [\c apihub_v1::ApiHubPluginClient](@ref apihub_v1::ApiHubPluginClient-endpoint-snippet) +- [\c apihub_v1::HostProjectRegistrationServiceClient](@ref apihub_v1::HostProjectRegistrationServiceClient-endpoint-snippet) +- [\c apihub_v1::LintingServiceClient](@ref apihub_v1::LintingServiceClient-endpoint-snippet) +- [\c apihub_v1::ProvisioningClient](@ref apihub_v1::ProvisioningClient-endpoint-snippet) +- [\c apihub_v1::RuntimeProjectAttachmentServiceClient](@ref apihub_v1::RuntimeProjectAttachmentServiceClient-endpoint-snippet) + + + +*/ + +// + +/*! @page apihub_v1::ApiHubClient-endpoint-snippet Override apihub_v1::ApiHubClient Endpoint Configuration + +@snippet google/cloud/apihub/v1/samples/api_hub_client_samples.cc set-client-endpoint + +*/ + +/*! @page apihub_v1::ApiHubDependenciesClient-endpoint-snippet Override apihub_v1::ApiHubDependenciesClient Endpoint Configuration + +@snippet google/cloud/apihub/v1/samples/api_hub_dependencies_client_samples.cc set-client-endpoint + +*/ + +/*! @page apihub_v1::ApiHubPluginClient-endpoint-snippet Override apihub_v1::ApiHubPluginClient Endpoint Configuration + +@snippet google/cloud/apihub/v1/samples/api_hub_plugin_client_samples.cc set-client-endpoint + +*/ + +/*! @page apihub_v1::HostProjectRegistrationServiceClient-endpoint-snippet Override apihub_v1::HostProjectRegistrationServiceClient Endpoint Configuration + +@snippet google/cloud/apihub/v1/samples/host_project_registration_client_samples.cc set-client-endpoint + +*/ + +/*! @page apihub_v1::LintingServiceClient-endpoint-snippet Override apihub_v1::LintingServiceClient Endpoint Configuration + +@snippet google/cloud/apihub/v1/samples/linting_client_samples.cc set-client-endpoint + +*/ + +/*! @page apihub_v1::ProvisioningClient-endpoint-snippet Override apihub_v1::ProvisioningClient Endpoint Configuration + +@snippet google/cloud/apihub/v1/samples/provisioning_client_samples.cc set-client-endpoint + +*/ + +/*! @page apihub_v1::RuntimeProjectAttachmentServiceClient-endpoint-snippet Override apihub_v1::RuntimeProjectAttachmentServiceClient Endpoint Configuration + +@snippet google/cloud/apihub/v1/samples/runtime_project_attachment_client_samples.cc set-client-endpoint + +*/ +// diff --git a/google/cloud/apihub/doc/override-retry-policies.dox b/google/cloud/apihub/doc/override-retry-policies.dox new file mode 100644 index 0000000000000..e155eed1ed3f9 --- /dev/null +++ b/google/cloud/apihub/doc/override-retry-policies.dox @@ -0,0 +1,186 @@ +/*! +@page apihub-override-retry Override Retry, Backoff, and Idempotency Policies + +When it is safe to do so, the library automatically retries requests that fail +due to a transient error. The library then uses [exponential backoff] to backoff +before trying again. Which operations are considered safe to retry, which +errors are treated as transient failures, the details of the exponential backoff +algorithm, and for how long the library retries are all configurable via +policies. + +This document provides examples showing how to override the default policies. + +The policies can be set when the `*Connection` object is created. The library +provides default policies for any policy that is not set. The application can +also override some (or all) policies when the `*Client` object is created. This +can be useful if multiple `*Client` objects share the same `*Connection` object, +but you want different retry behavior in some of the clients. Finally, the +application can override some retry policies when calling a specific member +function. + +The library uses three different options to control the retry loop. The options +have per-client names. + +@section apihub-override-retry-retry-policy Configuring the transient errors and retry duration + +The `*RetryPolicyOption` controls: + +- Which errors are to be treated as transient errors. +- How long the library will keep retrying transient errors. + +You can provide your own class for this option. The library also provides two +built-in policies: + +- `*LimitedErrorCountRetryPolicy`: stops retrying after a specified number + of transient errors. +- `*LimitedTimeRetryPolicy`: stops retrying after a specified time. + +Note that a library may have more than one version of these classes. Their name +match the `*Client` and `*Connection` object they are intended to be used +with. Some `*Client` objects treat different error codes as transient errors. +In most cases, only [kUnavailable](@ref google::cloud::StatusCode) is treated +as a transient error. + +@section apihub-override-retry-backoff-policy Controlling the backoff algorithm + +The `*BackoffPolicyOption` controls how long the client library will wait +before retrying a request that failed with a transient error. You can provide +your own class for this option. + +The only built-in backoff policy is +[`ExponentialBackoffPolicy`](@ref google::cloud::ExponentialBackoffPolicy). +This class implements a truncated exponential backoff algorithm, with jitter. +In summary, it doubles the current backoff time after each failure. The actual +backoff time for an RPC is chosen at random, but never exceeds the current +backoff. The current backoff is doubled after each failure, but never exceeds +(or is "truncated") if it reaches a prescribed maximum. + +@section apihub-override-retry-idempotency-policy Controlling which operations are retryable + +The `*IdempotencyPolicyOption` controls which requests are retryable, as some +requests are never safe to retry. + +Only one built-in idempotency policy is provided by the library. The name +matches the name of the client it is intended for. For example, `FooBarClient` +will use `FooBarIdempotencyPolicy`. This policy is very conservative. + +@section apihub-override-retry-example Example + + +For example, this will override the retry policies for `apihub_v1::ApiHubClient`: + +@snippet api_hub_client_samples.cc set-retry-policy + +This assumes you have created a custom idempotency policy. Such as: + +@snippet api_hub_client_samples.cc custom-idempotency-policy + + +Follow these links to find examples for other \c *Client classes: + +- [\c apihub_v1::ApiHubClient](@ref apihub_v1::ApiHubClient-retry-snippet) +- [\c apihub_v1::ApiHubDependenciesClient](@ref apihub_v1::ApiHubDependenciesClient-retry-snippet) +- [\c apihub_v1::ApiHubPluginClient](@ref apihub_v1::ApiHubPluginClient-retry-snippet) +- [\c apihub_v1::HostProjectRegistrationServiceClient](@ref apihub_v1::HostProjectRegistrationServiceClient-retry-snippet) +- [\c apihub_v1::LintingServiceClient](@ref apihub_v1::LintingServiceClient-retry-snippet) +- [\c apihub_v1::ProvisioningClient](@ref apihub_v1::ProvisioningClient-retry-snippet) +- [\c apihub_v1::RuntimeProjectAttachmentServiceClient](@ref apihub_v1::RuntimeProjectAttachmentServiceClient-retry-snippet) + + + +@section apihub-override-retry-more-information More Information + +@see google::cloud::Options +@see google::cloud::BackoffPolicy +@see google::cloud::ExponentialBackoffPolicy + +[exponential backoff]: https://en.wikipedia.org/wiki/Exponential_backoff + +*/ + +// + +/*! @page apihub_v1::ApiHubClient-retry-snippet Override apihub_v1::ApiHubClient Retry Policies + +This shows how to override the retry policies for apihub_v1::ApiHubClient: + +@snippet google/cloud/apihub/v1/samples/api_hub_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/apihub/v1/samples/api_hub_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page apihub_v1::ApiHubDependenciesClient-retry-snippet Override apihub_v1::ApiHubDependenciesClient Retry Policies + +This shows how to override the retry policies for apihub_v1::ApiHubDependenciesClient: + +@snippet google/cloud/apihub/v1/samples/api_hub_dependencies_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/apihub/v1/samples/api_hub_dependencies_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page apihub_v1::ApiHubPluginClient-retry-snippet Override apihub_v1::ApiHubPluginClient Retry Policies + +This shows how to override the retry policies for apihub_v1::ApiHubPluginClient: + +@snippet google/cloud/apihub/v1/samples/api_hub_plugin_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/apihub/v1/samples/api_hub_plugin_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page apihub_v1::HostProjectRegistrationServiceClient-retry-snippet Override apihub_v1::HostProjectRegistrationServiceClient Retry Policies + +This shows how to override the retry policies for apihub_v1::HostProjectRegistrationServiceClient: + +@snippet google/cloud/apihub/v1/samples/host_project_registration_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/apihub/v1/samples/host_project_registration_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page apihub_v1::LintingServiceClient-retry-snippet Override apihub_v1::LintingServiceClient Retry Policies + +This shows how to override the retry policies for apihub_v1::LintingServiceClient: + +@snippet google/cloud/apihub/v1/samples/linting_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/apihub/v1/samples/linting_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page apihub_v1::ProvisioningClient-retry-snippet Override apihub_v1::ProvisioningClient Retry Policies + +This shows how to override the retry policies for apihub_v1::ProvisioningClient: + +@snippet google/cloud/apihub/v1/samples/provisioning_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/apihub/v1/samples/provisioning_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page apihub_v1::RuntimeProjectAttachmentServiceClient-retry-snippet Override apihub_v1::RuntimeProjectAttachmentServiceClient Retry Policies + +This shows how to override the retry policies for apihub_v1::RuntimeProjectAttachmentServiceClient: + +@snippet google/cloud/apihub/v1/samples/runtime_project_attachment_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/apihub/v1/samples/runtime_project_attachment_client_samples.cc custom-idempotency-policy + +*/ +// diff --git a/google/cloud/apihub/quickstart/.bazelrc b/google/cloud/apihub/quickstart/.bazelrc new file mode 100644 index 0000000000000..e676fbffccb52 --- /dev/null +++ b/google/cloud/apihub/quickstart/.bazelrc @@ -0,0 +1,30 @@ +# Copyright 2024 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. + +# Use host-OS-specific config lines from bazelrc files. +build --enable_platform_specific_config=true + +# The project requires C++ >= 14. By default Bazel adds `-std=c++0x` which +# disables C++14 features, even if the compilers defaults to C++ >= 14 +build:linux --cxxopt=-std=c++14 +build:macos --cxxopt=-std=c++14 +# Protobuf and gRPC require (or soon will require) C++14 to compile the "host" +# targets, such as protoc and the grpc plugin. +build:linux --host_cxxopt=-std=c++14 +build:macos --host_cxxopt=-std=c++14 + +# Do not create the convenience links. They are inconvenient when the build +# runs inside a docker image or if one builds a quickstart and then builds +# the project separately. +build --experimental_convenience_symlinks=ignore diff --git a/google/cloud/apihub/quickstart/BUILD.bazel b/google/cloud/apihub/quickstart/BUILD.bazel new file mode 100644 index 0000000000000..22d9b72624f2b --- /dev/null +++ b/google/cloud/apihub/quickstart/BUILD.bazel @@ -0,0 +1,25 @@ +# Copyright 2024 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. + +licenses(["notice"]) # Apache 2.0 + +cc_binary( + name = "quickstart", + srcs = [ + "quickstart.cc", + ], + deps = [ + "@google_cloud_cpp//:apihub", + ], +) diff --git a/google/cloud/apihub/quickstart/CMakeLists.txt b/google/cloud/apihub/quickstart/CMakeLists.txt new file mode 100644 index 0000000000000..83389acb6c9e3 --- /dev/null +++ b/google/cloud/apihub/quickstart/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright 2024 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. + +# This file shows how to use the API hub API C++ client library from a larger +# CMake project. + +cmake_minimum_required(VERSION 3.10...3.24) +project(google-cloud-cpp-apihub-quickstart CXX) + +find_package(google_cloud_cpp_apihub REQUIRED) + +# MSVC requires some additional code to select the correct runtime library +if (VCPKG_TARGET_TRIPLET MATCHES "-static$") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +else () + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +endif () + +# Define your targets. +add_executable(quickstart quickstart.cc) +target_link_libraries(quickstart google-cloud-cpp::apihub) diff --git a/google/cloud/apihub/quickstart/Makefile b/google/cloud/apihub/quickstart/Makefile new file mode 100644 index 0000000000000..bd541d2cd6264 --- /dev/null +++ b/google/cloud/apihub/quickstart/Makefile @@ -0,0 +1,35 @@ +# Copyright 2024 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. + +# This is a minimal Makefile to show how to use the API hub API C++ client +# for developers who use make(1) as their build system. + +# The CXX, CXXFLAGS and CXXLD variables are hard-coded. These values work for +# our tests, but applications would typically make them configurable parameters. +CXX=g++ +CXXFLAGS= +CXXLD=$(CXX) +BIN=. + +all: $(BIN)/quickstart + +# Configuration variables to compile and link against the API hub API C++ +# client library. +CLIENT_MODULE := google_cloud_cpp_apihub +CLIENT_CXXFLAGS := $(shell pkg-config $(CLIENT_MODULE) --cflags) +CLIENT_CXXLDFLAGS := $(shell pkg-config $(CLIENT_MODULE) --libs-only-L) +CLIENT_LIBS := $(shell pkg-config $(CLIENT_MODULE) --libs-only-l) + +$(BIN)/quickstart: quickstart.cc + $(CXXLD) $(CXXFLAGS) $(CLIENT_CXXFLAGS) $(CLIENT_CXXLDFLAGS) -o $@ $^ $(CLIENT_LIBS) diff --git a/google/cloud/apihub/quickstart/README.md b/google/cloud/apihub/quickstart/README.md new file mode 100644 index 0000000000000..29422800b282d --- /dev/null +++ b/google/cloud/apihub/quickstart/README.md @@ -0,0 +1,154 @@ +# HOWTO: using the API hub API C++ client in your project + +This directory contains small examples showing how to use the API hub API C++ +client library in your own project. These instructions assume that you have some +experience as a C++ developer and that you have a working C++ toolchain +(compiler, linker, etc.) installed on your platform. + +- Packaging maintainers or developers who prefer to install the library in a + fixed directory (such as `/usr/local` or `/opt`) should consult the + [packaging guide](/doc/packaging.md). +- Developers who prefer using a package manager such as + [vcpkg](https://vcpkg.io), or [Conda](https://conda.io), should follow the + instructions for their package manager. +- Developers wanting to use the libraries as part of a larger CMake or Bazel + project should consult the current document. Note that there are similar + documents for each library in their corresponding directories. +- Developers wanting to compile the library just to run some examples or tests + should consult the + [building and installing](/README.md#building-and-installing) section of the + top-level README file. +- Contributors and developers to `google-cloud-cpp` should consult the guide to + [set up a development workstation][howto-setup-dev-workstation]. + +## Before you begin + +To run the quickstart examples you will need a working Google Cloud Platform +(GCP) project. The [quickstart][quickstart-link] covers the necessary steps in +detail. + +## Configuring authentication for the C++ Client Library + +Like most Google Cloud Platform (GCP) services, API hub API requires that your +application authenticates with the service before accessing any data. If you are +not familiar with GCP authentication please take this opportunity to review the +[Authentication Overview][authentication-quickstart]. This library uses the +`GOOGLE_APPLICATION_CREDENTIALS` environment variable to find the credentials +file. For example: + +| Shell | Command | +| :----------------- | ------------------------------------------------------------------------------------ | +| Bash/zsh/ksh/etc. | `export GOOGLE_APPLICATION_CREDENTIALS=[PATH]` | +| sh | `GOOGLE_APPLICATION_CREDENTIALS=[PATH];`
`export GOOGLE_APPLICATION_CREDENTIALS` | +| csh/tsch | `setenv GOOGLE_APPLICATION_CREDENTIALS [PATH]` | +| Windows Powershell | `$env:GOOGLE_APPLICATION_CREDENTIALS=[PATH]` | +| Windows cmd.exe | `set GOOGLE_APPLICATION_CREDENTIALS=[PATH]` | + +Setting this environment variable is the recommended way to configure the +authentication preferences, though if the environment variable is not set, the +library searches for a credentials file in the same location as the +[Cloud SDK](https://cloud.google.com/sdk/). For more information about +*Application Default Credentials*, see +https://cloud.google.com/docs/authentication/production + +## Using with Bazel + +> :warning: If you are using Windows or macOS there are additional instructions +> at the end of this document. + +1. Install Bazel using [the instructions][bazel-install] from the `bazel.build` + website. + +1. Compile this example using Bazel: + + ```bash + cd $HOME/google-cloud-cpp/google/cloud/apihub/quickstart + bazel build ... + ``` + + Note that Bazel automatically downloads and compiles all dependencies of the + project. As it is often the case with C++ libraries, compiling these + dependencies may take several minutes. + +1. Run the example, changing the placeholder(s) to appropriate values: + + ```bash + bazel run :quickstart -- [...] + ``` + +## Using with CMake + +> :warning: If you are using Windows or macOS there are additional instructions +> at the end of this document. + +1. Install CMake. The package managers for most Linux distributions include a + package for CMake. Likewise, you can install CMake on Windows using a package + manager such as [chocolatey][choco-cmake-link], and on macOS using + [homebrew][homebrew-cmake-link]. You can also obtain the software directly + from the [cmake.org](https://cmake.org/download/). + +1. Install the dependencies with your favorite tools. As an example, if you use + [vcpkg](https://github.com/Microsoft/vcpkg.git): + + ```bash + cd $HOME/vcpkg + ./vcpkg install google-cloud-cpp[core,apihub] + ``` + + Note that, as it is often the case with C++ libraries, compiling these + dependencies may take several minutes. + +1. Configure CMake, if necessary, configure the directory where you installed + the dependencies: + + ```bash + cd $HOME/google-cloud-cpp/google/cloud/apihub/quickstart + cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake + cmake --build .build + ``` + +1. Run the example, changing the placeholder(s) to appropriate values: + + ```bash + .build/quickstart [...] + ``` + +## Platform Specific Notes + +### macOS + +gRPC [requires][grpc-roots-pem-bug] an environment variable to configure the +trust store for SSL certificates, you can download and configure this using: + +```bash +curl -Lo roots.pem https://pki.google.com/roots.pem +export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH="$PWD/roots.pem" +``` + +### Windows + +Bazel tends to create very long file names and paths. You may need to use a +short directory to store the build output, such as `c:\b`, and instruct Bazel to +use it via: + +```shell +bazel --output_user_root=c:\b build ... +``` + +gRPC [requires][grpc-roots-pem-bug] an environment variable to configure the +trust store for SSL certificates, you can download and configure this using: + +```console +@powershell -NoProfile -ExecutionPolicy unrestricted -Command ^ + (new-object System.Net.WebClient).Downloadfile( ^ + 'https://pki.google.com/roots.pem', 'roots.pem') +set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=%cd%\roots.pem +``` + +[authentication-quickstart]: https://cloud.google.com/docs/authentication/getting-started "Authentication Getting Started" +[bazel-install]: https://docs.bazel.build/versions/main/install.html +[choco-cmake-link]: https://chocolatey.org/packages/cmake +[grpc-roots-pem-bug]: https://github.com/grpc/grpc/issues/16571 +[homebrew-cmake-link]: https://formulae.brew.sh/formula/cmake +[howto-setup-dev-workstation]: /doc/contributor/howto-guide-setup-development-workstation.md +[quickstart-link]: https://cloud.google.com/apigee/docs/apihub/quickstart-intro diff --git a/google/cloud/apihub/quickstart/WORKSPACE.bazel b/google/cloud/apihub/quickstart/WORKSPACE.bazel new file mode 100644 index 0000000000000..a4a1ef7c0692c --- /dev/null +++ b/google/cloud/apihub/quickstart/WORKSPACE.bazel @@ -0,0 +1,53 @@ +# Copyright 2024 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. + +# A minimal WORKSPACE file showing how to use the API hub API +# C++ client library in Bazel-based projects. +workspace(name = "qs") + +# Add the necessary Starlark functions to fetch google-cloud-cpp. +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# Fetch the Google Cloud C++ libraries. +# NOTE: Update this version and SHA256 as needed. +http_archive( + name = "google_cloud_cpp", + sha256 = "333fe00210ce1a6f0c1b51c232438a316eaf2c7a1724f75d0b2c64f8fc456aa7", + strip_prefix = "google-cloud-cpp-2.27.0", + url = "https://github.com/googleapis/google-cloud-cpp/archive/v2.27.0.tar.gz", +) + +load("@google_cloud_cpp//bazel:workspace0.bzl", "gl_cpp_workspace0") + +gl_cpp_workspace0() + +load("@google_cloud_cpp//bazel:workspace1.bzl", "gl_cpp_workspace1") + +gl_cpp_workspace1() + +load("@google_cloud_cpp//bazel:workspace2.bzl", "gl_cpp_workspace2") + +gl_cpp_workspace2() + +load("@google_cloud_cpp//bazel:workspace3.bzl", "gl_cpp_workspace3") + +gl_cpp_workspace3() + +load("@google_cloud_cpp//bazel:workspace4.bzl", "gl_cpp_workspace4") + +gl_cpp_workspace4() + +load("@google_cloud_cpp//bazel:workspace5.bzl", "gl_cpp_workspace5") + +gl_cpp_workspace5() diff --git a/google/cloud/apihub/quickstart/quickstart.cc b/google/cloud/apihub/quickstart/quickstart.cc new file mode 100644 index 0000000000000..068e13c67ad3b --- /dev/null +++ b/google/cloud/apihub/quickstart/quickstart.cc @@ -0,0 +1,41 @@ +// Copyright 2024 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. + +//! [all] +#include "google/cloud/apihub/v1/api_hub_client.h" +#include "google/cloud/location.h" +#include + +int main(int argc, char* argv[]) try { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " project-id location-id\n"; + return 1; + } + + auto const location = google::cloud::Location(argv[1], argv[2]); + + namespace apihub = ::google::cloud::apihub_v1; + auto client = apihub::ApiHubClient(apihub::MakeApiHubConnection()); + + for (auto r : client.ListApis(location.FullName())) { + if (!r) throw std::move(r).status(); + std::cout << r->DebugString() << "\n"; + } + + return 0; +} catch (google::cloud::Status const& status) { + std::cerr << "google::cloud::Status thrown: " << status << "\n"; + return 1; +} +//! [all] diff --git a/google/cloud/apihub/v1/.repo-metadata.json b/google/cloud/apihub/v1/.repo-metadata.json new file mode 100644 index 0000000000000..bc73e0b686d95 --- /dev/null +++ b/google/cloud/apihub/v1/.repo-metadata.json @@ -0,0 +1,14 @@ +{ + "api_id": "apihub.googleapis.com", + "api_shortname": "apihub", + "client_documentation": "https://cloud.google.com/cpp/docs/reference/apihub/latest", + "distribution_name": "google-cloud-cpp", + "issue_tracker": "https://issuetracker.google.com/issues?q=componentid:1447560%20status=open", + "language": "cpp", + "library_type": "GAPIC_AUTO", + "name_pretty": "API hub API", + "product_documentation": "https://cloud.google.com/apigee/docs/apihub/what-is-api-hub", + "release_level": "stable", + "repo": "googleapis/google-cloud-cpp", + "requires_billing": true +} diff --git a/google/cloud/apihub/v1/api_hub_client.cc b/google/cloud/apihub/v1/api_hub_client.cc new file mode 100644 index 0000000000000..d74f3a64805ef --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_client.cc @@ -0,0 +1,584 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubClient::ApiHubClient(std::shared_ptr connection, + Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +ApiHubClient::~ApiHubClient() = default; + +StatusOr ApiHubClient::CreateApi( + std::string const& parent, google::cloud::apihub::v1::Api const& api, + std::string const& api_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateApiRequest request; + request.set_parent(parent); + *request.mutable_api() = api; + request.set_api_id(api_id); + return connection_->CreateApi(request); +} + +StatusOr ApiHubClient::CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateApi(request); +} + +StatusOr ApiHubClient::GetApi( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetApiRequest request; + request.set_name(name); + return connection_->GetApi(request); +} + +StatusOr ApiHubClient::GetApi( + google::cloud::apihub::v1::GetApiRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetApi(request); +} + +StreamRange ApiHubClient::ListApis( + std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListApisRequest request; + request.set_parent(parent); + return connection_->ListApis(request); +} + +StreamRange ApiHubClient::ListApis( + google::cloud::apihub::v1::ListApisRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListApis(std::move(request)); +} + +StatusOr ApiHubClient::UpdateApi( + google::cloud::apihub::v1::Api const& api, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateApiRequest request; + *request.mutable_api() = api; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateApi(request); +} + +StatusOr ApiHubClient::UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateApi(request); +} + +Status ApiHubClient::DeleteApi(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteApiRequest request; + request.set_name(name); + return connection_->DeleteApi(request); +} + +Status ApiHubClient::DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteApi(request); +} + +StatusOr ApiHubClient::CreateVersion( + std::string const& parent, + google::cloud::apihub::v1::Version const& version, + std::string const& version_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateVersionRequest request; + request.set_parent(parent); + *request.mutable_version() = version; + request.set_version_id(version_id); + return connection_->CreateVersion(request); +} + +StatusOr ApiHubClient::CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateVersion(request); +} + +StatusOr ApiHubClient::GetVersion( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetVersionRequest request; + request.set_name(name); + return connection_->GetVersion(request); +} + +StatusOr ApiHubClient::GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetVersion(request); +} + +StreamRange ApiHubClient::ListVersions( + std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListVersionsRequest request; + request.set_parent(parent); + return connection_->ListVersions(request); +} + +StreamRange ApiHubClient::ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListVersions(std::move(request)); +} + +StatusOr ApiHubClient::UpdateVersion( + google::cloud::apihub::v1::Version const& version, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateVersionRequest request; + *request.mutable_version() = version; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateVersion(request); +} + +StatusOr ApiHubClient::UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateVersion(request); +} + +Status ApiHubClient::DeleteVersion(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteVersionRequest request; + request.set_name(name); + return connection_->DeleteVersion(request); +} + +Status ApiHubClient::DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteVersion(request); +} + +StatusOr ApiHubClient::CreateSpec( + std::string const& parent, google::cloud::apihub::v1::Spec const& spec, + std::string const& spec_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateSpecRequest request; + request.set_parent(parent); + *request.mutable_spec() = spec; + request.set_spec_id(spec_id); + return connection_->CreateSpec(request); +} + +StatusOr ApiHubClient::CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateSpec(request); +} + +StatusOr ApiHubClient::GetSpec( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetSpecRequest request; + request.set_name(name); + return connection_->GetSpec(request); +} + +StatusOr ApiHubClient::GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetSpec(request); +} + +StatusOr ApiHubClient::GetSpecContents( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetSpecContentsRequest request; + request.set_name(name); + return connection_->GetSpecContents(request); +} + +StatusOr ApiHubClient::GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetSpecContents(request); +} + +StreamRange ApiHubClient::ListSpecs( + std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListSpecsRequest request; + request.set_parent(parent); + return connection_->ListSpecs(request); +} + +StreamRange ApiHubClient::ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListSpecs(std::move(request)); +} + +StatusOr ApiHubClient::UpdateSpec( + google::cloud::apihub::v1::Spec const& spec, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateSpecRequest request; + *request.mutable_spec() = spec; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateSpec(request); +} + +StatusOr ApiHubClient::UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateSpec(request); +} + +Status ApiHubClient::DeleteSpec(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteSpecRequest request; + request.set_name(name); + return connection_->DeleteSpec(request); +} + +Status ApiHubClient::DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteSpec(request); +} + +StatusOr ApiHubClient::GetApiOperation( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetApiOperationRequest request; + request.set_name(name); + return connection_->GetApiOperation(request); +} + +StatusOr ApiHubClient::GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetApiOperation(request); +} + +StreamRange +ApiHubClient::ListApiOperations(std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListApiOperationsRequest request; + request.set_parent(parent); + return connection_->ListApiOperations(request); +} + +StreamRange +ApiHubClient::ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListApiOperations(std::move(request)); +} + +StatusOr ApiHubClient::GetDefinition( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetDefinitionRequest request; + request.set_name(name); + return connection_->GetDefinition(request); +} + +StatusOr ApiHubClient::GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetDefinition(request); +} + +StatusOr ApiHubClient::CreateDeployment( + std::string const& parent, + google::cloud::apihub::v1::Deployment const& deployment, + std::string const& deployment_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateDeploymentRequest request; + request.set_parent(parent); + *request.mutable_deployment() = deployment; + request.set_deployment_id(deployment_id); + return connection_->CreateDeployment(request); +} + +StatusOr ApiHubClient::CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateDeployment(request); +} + +StatusOr ApiHubClient::GetDeployment( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetDeploymentRequest request; + request.set_name(name); + return connection_->GetDeployment(request); +} + +StatusOr ApiHubClient::GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetDeployment(request); +} + +StreamRange +ApiHubClient::ListDeployments(std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListDeploymentsRequest request; + request.set_parent(parent); + return connection_->ListDeployments(request); +} + +StreamRange +ApiHubClient::ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListDeployments(std::move(request)); +} + +StatusOr ApiHubClient::UpdateDeployment( + google::cloud::apihub::v1::Deployment const& deployment, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateDeploymentRequest request; + *request.mutable_deployment() = deployment; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateDeployment(request); +} + +StatusOr ApiHubClient::UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateDeployment(request); +} + +Status ApiHubClient::DeleteDeployment(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteDeploymentRequest request; + request.set_name(name); + return connection_->DeleteDeployment(request); +} + +Status ApiHubClient::DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteDeployment(request); +} + +StatusOr ApiHubClient::CreateAttribute( + std::string const& parent, + google::cloud::apihub::v1::Attribute const& attribute, + std::string const& attribute_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateAttributeRequest request; + request.set_parent(parent); + *request.mutable_attribute() = attribute; + request.set_attribute_id(attribute_id); + return connection_->CreateAttribute(request); +} + +StatusOr ApiHubClient::CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateAttribute(request); +} + +StatusOr ApiHubClient::GetAttribute( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetAttributeRequest request; + request.set_name(name); + return connection_->GetAttribute(request); +} + +StatusOr ApiHubClient::GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetAttribute(request); +} + +StatusOr ApiHubClient::UpdateAttribute( + google::cloud::apihub::v1::Attribute const& attribute, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateAttributeRequest request; + *request.mutable_attribute() = attribute; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateAttribute(request); +} + +StatusOr ApiHubClient::UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateAttribute(request); +} + +Status ApiHubClient::DeleteAttribute(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteAttributeRequest request; + request.set_name(name); + return connection_->DeleteAttribute(request); +} + +Status ApiHubClient::DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteAttribute(request); +} + +StreamRange ApiHubClient::ListAttributes( + std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListAttributesRequest request; + request.set_parent(parent); + return connection_->ListAttributes(request); +} + +StreamRange ApiHubClient::ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListAttributes(std::move(request)); +} + +StreamRange +ApiHubClient::SearchResources(std::string const& location, + std::string const& query, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::SearchResourcesRequest request; + request.set_location(location); + request.set_query(query); + return connection_->SearchResources(request); +} + +StreamRange +ApiHubClient::SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->SearchResources(std::move(request)); +} + +StatusOr +ApiHubClient::CreateExternalApi( + std::string const& parent, + google::cloud::apihub::v1::ExternalApi const& external_api, + std::string const& external_api_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateExternalApiRequest request; + request.set_parent(parent); + *request.mutable_external_api() = external_api; + request.set_external_api_id(external_api_id); + return connection_->CreateExternalApi(request); +} + +StatusOr +ApiHubClient::CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateExternalApi(request); +} + +StatusOr ApiHubClient::GetExternalApi( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetExternalApiRequest request; + request.set_name(name); + return connection_->GetExternalApi(request); +} + +StatusOr ApiHubClient::GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetExternalApi(request); +} + +StatusOr +ApiHubClient::UpdateExternalApi( + google::cloud::apihub::v1::ExternalApi const& external_api, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateExternalApiRequest request; + *request.mutable_external_api() = external_api; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateExternalApi(request); +} + +StatusOr +ApiHubClient::UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateExternalApi(request); +} + +Status ApiHubClient::DeleteExternalApi(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteExternalApiRequest request; + request.set_name(name); + return connection_->DeleteExternalApi(request); +} + +Status ApiHubClient::DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteExternalApi(request); +} + +StreamRange +ApiHubClient::ListExternalApis(std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListExternalApisRequest request; + request.set_parent(parent); + return connection_->ListExternalApis(request); +} + +StreamRange +ApiHubClient::ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListExternalApis(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_client.h b/google/cloud/apihub/v1/api_hub_client.h new file mode 100644 index 0000000000000..6f1f3091c6064 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_client.h @@ -0,0 +1,2707 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CLIENT_H + +#include "google/cloud/apihub/v1/api_hub_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This service provides all methods related to the API hub. +/// +/// @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 ApiHubClient { + public: + explicit ApiHubClient(std::shared_ptr connection, + Options opts = {}); + ~ApiHubClient(); + + ///@{ + /// @name Copy and move support + ApiHubClient(ApiHubClient const&) = default; + ApiHubClient& operator=(ApiHubClient const&) = default; + ApiHubClient(ApiHubClient&&) = default; + ApiHubClient& operator=(ApiHubClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(ApiHubClient const& a, ApiHubClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(ApiHubClient const& a, ApiHubClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Create an API resource in the API hub. + /// Once an API resource is created, versions can be added to it. + /// + /// @param parent Required. The parent resource for the API resource. + /// Format: `projects/{project}/locations/{location}` + /// @param api Required. The API resource to create. + /// @param api_id Optional. The ID to use for the API resource, which will become the final + /// component of the API's resource name. This field is optional. + /// @n + /// * If provided, the same will be used. The service will throw an error if + /// the specified id is already used by another API resource in the API hub. + /// * If not provided, a system generated id will be used. + /// @n + /// This value should be 4-500 characters, and valid characters + /// are /[a-z][A-Z][0-9]-_/. + /// @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.apihub.v1.Api]) + /// 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.CreateApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L545} + /// + // clang-format on + StatusOr CreateApi( + std::string const& parent, google::cloud::apihub::v1::Api const& api, + std::string const& api_id, Options opts = {}); + + // clang-format off + /// + /// Create an API resource in the API hub. + /// Once an API resource is created, versions can be added to it. + /// + /// @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.apihub.v1.CreateApiRequest]. + /// 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.apihub.v1.Api]) + /// 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.CreateApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L545} + /// + // clang-format on + StatusOr CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get API resource details including the API versions contained in it. + /// + /// @param name Required. The name of the API resource to retrieve. + /// Format: `projects/{project}/locations/{location}/apis/{api}` + /// @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.apihub.v1.Api]) + /// 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.GetApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L571} + /// + // clang-format on + StatusOr GetApi(std::string const& name, + Options opts = {}); + + // clang-format off + /// + /// Get API resource details including the API versions contained in it. + /// + /// @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.apihub.v1.GetApiRequest]. + /// 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.apihub.v1.Api]) + /// 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.GetApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L571} + /// + // clang-format on + StatusOr GetApi( + google::cloud::apihub::v1::GetApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List API resources in the API hub. + /// + /// @param parent Required. The parent, which owns this collection of API resources. + /// Format: `projects/{project}/locations/{location}` + /// @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.cloud.apihub.v1.Api], 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.ListApisRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L609} + /// + // clang-format on + StreamRange ListApis( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List API resources in the API hub. + /// + /// @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.apihub.v1.ListApisRequest]. + /// 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.cloud.apihub.v1.Api], 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.ListApisRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L609} + /// + // clang-format on + StreamRange ListApis( + google::cloud::apihub::v1::ListApisRequest request, Options opts = {}); + + // clang-format off + /// + /// Update an API resource in the API hub. The following fields in the + /// [API][] can be updated: + /// + /// * [display_name][google.cloud.apihub.v1.Api.display_name] + /// * [description][google.cloud.apihub.v1.Api.description] + /// * [owner][google.cloud.apihub.v1.Api.owner] + /// * [documentation][google.cloud.apihub.v1.Api.documentation] + /// * [target_user][google.cloud.apihub.v1.Api.target_user] + /// * [team][google.cloud.apihub.v1.Api.team] + /// * [business_unit][google.cloud.apihub.v1.Api.business_unit] + /// * [maturity_level][google.cloud.apihub.v1.Api.maturity_level] + /// * [attributes][google.cloud.apihub.v1.Api.attributes] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateApiRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// Updating the owner field requires complete owner message + /// and updates both owner and email fields. + /// + /// @param api Required. The API resource to update. + /// @n + /// The API resource's `name` field is used to identify the API resource to + /// update. + /// Format: `projects/{project}/locations/{location}/apis/{api}` + /// @param update_mask Required. The list of fields to update. + /// @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.apihub.v1.Api]) + /// 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.Api.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L165} + /// [google.cloud.apihub.v1.Api.business_unit]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L149} + /// [google.cloud.apihub.v1.Api.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L96} + /// [google.cloud.apihub.v1.Api.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L93} + /// [google.cloud.apihub.v1.Api.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L99} + /// [google.cloud.apihub.v1.Api.maturity_level]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L159} + /// [google.cloud.apihub.v1.Api.owner]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L102} + /// [google.cloud.apihub.v1.Api.target_user]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L129} + /// [google.cloud.apihub.v1.Api.team]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L139} + /// [google.cloud.apihub.v1.UpdateApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L581} + /// [google.cloud.apihub.v1.UpdateApiRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L590} + /// + // clang-format on + StatusOr UpdateApi( + google::cloud::apihub::v1::Api const& api, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update an API resource in the API hub. The following fields in the + /// [API][] can be updated: + /// + /// * [display_name][google.cloud.apihub.v1.Api.display_name] + /// * [description][google.cloud.apihub.v1.Api.description] + /// * [owner][google.cloud.apihub.v1.Api.owner] + /// * [documentation][google.cloud.apihub.v1.Api.documentation] + /// * [target_user][google.cloud.apihub.v1.Api.target_user] + /// * [team][google.cloud.apihub.v1.Api.team] + /// * [business_unit][google.cloud.apihub.v1.Api.business_unit] + /// * [maturity_level][google.cloud.apihub.v1.Api.maturity_level] + /// * [attributes][google.cloud.apihub.v1.Api.attributes] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateApiRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// Updating the owner field requires complete owner message + /// and updates both owner and email fields. + /// + /// @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.apihub.v1.UpdateApiRequest]. + /// 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.apihub.v1.Api]) + /// 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 + /// [`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.apihub.v1.Api]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L78} + /// [google.cloud.apihub.v1.Api.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L165} + /// [google.cloud.apihub.v1.Api.business_unit]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L149} + /// [google.cloud.apihub.v1.Api.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L96} + /// [google.cloud.apihub.v1.Api.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L93} + /// [google.cloud.apihub.v1.Api.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L99} + /// [google.cloud.apihub.v1.Api.maturity_level]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L159} + /// [google.cloud.apihub.v1.Api.owner]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L102} + /// [google.cloud.apihub.v1.Api.target_user]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L129} + /// [google.cloud.apihub.v1.Api.team]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L139} + /// [google.cloud.apihub.v1.UpdateApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L581} + /// [google.cloud.apihub.v1.UpdateApiRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L590} + /// + // clang-format on + StatusOr UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Delete an API resource in the API hub. API can only be deleted if all + /// underlying versions are deleted. + /// + /// @param name Required. The name of the API resource to delete. + /// Format: `projects/{project}/locations/{location}/apis/{api}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L595} + /// + // clang-format on + Status DeleteApi(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Delete an API resource in the API hub. API can only be deleted if all + /// underlying versions are deleted. + /// + /// @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.apihub.v1.DeleteApiRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L595} + /// + // clang-format on + Status DeleteApi(google::cloud::apihub::v1::DeleteApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Create an API version for an API resource in the API hub. + /// + /// @param parent Required. The parent resource for API version. + /// Format: `projects/{project}/locations/{location}/apis/{api}` + /// @param version Required. The version to create. + /// @param version_id Optional. The ID to use for the API version, which will become the final + /// component of the version's resource name. This field is optional. + /// @n + /// * If provided, the same will be used. The service will throw an error if + /// the specified id is already used by another version in the API resource. + /// * If not provided, a system generated id will be used. + /// @n + /// This value should be 4-500 characters, and valid characters + /// are /[a-z][A-Z][0-9]-_/. + /// @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.apihub.v1.Version]) + /// 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 + /// [`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.apihub.v1.CreateVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L718} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// + // clang-format on + StatusOr CreateVersion( + std::string const& parent, + google::cloud::apihub::v1::Version const& version, + std::string const& version_id, Options opts = {}); + + // clang-format off + /// + /// Create an API version for an API resource in the API hub. + /// + /// @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.apihub.v1.CreateVersionRequest]. + /// 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.apihub.v1.Version]) + /// 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 + /// [`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.apihub.v1.CreateVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L718} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// + // clang-format on + StatusOr CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get details about the API version of an API resource. This will include + /// information about the specs and operations present in the API + /// version as well as the deployments linked to it. + /// + /// @param name Required. The name of the API version to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}` + /// @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.apihub.v1.Version]) + /// 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 + /// [`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.apihub.v1.GetVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L742} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// + // clang-format on + StatusOr GetVersion( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get details about the API version of an API resource. This will include + /// information about the specs and operations present in the API + /// version as well as the deployments linked to it. + /// + /// @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.apihub.v1.GetVersionRequest]. + /// 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.apihub.v1.Version]) + /// 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 + /// [`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.apihub.v1.GetVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L742} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// + // clang-format on + StatusOr GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List API versions of an API resource in the API hub. + /// + /// @param parent Required. The parent which owns this collection of API versions i.e., the + /// API resource Format: `projects/{project}/locations/{location}/apis/{api}` + /// @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.cloud.apihub.v1.Version], 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 + /// [`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.apihub.v1.ListVersionsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L785} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// + // clang-format on + StreamRange ListVersions( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List API versions of an API resource in the API hub. + /// + /// @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.apihub.v1.ListVersionsRequest]. + /// 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.cloud.apihub.v1.Version], 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 + /// [`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.apihub.v1.ListVersionsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L785} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// + // clang-format on + StreamRange ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request, + Options opts = {}); + + // clang-format off + /// + /// Update API version. The following fields in the + /// [version][google.cloud.apihub.v1.Version] can be updated currently: + /// + /// * [display_name][google.cloud.apihub.v1.Version.display_name] + /// * [description][google.cloud.apihub.v1.Version.description] + /// * [documentation][google.cloud.apihub.v1.Version.documentation] + /// * [deployments][google.cloud.apihub.v1.Version.deployments] + /// * [lifecycle][google.cloud.apihub.v1.Version.lifecycle] + /// * [compliance][google.cloud.apihub.v1.Version.compliance] + /// * [accreditation][google.cloud.apihub.v1.Version.accreditation] + /// * [attributes][google.cloud.apihub.v1.Version.attributes] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateVersionRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @param version Required. The API version to update. + /// @n + /// The version's `name` field is used to identify the API version to update. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}` + /// @param update_mask Required. The list of fields to update. + /// @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.apihub.v1.Version]) + /// 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 + /// [`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.apihub.v1.UpdateVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L754} + /// [google.cloud.apihub.v1.UpdateVersionRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L763} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// [google.cloud.apihub.v1.Version.accreditation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L292} + /// [google.cloud.apihub.v1.Version.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L298} + /// [google.cloud.apihub.v1.Version.compliance]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L282} + /// [google.cloud.apihub.v1.Version.deployments]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L249} + /// [google.cloud.apihub.v1.Version.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L208} + /// [google.cloud.apihub.v1.Version.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L205} + /// [google.cloud.apihub.v1.Version.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L211} + /// [google.cloud.apihub.v1.Version.lifecycle]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L272} + /// + // clang-format on + StatusOr UpdateVersion( + google::cloud::apihub::v1::Version const& version, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update API version. The following fields in the + /// [version][google.cloud.apihub.v1.Version] can be updated currently: + /// + /// * [display_name][google.cloud.apihub.v1.Version.display_name] + /// * [description][google.cloud.apihub.v1.Version.description] + /// * [documentation][google.cloud.apihub.v1.Version.documentation] + /// * [deployments][google.cloud.apihub.v1.Version.deployments] + /// * [lifecycle][google.cloud.apihub.v1.Version.lifecycle] + /// * [compliance][google.cloud.apihub.v1.Version.compliance] + /// * [accreditation][google.cloud.apihub.v1.Version.accreditation] + /// * [attributes][google.cloud.apihub.v1.Version.attributes] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateVersionRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @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.apihub.v1.UpdateVersionRequest]. + /// 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.apihub.v1.Version]) + /// 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 + /// [`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.apihub.v1.UpdateVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L754} + /// [google.cloud.apihub.v1.UpdateVersionRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L763} + /// [google.cloud.apihub.v1.Version]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L190} + /// [google.cloud.apihub.v1.Version.accreditation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L292} + /// [google.cloud.apihub.v1.Version.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L298} + /// [google.cloud.apihub.v1.Version.compliance]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L282} + /// [google.cloud.apihub.v1.Version.deployments]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L249} + /// [google.cloud.apihub.v1.Version.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L208} + /// [google.cloud.apihub.v1.Version.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L205} + /// [google.cloud.apihub.v1.Version.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L211} + /// [google.cloud.apihub.v1.Version.lifecycle]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L272} + /// + // clang-format on + StatusOr UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Delete an API version. Version can only be deleted if all underlying specs, + /// operations, definitions and linked deployments are deleted. + /// + /// @param name Required. The name of the version to delete. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L769} + /// + // clang-format on + Status DeleteVersion(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Delete an API version. Version can only be deleted if all underlying specs, + /// operations, definitions and linked deployments are deleted. + /// + /// @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.apihub.v1.DeleteVersionRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteVersionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L769} + /// + // clang-format on + Status DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Add a spec to an API version in the API hub. + /// Multiple specs can be added to an API version. + /// Note, while adding a spec, at least one of `contents` or `source_uri` must + /// be provided. If `contents` is provided, then `spec_type` must also be + /// provided. + /// + /// On adding a spec with contents to the version, the operations present in it + /// will be added to the version.Note that the file contents in the spec should + /// be of the same type as defined in the + /// `projects/{project}/locations/{location}/attributes/system-spec-type` + /// attribute associated with spec resource. Note that specs of various types + /// can be uploaded, however parsing of details is supported for OpenAPI spec + /// currently. + /// + /// In order to access the information parsed from the spec, use the + /// [GetSpec][google.cloud.apihub.v1.ApiHub.GetSpec] method. + /// In order to access the raw contents for a particular spec, use the + /// [GetSpecContents][google.cloud.apihub.v1.ApiHub.GetSpecContents] method. + /// In order to access the operations parsed from the spec, use the + /// [ListAPIOperations][google.cloud.apihub.v1.ApiHub.ListApiOperations] + /// method. + /// + /// @param parent Required. The parent resource for Spec. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}` + /// @param spec Required. The spec to create. + /// @param spec_id Optional. The ID to use for the spec, which will become the final component + /// of the spec's resource name. This field is optional. + /// @n + /// * If provided, the same will be used. The service will throw an error if + /// the specified id is already used by another spec in the API + /// resource. + /// * If not provided, a system generated id will be used. + /// @n + /// This value should be 4-500 characters, and valid characters + /// are /[a-z][A-Z][0-9]-_/. + /// @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.apihub.v1.Spec]) + /// 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 + /// [`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.apihub.v1.ApiHub.GetSpec]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L195} + /// [google.cloud.apihub.v1.ApiHub.GetSpecContents]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L203} + /// [google.cloud.apihub.v1.ApiHub.ListApiOperations]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L267} + /// [google.cloud.apihub.v1.CreateSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L882} + /// [google.cloud.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// + // clang-format on + StatusOr CreateSpec( + std::string const& parent, google::cloud::apihub::v1::Spec const& spec, + std::string const& spec_id, Options opts = {}); + + // clang-format off + /// + /// Add a spec to an API version in the API hub. + /// Multiple specs can be added to an API version. + /// Note, while adding a spec, at least one of `contents` or `source_uri` must + /// be provided. If `contents` is provided, then `spec_type` must also be + /// provided. + /// + /// On adding a spec with contents to the version, the operations present in it + /// will be added to the version.Note that the file contents in the spec should + /// be of the same type as defined in the + /// `projects/{project}/locations/{location}/attributes/system-spec-type` + /// attribute associated with spec resource. Note that specs of various types + /// can be uploaded, however parsing of details is supported for OpenAPI spec + /// currently. + /// + /// In order to access the information parsed from the spec, use the + /// [GetSpec][google.cloud.apihub.v1.ApiHub.GetSpec] method. + /// In order to access the raw contents for a particular spec, use the + /// [GetSpecContents][google.cloud.apihub.v1.ApiHub.GetSpecContents] method. + /// In order to access the operations parsed from the spec, use the + /// [ListAPIOperations][google.cloud.apihub.v1.ApiHub.ListApiOperations] + /// method. + /// + /// @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.apihub.v1.CreateSpecRequest]. + /// 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.apihub.v1.Spec]) + /// 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 + /// [`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.apihub.v1.ApiHub.GetSpec]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L195} + /// [google.cloud.apihub.v1.ApiHub.GetSpecContents]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L203} + /// [google.cloud.apihub.v1.ApiHub.ListApiOperations]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L267} + /// [google.cloud.apihub.v1.CreateSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L882} + /// [google.cloud.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// + // clang-format on + StatusOr CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get details about the information parsed from a spec. + /// Note that this method does not return the raw spec contents. + /// Use [GetSpecContents][google.cloud.apihub.v1.ApiHub.GetSpecContents] method + /// to retrieve the same. + /// + /// @param name Required. The name of the spec to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}` + /// @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.apihub.v1.Spec]) + /// 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 + /// [`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.apihub.v1.ApiHub.GetSpecContents]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L203} + /// [google.cloud.apihub.v1.GetSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L908} + /// [google.cloud.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// + // clang-format on + StatusOr GetSpec(std::string const& name, + Options opts = {}); + + // clang-format off + /// + /// Get details about the information parsed from a spec. + /// Note that this method does not return the raw spec contents. + /// Use [GetSpecContents][google.cloud.apihub.v1.ApiHub.GetSpecContents] method + /// to retrieve the same. + /// + /// @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.apihub.v1.GetSpecRequest]. + /// 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.apihub.v1.Spec]) + /// 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 + /// [`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.apihub.v1.ApiHub.GetSpecContents]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L203} + /// [google.cloud.apihub.v1.GetSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L908} + /// [google.cloud.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// + // clang-format on + StatusOr GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get spec contents. + /// + /// @param name Required. The name of the spec whose contents need to be retrieved. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}` + /// @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.apihub.v1.SpecContents]) + /// 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 + /// [`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.apihub.v1.GetSpecContentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1034} + /// [google.cloud.apihub.v1.SpecContents]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L757} + /// + // clang-format on + StatusOr GetSpecContents( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get spec contents. + /// + /// @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.apihub.v1.GetSpecContentsRequest]. + /// 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.apihub.v1.SpecContents]) + /// 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 + /// [`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.apihub.v1.GetSpecContentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1034} + /// [google.cloud.apihub.v1.SpecContents]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L757} + /// + // clang-format on + StatusOr GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List specs corresponding to a particular API resource. + /// + /// @param parent Required. The parent, which owns this collection of specs. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}` + /// @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.cloud.apihub.v1.Spec], 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 + /// [`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.apihub.v1.ListSpecsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L944} + /// [google.cloud.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// + // clang-format on + StreamRange ListSpecs( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List specs corresponding to a particular API resource. + /// + /// @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.apihub.v1.ListSpecsRequest]. + /// 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.cloud.apihub.v1.Spec], 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 + /// [`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.apihub.v1.ListSpecsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L944} + /// [google.cloud.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// + // clang-format on + StreamRange ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request, Options opts = {}); + + // clang-format off + /// + /// Update spec. The following fields in the + /// [spec][google.cloud.apihub.v1.Spec] can be updated: + /// + /// * [display_name][google.cloud.apihub.v1.Spec.display_name] + /// * [source_uri][google.cloud.apihub.v1.Spec.source_uri] + /// * [lint_response][google.cloud.apihub.v1.Spec.lint_response] + /// * [attributes][google.cloud.apihub.v1.Spec.attributes] + /// * [contents][google.cloud.apihub.v1.Spec.contents] + /// * [spec_type][google.cloud.apihub.v1.Spec.spec_type] + /// + /// In case of an OAS spec, updating spec contents can lead to: + /// 1. Creation, deletion and update of operations. + /// 2. Creation, deletion and update of definitions. + /// 3. Update of other info parsed out from the new spec. + /// + /// In case of contents or source_uri being present in update mask, spec_type + /// must also be present. Also, spec_type can not be present in update mask if + /// contents or source_uri is not present. + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateSpecRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @param spec Required. The spec to update. + /// @n + /// The spec's `name` field is used to identify the spec to + /// update. Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}` + /// @param update_mask Required. The list of fields to update. + /// @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.apihub.v1.Spec]) + /// 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 + /// [`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.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// [google.cloud.apihub.v1.Spec.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L394} + /// [google.cloud.apihub.v1.Spec.contents]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L367} + /// [google.cloud.apihub.v1.Spec.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L353} + /// [google.cloud.apihub.v1.Spec.lint_response]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L388} + /// [google.cloud.apihub.v1.Spec.source_uri]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L377} + /// [google.cloud.apihub.v1.Spec.spec_type]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L364} + /// [google.cloud.apihub.v1.UpdateSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L919} + /// [google.cloud.apihub.v1.UpdateSpecRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L928} + /// + // clang-format on + StatusOr UpdateSpec( + google::cloud::apihub::v1::Spec const& spec, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update spec. The following fields in the + /// [spec][google.cloud.apihub.v1.Spec] can be updated: + /// + /// * [display_name][google.cloud.apihub.v1.Spec.display_name] + /// * [source_uri][google.cloud.apihub.v1.Spec.source_uri] + /// * [lint_response][google.cloud.apihub.v1.Spec.lint_response] + /// * [attributes][google.cloud.apihub.v1.Spec.attributes] + /// * [contents][google.cloud.apihub.v1.Spec.contents] + /// * [spec_type][google.cloud.apihub.v1.Spec.spec_type] + /// + /// In case of an OAS spec, updating spec contents can lead to: + /// 1. Creation, deletion and update of operations. + /// 2. Creation, deletion and update of definitions. + /// 3. Update of other info parsed out from the new spec. + /// + /// In case of contents or source_uri being present in update mask, spec_type + /// must also be present. Also, spec_type can not be present in update mask if + /// contents or source_uri is not present. + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateSpecRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @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.apihub.v1.UpdateSpecRequest]. + /// 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.apihub.v1.Spec]) + /// 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 + /// [`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.apihub.v1.Spec]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L317} + /// [google.cloud.apihub.v1.Spec.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L394} + /// [google.cloud.apihub.v1.Spec.contents]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L367} + /// [google.cloud.apihub.v1.Spec.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L353} + /// [google.cloud.apihub.v1.Spec.lint_response]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L388} + /// [google.cloud.apihub.v1.Spec.source_uri]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L377} + /// [google.cloud.apihub.v1.Spec.spec_type]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L364} + /// [google.cloud.apihub.v1.UpdateSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L919} + /// [google.cloud.apihub.v1.UpdateSpecRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L928} + /// + // clang-format on + StatusOr UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Delete a spec. + /// Deleting a spec will also delete the associated operations from the + /// version. + /// + /// @param name Required. The name of the spec to delete. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}/specs/{spec}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L933} + /// + // clang-format on + Status DeleteSpec(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Delete a spec. + /// Deleting a spec will also delete the associated operations from the + /// version. + /// + /// @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.apihub.v1.DeleteSpecRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L933} + /// + // clang-format on + Status DeleteSpec(google::cloud::apihub::v1::DeleteSpecRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get details about a particular operation in API version. + /// + /// @param name Required. The name of the operation to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}/operations/{operation}` + /// @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.apihub.v1.ApiOperation]) + /// 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 + /// [`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.apihub.v1.ApiOperation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L503} + /// [google.cloud.apihub.v1.GetApiOperationRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1046} + /// + // clang-format on + StatusOr GetApiOperation( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get details about a particular operation in API version. + /// + /// @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.apihub.v1.GetApiOperationRequest]. + /// 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.apihub.v1.ApiOperation]) + /// 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 + /// [`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.apihub.v1.ApiOperation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L503} + /// [google.cloud.apihub.v1.GetApiOperationRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1046} + /// + // clang-format on + StatusOr GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List operations in an API version. + /// + /// @param parent Required. The parent which owns this collection of operations i.e., the API + /// version. Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}` + /// @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.cloud.apihub.v1.ApiOperation], 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 + /// [`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.apihub.v1.ApiOperation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L503} + /// [google.cloud.apihub.v1.ListApiOperationsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1060} + /// + // clang-format on + StreamRange ListApiOperations( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List operations in an API version. + /// + /// @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.apihub.v1.ListApiOperationsRequest]. + /// 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.cloud.apihub.v1.ApiOperation], 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 + /// [`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.apihub.v1.ApiOperation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L503} + /// [google.cloud.apihub.v1.ListApiOperationsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1060} + /// + // clang-format on + StreamRange ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request, + Options opts = {}); + + // clang-format off + /// + /// Get details about a definition in an API version. + /// + /// @param name Required. The name of the definition to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/apis/{api}/versions/{version}/definitions/{definition}` + /// @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.apihub.v1.Definition]) + /// 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 + /// [`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.apihub.v1.Definition]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L551} + /// [google.cloud.apihub.v1.GetDefinitionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1143} + /// + // clang-format on + StatusOr GetDefinition( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get details about a definition in an API version. + /// + /// @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.apihub.v1.GetDefinitionRequest]. + /// 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.apihub.v1.Definition]) + /// 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 + /// [`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.apihub.v1.Definition]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L551} + /// [google.cloud.apihub.v1.GetDefinitionRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1143} + /// + // clang-format on + StatusOr GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Create a deployment resource in the API hub. + /// Once a deployment resource is created, it can be associated with API + /// versions. + /// + /// @param parent Required. The parent resource for the deployment resource. + /// Format: `projects/{project}/locations/{location}` + /// @param deployment Required. The deployment resource to create. + /// @param deployment_id Optional. The ID to use for the deployment resource, which will become the + /// final component of the deployment's resource name. This field is optional. + /// @n + /// * If provided, the same will be used. The service will throw an error if + /// the specified id is already used by another deployment resource in the API + /// hub. + /// * If not provided, a system generated id will be used. + /// @n + /// This value should be 4-500 characters, and valid characters + /// are /[a-z][A-Z][0-9]-_/. + /// @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.apihub.v1.Deployment]) + /// 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 + /// [`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.apihub.v1.CreateDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1157} + /// [google.cloud.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// + // clang-format on + StatusOr CreateDeployment( + std::string const& parent, + google::cloud::apihub::v1::Deployment const& deployment, + std::string const& deployment_id, Options opts = {}); + + // clang-format off + /// + /// Create a deployment resource in the API hub. + /// Once a deployment resource is created, it can be associated with API + /// versions. + /// + /// @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.apihub.v1.CreateDeploymentRequest]. + /// 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.apihub.v1.Deployment]) + /// 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 + /// [`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.apihub.v1.CreateDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1157} + /// [google.cloud.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// + // clang-format on + StatusOr CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get details about a deployment and the API versions linked to it. + /// + /// @param name Required. The name of the deployment resource to retrieve. + /// Format: `projects/{project}/locations/{location}/deployments/{deployment}` + /// @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.apihub.v1.Deployment]) + /// 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 + /// [`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.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// [google.cloud.apihub.v1.GetDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1185} + /// + // clang-format on + StatusOr GetDeployment( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get details about a deployment and the API versions linked to it. + /// + /// @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.apihub.v1.GetDeploymentRequest]. + /// 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.apihub.v1.Deployment]) + /// 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 + /// [`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.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// [google.cloud.apihub.v1.GetDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1185} + /// + // clang-format on + StatusOr GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List deployment resources in the API hub. + /// + /// @param parent Required. The parent, which owns this collection of deployment resources. + /// Format: `projects/{project}/locations/{location}` + /// @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.cloud.apihub.v1.Deployment], 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 + /// [`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.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// [google.cloud.apihub.v1.ListDeploymentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1226} + /// + // clang-format on + StreamRange ListDeployments( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List deployment resources in the API hub. + /// + /// @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.apihub.v1.ListDeploymentsRequest]. + /// 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.cloud.apihub.v1.Deployment], 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 + /// [`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.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// [google.cloud.apihub.v1.ListDeploymentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1226} + /// + // clang-format on + StreamRange ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request, + Options opts = {}); + + // clang-format off + /// + /// Update a deployment resource in the API hub. The following fields in the + /// [deployment resource][google.cloud.apihub.v1.Deployment] can be + /// updated: + /// + /// * [display_name][google.cloud.apihub.v1.Deployment.display_name] + /// * [description][google.cloud.apihub.v1.Deployment.description] + /// * [documentation][google.cloud.apihub.v1.Deployment.documentation] + /// * [deployment_type][google.cloud.apihub.v1.Deployment.deployment_type] + /// * [resource_uri][google.cloud.apihub.v1.Deployment.resource_uri] + /// * [endpoints][google.cloud.apihub.v1.Deployment.endpoints] + /// * [slo][google.cloud.apihub.v1.Deployment.slo] + /// * [environment][google.cloud.apihub.v1.Deployment.environment] + /// * [attributes][google.cloud.apihub.v1.Deployment.attributes] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateDeploymentRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @param deployment Required. The deployment resource to update. + /// @n + /// The deployment resource's `name` field is used to identify the deployment + /// resource to update. + /// Format: `projects/{project}/locations/{location}/deployments/{deployment}` + /// @param update_mask Required. The list of fields to update. + /// @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.apihub.v1.Deployment]) + /// 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 + /// [`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.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// [google.cloud.apihub.v1.Deployment.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L494} + /// [google.cloud.apihub.v1.Deployment.deployment_type]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L445} + /// [google.cloud.apihub.v1.Deployment.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L432} + /// [google.cloud.apihub.v1.Deployment.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L429} + /// [google.cloud.apihub.v1.Deployment.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L435} + /// [google.cloud.apihub.v1.Deployment.endpoints]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L455} + /// [google.cloud.apihub.v1.Deployment.environment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L488} + /// [google.cloud.apihub.v1.Deployment.resource_uri]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L450} + /// [google.cloud.apihub.v1.Deployment.slo]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L478} + /// [google.cloud.apihub.v1.UpdateDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1198} + /// [google.cloud.apihub.v1.UpdateDeploymentRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1207} + /// + // clang-format on + StatusOr UpdateDeployment( + google::cloud::apihub::v1::Deployment const& deployment, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update a deployment resource in the API hub. The following fields in the + /// [deployment resource][google.cloud.apihub.v1.Deployment] can be + /// updated: + /// + /// * [display_name][google.cloud.apihub.v1.Deployment.display_name] + /// * [description][google.cloud.apihub.v1.Deployment.description] + /// * [documentation][google.cloud.apihub.v1.Deployment.documentation] + /// * [deployment_type][google.cloud.apihub.v1.Deployment.deployment_type] + /// * [resource_uri][google.cloud.apihub.v1.Deployment.resource_uri] + /// * [endpoints][google.cloud.apihub.v1.Deployment.endpoints] + /// * [slo][google.cloud.apihub.v1.Deployment.slo] + /// * [environment][google.cloud.apihub.v1.Deployment.environment] + /// * [attributes][google.cloud.apihub.v1.Deployment.attributes] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateDeploymentRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @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.apihub.v1.UpdateDeploymentRequest]. + /// 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.apihub.v1.Deployment]) + /// 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 + /// [`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.apihub.v1.Deployment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L414} + /// [google.cloud.apihub.v1.Deployment.attributes]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L494} + /// [google.cloud.apihub.v1.Deployment.deployment_type]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L445} + /// [google.cloud.apihub.v1.Deployment.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L432} + /// [google.cloud.apihub.v1.Deployment.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L429} + /// [google.cloud.apihub.v1.Deployment.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L435} + /// [google.cloud.apihub.v1.Deployment.endpoints]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L455} + /// [google.cloud.apihub.v1.Deployment.environment]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L488} + /// [google.cloud.apihub.v1.Deployment.resource_uri]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L450} + /// [google.cloud.apihub.v1.Deployment.slo]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L478} + /// [google.cloud.apihub.v1.UpdateDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1198} + /// [google.cloud.apihub.v1.UpdateDeploymentRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1207} + /// + // clang-format on + StatusOr UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Delete a deployment resource in the API hub. + /// + /// @param name Required. The name of the deployment resource to delete. + /// Format: `projects/{project}/locations/{location}/deployments/{deployment}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1213} + /// + // clang-format on + Status DeleteDeployment(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Delete a deployment resource in the API hub. + /// + /// @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.apihub.v1.DeleteDeploymentRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteDeploymentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1213} + /// + // clang-format on + Status DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Create a user defined attribute. + /// + /// Certain pre defined attributes are already created by the API hub. These + /// attributes will have type as `SYSTEM_DEFINED` and can be listed via + /// [ListAttributes][google.cloud.apihub.v1.ApiHub.ListAttributes] method. + /// Allowed values for the same can be updated via + /// [UpdateAttribute][google.cloud.apihub.v1.ApiHub.UpdateAttribute] method. + /// + /// @param parent Required. The parent resource for Attribute. + /// Format: `projects/{project}/locations/{location}` + /// @param attribute Required. The attribute to create. + /// @param attribute_id Optional. The ID to use for the attribute, which will become the final + /// component of the attribute's resource name. This field is optional. + /// @n + /// * If provided, the same will be used. The service will throw an error if + /// the specified id is already used by another attribute resource in the API + /// hub. + /// * If not provided, a system generated id will be used. + /// @n + /// This value should be 4-500 characters, and valid characters + /// are /[a-z][A-Z][0-9]-_/. + /// @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.apihub.v1.Attribute]) + /// 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 + /// [`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.apihub.v1.ApiHub.ListAttributes]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L412} + /// [google.cloud.apihub.v1.ApiHub.UpdateAttribute]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L391} + /// [google.cloud.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.CreateAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1323} + /// + // clang-format on + StatusOr CreateAttribute( + std::string const& parent, + google::cloud::apihub::v1::Attribute const& attribute, + std::string const& attribute_id, Options opts = {}); + + // clang-format off + /// + /// Create a user defined attribute. + /// + /// Certain pre defined attributes are already created by the API hub. These + /// attributes will have type as `SYSTEM_DEFINED` and can be listed via + /// [ListAttributes][google.cloud.apihub.v1.ApiHub.ListAttributes] method. + /// Allowed values for the same can be updated via + /// [UpdateAttribute][google.cloud.apihub.v1.ApiHub.UpdateAttribute] method. + /// + /// @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.apihub.v1.CreateAttributeRequest]. + /// 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.apihub.v1.Attribute]) + /// 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 + /// [`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.apihub.v1.ApiHub.ListAttributes]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L412} + /// [google.cloud.apihub.v1.ApiHub.UpdateAttribute]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L391} + /// [google.cloud.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.CreateAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1323} + /// + // clang-format on + StatusOr CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get details about the attribute. + /// + /// @param name Required. The name of the attribute to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/attributes/{attribute}` + /// @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.apihub.v1.Attribute]) + /// 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 + /// [`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.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.GetAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1351} + /// + // clang-format on + StatusOr GetAttribute( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get details about the attribute. + /// + /// @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.apihub.v1.GetAttributeRequest]. + /// 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.apihub.v1.Attribute]) + /// 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 + /// [`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.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.GetAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1351} + /// + // clang-format on + StatusOr GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Update the attribute. The following fields in the + /// [Attribute resource][google.cloud.apihub.v1.Attribute] can be updated: + /// + /// * [display_name][google.cloud.apihub.v1.Attribute.display_name] + /// The display name can be updated for user defined attributes only. + /// * [description][google.cloud.apihub.v1.Attribute.description] + /// The description can be updated for user defined attributes only. + /// * [allowed_values][google.cloud.apihub.v1.Attribute.allowed_values] + /// To update the list of allowed values, clients need to use the fetched list + /// of allowed values and add or remove values to or from the same list. + /// The mutable allowed values can be updated for both user defined and System + /// defined attributes. The immutable allowed values cannot be updated or + /// deleted. The updated list of allowed values cannot be empty. If an allowed + /// value that is already used by some resource's attribute is deleted, then + /// the association between the resource and the attribute value will also be + /// deleted. + /// * [cardinality][google.cloud.apihub.v1.Attribute.cardinality] + /// The cardinality can be updated for user defined attributes only. + /// Cardinality can only be increased during an update. + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateAttributeRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @param attribute Required. The attribute to update. + /// @n + /// The attribute's `name` field is used to identify the attribute to update. + /// Format: + /// `projects/{project}/locations/{location}/attributes/{attribute}` + /// @param update_mask Required. The list of fields to update. + /// @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.apihub.v1.Attribute]) + /// 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 + /// [`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.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.Attribute.allowed_values]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L732} + /// [google.cloud.apihub.v1.Attribute.cardinality]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L740} + /// [google.cloud.apihub.v1.Attribute.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L716} + /// [google.cloud.apihub.v1.Attribute.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L713} + /// [google.cloud.apihub.v1.UpdateAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1365} + /// [google.cloud.apihub.v1.UpdateAttributeRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1374} + /// + // clang-format on + StatusOr UpdateAttribute( + google::cloud::apihub::v1::Attribute const& attribute, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update the attribute. The following fields in the + /// [Attribute resource][google.cloud.apihub.v1.Attribute] can be updated: + /// + /// * [display_name][google.cloud.apihub.v1.Attribute.display_name] + /// The display name can be updated for user defined attributes only. + /// * [description][google.cloud.apihub.v1.Attribute.description] + /// The description can be updated for user defined attributes only. + /// * [allowed_values][google.cloud.apihub.v1.Attribute.allowed_values] + /// To update the list of allowed values, clients need to use the fetched list + /// of allowed values and add or remove values to or from the same list. + /// The mutable allowed values can be updated for both user defined and System + /// defined attributes. The immutable allowed values cannot be updated or + /// deleted. The updated list of allowed values cannot be empty. If an allowed + /// value that is already used by some resource's attribute is deleted, then + /// the association between the resource and the attribute value will also be + /// deleted. + /// * [cardinality][google.cloud.apihub.v1.Attribute.cardinality] + /// The cardinality can be updated for user defined attributes only. + /// Cardinality can only be increased during an update. + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateAttributeRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @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.apihub.v1.UpdateAttributeRequest]. + /// 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.apihub.v1.Attribute]) + /// 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 + /// [`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.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.Attribute.allowed_values]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L732} + /// [google.cloud.apihub.v1.Attribute.cardinality]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L740} + /// [google.cloud.apihub.v1.Attribute.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L716} + /// [google.cloud.apihub.v1.Attribute.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L713} + /// [google.cloud.apihub.v1.UpdateAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1365} + /// [google.cloud.apihub.v1.UpdateAttributeRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1374} + /// + // clang-format on + StatusOr UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Delete an attribute. + /// + /// Note: System defined attributes cannot be deleted. All + /// associations of the attribute being deleted with any API hub resource will + /// also get deleted. + /// + /// @param name Required. The name of the attribute to delete. + /// Format: + /// `projects/{project}/locations/{location}/attributes/{attribute}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1380} + /// + // clang-format on + Status DeleteAttribute(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Delete an attribute. + /// + /// Note: System defined attributes cannot be deleted. All + /// associations of the attribute being deleted with any API hub resource will + /// also get deleted. + /// + /// @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.apihub.v1.DeleteAttributeRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteAttributeRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1380} + /// + // clang-format on + Status DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List all attributes. + /// + /// @param parent Required. The parent resource for Attribute. + /// Format: `projects/{project}/locations/{location}` + /// @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.cloud.apihub.v1.Attribute], 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 + /// [`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.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.ListAttributesRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1394} + /// + // clang-format on + StreamRange ListAttributes( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List all attributes. + /// + /// @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.apihub.v1.ListAttributesRequest]. + /// 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.cloud.apihub.v1.Attribute], 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 + /// [`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.apihub.v1.Attribute]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L610} + /// [google.cloud.apihub.v1.ListAttributesRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1394} + /// + // clang-format on + StreamRange ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request, + Options opts = {}); + + // clang-format off + /// + /// Search across API-Hub resources. + /// + /// @param location Required. The resource name of the location which will be of the type + /// `projects/{project_id}/locations/{location_id}`. This field is used to + /// identify the instance of API-Hub in which resources should be searched. + /// @param query Required. The free text search query. This query can contain keywords which + /// could be related to any detail of the API-Hub resources such display names, + /// descriptions, attributes etc. + /// @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.cloud.apihub.v1.SearchResult], 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 + /// [`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.apihub.v1.SearchResourcesRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1476} + /// [google.cloud.apihub.v1.SearchResult]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1562} + /// + // clang-format on + StreamRange SearchResources( + std::string const& location, std::string const& query, Options opts = {}); + + // clang-format off + /// + /// Search across API-Hub resources. + /// + /// @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.apihub.v1.SearchResourcesRequest]. + /// 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.cloud.apihub.v1.SearchResult], 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 + /// [`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.apihub.v1.SearchResourcesRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1476} + /// [google.cloud.apihub.v1.SearchResult]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1562} + /// + // clang-format on + StreamRange SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request, + Options opts = {}); + + // clang-format off + /// + /// Create an External API resource in the API hub. + /// + /// @param parent Required. The parent resource for the External API resource. + /// Format: `projects/{project}/locations/{location}` + /// @param external_api Required. The External API resource to create. + /// @param external_api_id Optional. The ID to use for the External API resource, which will become + /// the final component of the External API's resource name. This field is + /// optional. + /// @n + /// * If provided, the same will be used. The service will throw an error if + /// the specified id is already used by another External API resource in the + /// API hub. + /// * If not provided, a system generated id will be used. + /// @n + /// This value should be 4-500 characters, and valid characters + /// are /[a-z][A-Z][0-9]-_/. + /// @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.apihub.v1.ExternalApi]) + /// 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 + /// [`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.apihub.v1.CreateExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1729} + /// [google.cloud.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// + // clang-format on + StatusOr CreateExternalApi( + std::string const& parent, + google::cloud::apihub::v1::ExternalApi const& external_api, + std::string const& external_api_id, Options opts = {}); + + // clang-format off + /// + /// Create an External API resource in the API hub. + /// + /// @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.apihub.v1.CreateExternalApiRequest]. + /// 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.apihub.v1.ExternalApi]) + /// 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 + /// [`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.apihub.v1.CreateExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1729} + /// [google.cloud.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// + // clang-format on + StatusOr CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get details about an External API resource in the API hub. + /// + /// @param name Required. The name of the External API resource to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/externalApis/{externalApi}` + /// @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.apihub.v1.ExternalApi]) + /// 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 + /// [`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.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// [google.cloud.apihub.v1.GetExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1758} + /// + // clang-format on + StatusOr GetExternalApi( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get details about an External API resource in the API hub. + /// + /// @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.apihub.v1.GetExternalApiRequest]. + /// 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.apihub.v1.ExternalApi]) + /// 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 + /// [`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.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// [google.cloud.apihub.v1.GetExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1758} + /// + // clang-format on + StatusOr GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Update an External API resource in the API hub. The following fields can be + /// updated: + /// + /// * [display_name][google.cloud.apihub.v1.ExternalApi.display_name] + /// * [description][google.cloud.apihub.v1.ExternalApi.description] + /// * [documentation][google.cloud.apihub.v1.ExternalApi.documentation] + /// * [endpoints][google.cloud.apihub.v1.ExternalApi.endpoints] + /// * [paths][google.cloud.apihub.v1.ExternalApi.paths] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateExternalApiRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @param external_api Required. The External API resource to update. + /// @n + /// The External API resource's `name` field is used to identify the External + /// API resource to update. Format: + /// `projects/{project}/locations/{location}/externalApis/{externalApi}` + /// @param update_mask Required. The list of fields to update. + /// @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.apihub.v1.ExternalApi]) + /// 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 + /// [`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.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// [google.cloud.apihub.v1.ExternalApi.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1272} + /// [google.cloud.apihub.v1.ExternalApi.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1268} + /// [google.cloud.apihub.v1.ExternalApi.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1281} + /// [google.cloud.apihub.v1.ExternalApi.endpoints]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1275} + /// [google.cloud.apihub.v1.ExternalApi.paths]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1278} + /// [google.cloud.apihub.v1.UpdateExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1772} + /// [google.cloud.apihub.v1.UpdateExternalApiRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1781} + /// + // clang-format on + StatusOr UpdateExternalApi( + google::cloud::apihub::v1::ExternalApi const& external_api, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update an External API resource in the API hub. The following fields can be + /// updated: + /// + /// * [display_name][google.cloud.apihub.v1.ExternalApi.display_name] + /// * [description][google.cloud.apihub.v1.ExternalApi.description] + /// * [documentation][google.cloud.apihub.v1.ExternalApi.documentation] + /// * [endpoints][google.cloud.apihub.v1.ExternalApi.endpoints] + /// * [paths][google.cloud.apihub.v1.ExternalApi.paths] + /// + /// The + /// [update_mask][google.cloud.apihub.v1.UpdateExternalApiRequest.update_mask] + /// should be used to specify the fields being updated. + /// + /// @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.apihub.v1.UpdateExternalApiRequest]. + /// 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.apihub.v1.ExternalApi]) + /// 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 + /// [`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.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// [google.cloud.apihub.v1.ExternalApi.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1272} + /// [google.cloud.apihub.v1.ExternalApi.display_name]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1268} + /// [google.cloud.apihub.v1.ExternalApi.documentation]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1281} + /// [google.cloud.apihub.v1.ExternalApi.endpoints]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1275} + /// [google.cloud.apihub.v1.ExternalApi.paths]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1278} + /// [google.cloud.apihub.v1.UpdateExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1772} + /// [google.cloud.apihub.v1.UpdateExternalApiRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1781} + /// + // clang-format on + StatusOr UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Delete an External API resource in the API hub. + /// + /// @param name Required. The name of the External API resource to delete. + /// Format: + /// `projects/{project}/locations/{location}/externalApis/{externalApi}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1787} + /// + // clang-format on + Status DeleteExternalApi(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Delete an External API resource in the API hub. + /// + /// @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.apihub.v1.DeleteExternalApiRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteExternalApiRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1787} + /// + // clang-format on + Status DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List External API resources in the API hub. + /// + /// @param parent Required. The parent, which owns this collection of External API resources. + /// Format: `projects/{project}/locations/{location}` + /// @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.cloud.apihub.v1.ExternalApi], 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 + /// [`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.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// [google.cloud.apihub.v1.ListExternalApisRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1801} + /// + // clang-format on + StreamRange ListExternalApis( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List External API resources in the API hub. + /// + /// @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.apihub.v1.ListExternalApisRequest]. + /// 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.cloud.apihub.v1.ExternalApi], 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 + /// [`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.apihub.v1.ExternalApi]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1254} + /// [google.cloud.apihub.v1.ListExternalApisRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1801} + /// + // clang-format on + StreamRange ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CLIENT_H diff --git a/google/cloud/apihub/v1/api_hub_connection.cc b/google/cloud/apihub/v1/api_hub_connection.cc new file mode 100644 index 0000000000000..3b4eda4535bfd --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_connection.cc @@ -0,0 +1,263 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_connection.h" +#include "google/cloud/apihub/v1/api_hub_options.h" +#include "google/cloud/apihub/v1/internal/api_hub_connection_impl.h" +#include "google/cloud/apihub/v1/internal/api_hub_option_defaults.h" +#include "google/cloud/apihub/v1/internal/api_hub_stub_factory.h" +#include "google/cloud/apihub/v1/internal/api_hub_tracing_connection.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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubConnection::~ApiHubConnection() = default; + +StatusOr ApiHubConnection::CreateApi( + google::cloud::apihub::v1::CreateApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr ApiHubConnection::GetApi( + google::cloud::apihub::v1::GetApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange ApiHubConnection::ListApis( + google::cloud::apihub::v1:: + ListApisRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr ApiHubConnection::UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ApiHubConnection::DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr ApiHubConnection::CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr ApiHubConnection::GetVersion( + google::cloud::apihub::v1::GetVersionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange ApiHubConnection::ListVersions( + google::cloud::apihub::v1:: + ListVersionsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr ApiHubConnection::UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ApiHubConnection::DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr ApiHubConnection::CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr ApiHubConnection::GetSpec( + google::cloud::apihub::v1::GetSpecRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubConnection::GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange ApiHubConnection::ListSpecs( + google::cloud::apihub::v1:: + ListSpecsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr ApiHubConnection::UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ApiHubConnection::DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubConnection::GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +ApiHubConnection::ListApiOperations( + google::cloud::apihub::v1:: + ListApiOperationsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr ApiHubConnection::GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubConnection::CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr ApiHubConnection::GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +ApiHubConnection::ListDeployments( + google::cloud::apihub::v1:: + ListDeploymentsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr +ApiHubConnection::UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ApiHubConnection::DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubConnection::CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr ApiHubConnection::GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubConnection::UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ApiHubConnection::DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +ApiHubConnection::ListAttributes( + google::cloud::apihub::v1:: + ListAttributesRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StreamRange +ApiHubConnection::SearchResources( + google::cloud::apihub::v1:: + SearchResourcesRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr +ApiHubConnection::CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubConnection::GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubConnection::UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ApiHubConnection::DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +ApiHubConnection::ListExternalApis( + google::cloud::apihub::v1:: + ListExternalApisRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +std::shared_ptr MakeApiHubConnection(Options options) { + internal::CheckExpectedOptions(options, __func__); + options = apihub_v1_internal::ApiHubDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); + auto stub = + apihub_v1_internal::CreateDefaultApiHubStub(std::move(auth), options); + return apihub_v1_internal::MakeApiHubTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_connection.h b/google/cloud/apihub/v1/api_hub_connection.h new file mode 100644 index 0000000000000..c50af7eb22697 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_connection.h @@ -0,0 +1,316 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/internal/api_hub_retry_traits.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/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `ApiHubConnection`. +class ApiHubRetryPolicy : 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 `ApiHubConnection` 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 ApiHubLimitedErrorCountRetryPolicy : public ApiHubRetryPolicy { + 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 ApiHubLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ApiHubLimitedErrorCountRetryPolicy( + ApiHubLimitedErrorCountRetryPolicy&& rhs) noexcept + : ApiHubLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ApiHubLimitedErrorCountRetryPolicy( + ApiHubLimitedErrorCountRetryPolicy const& rhs) noexcept + : ApiHubLimitedErrorCountRetryPolicy(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 = ApiHubRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apihub_v1_internal::ApiHubRetryTraits> + impl_; +}; + +/** + * A retry policy for `ApiHubConnection` 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 ApiHubLimitedTimeRetryPolicy : public ApiHubRetryPolicy { + 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 ApiHubLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ApiHubLimitedTimeRetryPolicy(ApiHubLimitedTimeRetryPolicy&& rhs) noexcept + : ApiHubLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ApiHubLimitedTimeRetryPolicy(ApiHubLimitedTimeRetryPolicy const& rhs) noexcept + : ApiHubLimitedTimeRetryPolicy(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 = ApiHubRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apihub_v1_internal::ApiHubRetryTraits> + impl_; +}; + +/** + * The `ApiHubConnection` object for `ApiHubClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `ApiHubClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `ApiHubClient`. + * + * To create a concrete instance, see `MakeApiHubConnection()`. + * + * For mocking, see `apihub_v1_mocks::MockApiHubConnection`. + */ +class ApiHubConnection { + public: + virtual ~ApiHubConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request); + + virtual StatusOr GetApi( + google::cloud::apihub::v1::GetApiRequest const& request); + + virtual StreamRange ListApis( + google::cloud::apihub::v1::ListApisRequest request); + + virtual StatusOr UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request); + + virtual Status DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const& request); + + virtual StatusOr CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request); + + virtual StatusOr GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request); + + virtual StreamRange ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request); + + virtual StatusOr UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request); + + virtual Status DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request); + + virtual StatusOr CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request); + + virtual StatusOr GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request); + + virtual StatusOr GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request); + + virtual StreamRange ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request); + + virtual StatusOr UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request); + + virtual Status DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const& request); + + virtual StatusOr GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request); + + virtual StreamRange + ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request); + + virtual StatusOr GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request); + + virtual StatusOr CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request); + + virtual StatusOr GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request); + + virtual StreamRange ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request); + + virtual StatusOr UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request); + + virtual Status DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request); + + virtual StatusOr CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request); + + virtual StatusOr GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request); + + virtual StatusOr UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request); + + virtual Status DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request); + + virtual StreamRange ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request); + + virtual StreamRange SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request); + + virtual StatusOr CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request); + + virtual StatusOr GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request); + + virtual StatusOr UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request); + + virtual Status DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request); + + virtual StreamRange ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest request); +}; + +/** + * A factory function to construct an object of type `ApiHubConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of ApiHubClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `ApiHubConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::apihub_v1::ApiHubPolicyOptionList` + * + * @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 `ApiHubConnection` created by + * this function. + */ +std::shared_ptr MakeApiHubConnection(Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CONNECTION_H diff --git a/google/cloud/apihub/v1/api_hub_connection_idempotency_policy.cc b/google/cloud/apihub/v1/api_hub_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..fbfd52f541176 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_connection_idempotency_policy.cc @@ -0,0 +1,220 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +ApiHubConnectionIdempotencyPolicy::~ApiHubConnectionIdempotencyPolicy() = + default; + +std::unique_ptr +ApiHubConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency ApiHubConnectionIdempotencyPolicy::CreateApi( + google::cloud::apihub::v1::CreateApiRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetApi( + google::cloud::apihub::v1::GetApiRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::ListApis( + google::cloud::apihub::v1::ListApisRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetVersion( + google::cloud::apihub::v1::GetVersionRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::ListVersions( + google::cloud::apihub::v1::ListVersionsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetSpec( + google::cloud::apihub::v1::GetSpecRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest) { // NOLINT + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubConnectionIdempotencyPolicy::ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultApiHubConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_connection_idempotency_policy.h b/google/cloud/apihub/v1/api_hub_connection_idempotency_policy.h new file mode 100644 index 0000000000000..e4eee761b8756 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_connection_idempotency_policy.h @@ -0,0 +1,153 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubConnectionIdempotencyPolicy { + public: + virtual ~ApiHubConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() const; + + virtual google::cloud::Idempotency CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request); + + virtual google::cloud::Idempotency GetApi( + google::cloud::apihub::v1::GetApiRequest const& request); + + virtual google::cloud::Idempotency ListApis( + google::cloud::apihub::v1::ListApisRequest request); + + virtual google::cloud::Idempotency UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request); + + virtual google::cloud::Idempotency DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const& request); + + virtual google::cloud::Idempotency CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request); + + virtual google::cloud::Idempotency GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request); + + virtual google::cloud::Idempotency ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request); + + virtual google::cloud::Idempotency UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request); + + virtual google::cloud::Idempotency DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request); + + virtual google::cloud::Idempotency CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request); + + virtual google::cloud::Idempotency GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request); + + virtual google::cloud::Idempotency GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request); + + virtual google::cloud::Idempotency ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request); + + virtual google::cloud::Idempotency UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request); + + virtual google::cloud::Idempotency DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const& request); + + virtual google::cloud::Idempotency GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request); + + virtual google::cloud::Idempotency ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request); + + virtual google::cloud::Idempotency GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request); + + virtual google::cloud::Idempotency CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request); + + virtual google::cloud::Idempotency GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request); + + virtual google::cloud::Idempotency ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request); + + virtual google::cloud::Idempotency UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request); + + virtual google::cloud::Idempotency DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request); + + virtual google::cloud::Idempotency CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request); + + virtual google::cloud::Idempotency GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request); + + virtual google::cloud::Idempotency UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request); + + virtual google::cloud::Idempotency DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request); + + virtual google::cloud::Idempotency ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request); + + virtual google::cloud::Idempotency SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request); + + virtual google::cloud::Idempotency CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request); + + virtual google::cloud::Idempotency GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request); + + virtual google::cloud::Idempotency UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request); + + virtual google::cloud::Idempotency DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request); + + virtual google::cloud::Idempotency ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest request); +}; + +std::unique_ptr +MakeDefaultApiHubConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/apihub/v1/api_hub_dependencies_client.cc b/google/cloud/apihub/v1/api_hub_dependencies_client.cc new file mode 100644 index 0000000000000..a451fab84d578 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_dependencies_client.cc @@ -0,0 +1,125 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_dependencies_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubDependenciesClient::ApiHubDependenciesClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +ApiHubDependenciesClient::~ApiHubDependenciesClient() = default; + +StatusOr +ApiHubDependenciesClient::CreateDependency( + std::string const& parent, + google::cloud::apihub::v1::Dependency const& dependency, + std::string const& dependency_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateDependencyRequest request; + request.set_parent(parent); + *request.mutable_dependency() = dependency; + request.set_dependency_id(dependency_id); + return connection_->CreateDependency(request); +} + +StatusOr +ApiHubDependenciesClient::CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateDependency(request); +} + +StatusOr +ApiHubDependenciesClient::GetDependency(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetDependencyRequest request; + request.set_name(name); + return connection_->GetDependency(request); +} + +StatusOr +ApiHubDependenciesClient::GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetDependency(request); +} + +StatusOr +ApiHubDependenciesClient::UpdateDependency( + google::cloud::apihub::v1::Dependency const& dependency, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateDependencyRequest request; + *request.mutable_dependency() = dependency; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateDependency(request); +} + +StatusOr +ApiHubDependenciesClient::UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateDependency(request); +} + +Status ApiHubDependenciesClient::DeleteDependency(std::string const& name, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteDependencyRequest request; + request.set_name(name); + return connection_->DeleteDependency(request); +} + +Status ApiHubDependenciesClient::DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteDependency(request); +} + +StreamRange +ApiHubDependenciesClient::ListDependencies(std::string const& parent, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListDependenciesRequest request; + request.set_parent(parent); + return connection_->ListDependencies(request); +} + +StreamRange +ApiHubDependenciesClient::ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListDependencies(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_dependencies_client.h b/google/cloud/apihub/v1/api_hub_dependencies_client.h new file mode 100644 index 0000000000000..837efef502b03 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_dependencies_client.h @@ -0,0 +1,432 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CLIENT_H + +#include "google/cloud/apihub/v1/api_hub_dependencies_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This service provides methods for various operations related to a +/// [Dependency][google.cloud.apihub.v1.Dependency] in the API hub. +/// +/// @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. +/// +/// [google.cloud.apihub.v1.Dependency]: +/// @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} +/// +class ApiHubDependenciesClient { + public: + explicit ApiHubDependenciesClient( + std::shared_ptr connection, + Options opts = {}); + ~ApiHubDependenciesClient(); + + ///@{ + /// @name Copy and move support + ApiHubDependenciesClient(ApiHubDependenciesClient const&) = default; + ApiHubDependenciesClient& operator=(ApiHubDependenciesClient const&) = + default; + ApiHubDependenciesClient(ApiHubDependenciesClient&&) = default; + ApiHubDependenciesClient& operator=(ApiHubDependenciesClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(ApiHubDependenciesClient const& a, + ApiHubDependenciesClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(ApiHubDependenciesClient const& a, + ApiHubDependenciesClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Create a dependency between two entities in the API hub. + /// + /// @param parent Required. The parent resource for the dependency resource. + /// Format: `projects/{project}/locations/{location}` + /// @param dependency Required. The dependency resource to create. + /// @param dependency_id Optional. The ID to use for the dependency resource, which will become the + /// final component of the dependency's resource name. This field is optional. + /// * If provided, the same will be used. The service will throw an error if + /// duplicate id is provided by the client. + /// * If not provided, a system generated id will be used. + /// @n + /// This value should be 4-500 characters, and valid characters + /// are `[a-z][A-Z][0-9]-_`. + /// @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.apihub.v1.Dependency]) + /// 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 + /// [`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.apihub.v1.CreateDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1585} + /// [google.cloud.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// + // clang-format on + StatusOr CreateDependency( + std::string const& parent, + google::cloud::apihub::v1::Dependency const& dependency, + std::string const& dependency_id, Options opts = {}); + + // clang-format off + /// + /// Create a dependency between two entities in the API hub. + /// + /// @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.apihub.v1.CreateDependencyRequest]. + /// 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.apihub.v1.Dependency]) + /// 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 + /// [`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.apihub.v1.CreateDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1585} + /// [google.cloud.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// + // clang-format on + StatusOr CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get details about a dependency resource in the API hub. + /// + /// @param name Required. The name of the dependency resource to retrieve. + /// Format: `projects/{project}/locations/{location}/dependencies/{dependency}` + /// @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.apihub.v1.Dependency]) + /// 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 + /// [`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.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// [google.cloud.apihub.v1.GetDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1611} + /// + // clang-format on + StatusOr GetDependency( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get details about a dependency resource in the API hub. + /// + /// @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.apihub.v1.GetDependencyRequest]. + /// 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.apihub.v1.Dependency]) + /// 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 + /// [`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.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// [google.cloud.apihub.v1.GetDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1611} + /// + // clang-format on + StatusOr GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Update a dependency based on the + /// [update_mask][google.cloud.apihub.v1.UpdateDependencyRequest.update_mask] + /// provided in the request. + /// + /// The following fields in the [dependency][google.cloud.apihub.v1.Dependency] + /// can be updated: + /// * [description][google.cloud.apihub.v1.Dependency.description] + /// + /// @param dependency Required. The dependency resource to update. + /// @n + /// The dependency's `name` field is used to identify the dependency to update. + /// Format: `projects/{project}/locations/{location}/dependencies/{dependency}` + /// @param update_mask Required. The list of fields to update. + /// @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.apihub.v1.Dependency]) + /// 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 + /// [`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.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// [google.cloud.apihub.v1.Dependency.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1011} + /// [google.cloud.apihub.v1.UpdateDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1625} + /// [google.cloud.apihub.v1.UpdateDependencyRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1633} + /// + // clang-format on + StatusOr UpdateDependency( + google::cloud::apihub::v1::Dependency const& dependency, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update a dependency based on the + /// [update_mask][google.cloud.apihub.v1.UpdateDependencyRequest.update_mask] + /// provided in the request. + /// + /// The following fields in the [dependency][google.cloud.apihub.v1.Dependency] + /// can be updated: + /// * [description][google.cloud.apihub.v1.Dependency.description] + /// + /// @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.apihub.v1.UpdateDependencyRequest]. + /// 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.apihub.v1.Dependency]) + /// 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 + /// [`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.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// [google.cloud.apihub.v1.Dependency.description]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1011} + /// [google.cloud.apihub.v1.UpdateDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1625} + /// [google.cloud.apihub.v1.UpdateDependencyRequest.update_mask]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1633} + /// + // clang-format on + StatusOr UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Delete the dependency resource. + /// + /// @param name Required. The name of the dependency resource to delete. + /// Format: `projects/{project}/locations/{location}/dependencies/{dependency}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1640} + /// + // clang-format on + Status DeleteDependency(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Delete the dependency resource. + /// + /// @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.apihub.v1.DeleteDependencyRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteDependencyRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1640} + /// + // clang-format on + Status DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// List dependencies based on the provided filter and pagination parameters. + /// + /// @param parent Required. The parent which owns this collection of dependency resources. + /// Format: `projects/{project}/locations/{location}` + /// @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.cloud.apihub.v1.Dependency], 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 + /// [`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.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// [google.cloud.apihub.v1.ListDependenciesRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1654} + /// + // clang-format on + StreamRange ListDependencies( + std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List dependencies based on the provided filter and pagination parameters. + /// + /// @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.apihub.v1.ListDependenciesRequest]. + /// 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.cloud.apihub.v1.Dependency], 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 + /// [`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.apihub.v1.Dependency]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L959} + /// [google.cloud.apihub.v1.ListDependenciesRequest]: @googleapis_reference_link{google/cloud/apihub/v1/apihub_service.proto#L1654} + /// + // clang-format on + StreamRange ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CLIENT_H diff --git a/google/cloud/apihub/v1/api_hub_dependencies_connection.cc b/google/cloud/apihub/v1/api_hub_dependencies_connection.cc new file mode 100644 index 0000000000000..4d8e5c1a09e59 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_dependencies_connection.cc @@ -0,0 +1,92 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_dependencies_connection.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_options.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubDependenciesConnection::~ApiHubDependenciesConnection() = default; + +StatusOr +ApiHubDependenciesConnection::CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubDependenciesConnection::GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubDependenciesConnection::UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ApiHubDependenciesConnection::DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +ApiHubDependenciesConnection::ListDependencies( + google::cloud::apihub::v1:: + ListDependenciesRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +std::shared_ptr MakeApiHubDependenciesConnection( + Options options) { + internal::CheckExpectedOptions(options, + __func__); + options = + apihub_v1_internal::ApiHubDependenciesDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); + auto stub = apihub_v1_internal::CreateDefaultApiHubDependenciesStub( + std::move(auth), options); + return apihub_v1_internal::MakeApiHubDependenciesTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_dependencies_connection.h b/google/cloud/apihub/v1/api_hub_dependencies_connection.h new file mode 100644 index 0000000000000..aebd54923c659 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_dependencies_connection.h @@ -0,0 +1,235 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_retry_traits.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/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `ApiHubDependenciesConnection`. +class ApiHubDependenciesRetryPolicy : 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 `ApiHubDependenciesConnection` 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 ApiHubDependenciesLimitedErrorCountRetryPolicy + : public ApiHubDependenciesRetryPolicy { + 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 ApiHubDependenciesLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ApiHubDependenciesLimitedErrorCountRetryPolicy( + ApiHubDependenciesLimitedErrorCountRetryPolicy&& rhs) noexcept + : ApiHubDependenciesLimitedErrorCountRetryPolicy(rhs.maximum_failures()) { + } + ApiHubDependenciesLimitedErrorCountRetryPolicy( + ApiHubDependenciesLimitedErrorCountRetryPolicy const& rhs) noexcept + : ApiHubDependenciesLimitedErrorCountRetryPolicy(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 = ApiHubDependenciesRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apihub_v1_internal::ApiHubDependenciesRetryTraits> + impl_; +}; + +/** + * A retry policy for `ApiHubDependenciesConnection` 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 ApiHubDependenciesLimitedTimeRetryPolicy + : public ApiHubDependenciesRetryPolicy { + 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 ApiHubDependenciesLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ApiHubDependenciesLimitedTimeRetryPolicy( + ApiHubDependenciesLimitedTimeRetryPolicy&& rhs) noexcept + : ApiHubDependenciesLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ApiHubDependenciesLimitedTimeRetryPolicy( + ApiHubDependenciesLimitedTimeRetryPolicy const& rhs) noexcept + : ApiHubDependenciesLimitedTimeRetryPolicy(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 = ApiHubDependenciesRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apihub_v1_internal::ApiHubDependenciesRetryTraits> + impl_; +}; + +/** + * The `ApiHubDependenciesConnection` object for `ApiHubDependenciesClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `ApiHubDependenciesClient`. This allows users to inject custom + * behavior (e.g., with a Google Mock object) when writing tests that use + * objects of type `ApiHubDependenciesClient`. + * + * To create a concrete instance, see `MakeApiHubDependenciesConnection()`. + * + * For mocking, see `apihub_v1_mocks::MockApiHubDependenciesConnection`. + */ +class ApiHubDependenciesConnection { + public: + virtual ~ApiHubDependenciesConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request); + + virtual StatusOr GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request); + + virtual StatusOr UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request); + + virtual Status DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request); + + virtual StreamRange ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest request); +}; + +/** + * A factory function to construct an object of type + * `ApiHubDependenciesConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of + * ApiHubDependenciesClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `ApiHubDependenciesConnection`. Expected options are any of the + * types in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::apihub_v1::ApiHubDependenciesPolicyOptionList` + * + * @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 `ApiHubDependenciesConnection` + * created by this function. + */ +std::shared_ptr MakeApiHubDependenciesConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CONNECTION_H diff --git a/google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.cc b/google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..1ed92fd96e682 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.cc @@ -0,0 +1,70 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +ApiHubDependenciesConnectionIdempotencyPolicy:: + ~ApiHubDependenciesConnectionIdempotencyPolicy() = default; + +std::unique_ptr +ApiHubDependenciesConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency ApiHubDependenciesConnectionIdempotencyPolicy::CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubDependenciesConnectionIdempotencyPolicy::GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubDependenciesConnectionIdempotencyPolicy::UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubDependenciesConnectionIdempotencyPolicy::DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubDependenciesConnectionIdempotencyPolicy::ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultApiHubDependenciesConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.h b/google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.h new file mode 100644 index 0000000000000..feccd4d868029 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubDependenciesConnectionIdempotencyPolicy { + public: + virtual ~ApiHubDependenciesConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request); + + virtual google::cloud::Idempotency GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request); + + virtual google::cloud::Idempotency UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request); + + virtual google::cloud::Idempotency DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request); + + virtual google::cloud::Idempotency ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest request); +}; + +std::unique_ptr +MakeDefaultApiHubDependenciesConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/apihub/v1/api_hub_dependencies_options.h b/google/cloud/apihub/v1/api_hub_dependencies_options.h new file mode 100644 index 0000000000000..c4a2296be2c6e --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_dependencies_options.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_OPTIONS_H + +#include "google/cloud/apihub/v1/api_hub_dependencies_connection.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubDependenciesRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubDependenciesBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubDependenciesConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to ApiHubDependencies. + * + * @ingroup google-cloud-apihub-options + */ +using ApiHubDependenciesPolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_DEPENDENCIES_OPTIONS_H diff --git a/google/cloud/apihub/v1/api_hub_options.h b/google/cloud/apihub/v1/api_hub_options.h new file mode 100644 index 0000000000000..40c858316d949 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_options.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_OPTIONS_H + +#include "google/cloud/apihub/v1/api_hub_connection.h" +#include "google/cloud/apihub/v1/api_hub_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to ApiHub. + * + * @ingroup google-cloud-apihub-options + */ +using ApiHubPolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_OPTIONS_H diff --git a/google/cloud/apihub/v1/api_hub_plugin_client.cc b/google/cloud/apihub/v1/api_hub_plugin_client.cc new file mode 100644 index 0000000000000..a840db2ab910d --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_plugin_client.cc @@ -0,0 +1,82 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/api_hub_plugin_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubPluginClient::ApiHubPluginClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +ApiHubPluginClient::~ApiHubPluginClient() = default; + +StatusOr ApiHubPluginClient::GetPlugin( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetPluginRequest request; + request.set_name(name); + return connection_->GetPlugin(request); +} + +StatusOr ApiHubPluginClient::GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetPlugin(request); +} + +StatusOr ApiHubPluginClient::EnablePlugin( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::EnablePluginRequest request; + request.set_name(name); + return connection_->EnablePlugin(request); +} + +StatusOr ApiHubPluginClient::EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->EnablePlugin(request); +} + +StatusOr ApiHubPluginClient::DisablePlugin( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DisablePluginRequest request; + request.set_name(name); + return connection_->DisablePlugin(request); +} + +StatusOr ApiHubPluginClient::DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DisablePlugin(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_plugin_client.h b/google/cloud/apihub/v1/api_hub_plugin_client.h new file mode 100644 index 0000000000000..0728da8f2b5c2 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_plugin_client.h @@ -0,0 +1,273 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CLIENT_H + +#include "google/cloud/apihub/v1/api_hub_plugin_connection.h" +#include "google/cloud/future.h" +#include "google/cloud/options.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This service is used for managing plugins inside the API Hub. +/// +/// @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 ApiHubPluginClient { + public: + explicit ApiHubPluginClient( + std::shared_ptr connection, Options opts = {}); + ~ApiHubPluginClient(); + + ///@{ + /// @name Copy and move support + ApiHubPluginClient(ApiHubPluginClient const&) = default; + ApiHubPluginClient& operator=(ApiHubPluginClient const&) = default; + ApiHubPluginClient(ApiHubPluginClient&&) = default; + ApiHubPluginClient& operator=(ApiHubPluginClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(ApiHubPluginClient const& a, + ApiHubPluginClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(ApiHubPluginClient const& a, + ApiHubPluginClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Get details about an API Hub plugin. + /// + /// @param name Required. The name of the plugin to retrieve. + /// Format: `projects/{project}/locations/{location}/plugins/{plugin}`. + /// @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.apihub.v1.Plugin]) + /// 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 + /// [`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.apihub.v1.GetPluginRequest]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L119} + /// [google.cloud.apihub.v1.Plugin]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L69} + /// + // clang-format on + StatusOr GetPlugin(std::string const& name, + Options opts = {}); + + // clang-format off + /// + /// Get details about an API Hub plugin. + /// + /// @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.apihub.v1.GetPluginRequest]. + /// 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.apihub.v1.Plugin]) + /// 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 + /// [`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.apihub.v1.GetPluginRequest]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L119} + /// [google.cloud.apihub.v1.Plugin]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L69} + /// + // clang-format on + StatusOr GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Enables a plugin. + /// The `state` of the plugin after enabling is `ENABLED` + /// + /// @param name Required. The name of the plugin to enable. + /// Format: `projects/{project}/locations/{location}/plugins/{plugin}`. + /// @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.apihub.v1.Plugin]) + /// 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 + /// [`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.apihub.v1.EnablePluginRequest]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L130} + /// [google.cloud.apihub.v1.Plugin]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L69} + /// + // clang-format on + StatusOr EnablePlugin( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Enables a plugin. + /// The `state` of the plugin after enabling is `ENABLED` + /// + /// @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.apihub.v1.EnablePluginRequest]. + /// 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.apihub.v1.Plugin]) + /// 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 + /// [`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.apihub.v1.EnablePluginRequest]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L130} + /// [google.cloud.apihub.v1.Plugin]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L69} + /// + // clang-format on + StatusOr EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Disables a plugin. + /// The `state` of the plugin after disabling is `DISABLED` + /// + /// @param name Required. The name of the plugin to disable. + /// Format: `projects/{project}/locations/{location}/plugins/{plugin}`. + /// @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.apihub.v1.Plugin]) + /// 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 + /// [`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.apihub.v1.DisablePluginRequest]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L141} + /// [google.cloud.apihub.v1.Plugin]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L69} + /// + // clang-format on + StatusOr DisablePlugin( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Disables a plugin. + /// The `state` of the plugin after disabling is `DISABLED` + /// + /// @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.apihub.v1.DisablePluginRequest]. + /// 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.apihub.v1.Plugin]) + /// 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 + /// [`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.apihub.v1.DisablePluginRequest]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L141} + /// [google.cloud.apihub.v1.Plugin]: @googleapis_reference_link{google/cloud/apihub/v1/plugin_service.proto#L69} + /// + // clang-format on + StatusOr DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CLIENT_H diff --git a/google/cloud/apihub/v1/api_hub_plugin_connection.cc b/google/cloud/apihub/v1/api_hub_plugin_connection.cc new file mode 100644 index 0000000000000..96fd214c12654 --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_plugin_connection.cc @@ -0,0 +1,76 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/api_hub_plugin_connection.h" +#include "google/cloud/apihub/v1/api_hub_plugin_options.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.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/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubPluginConnection::~ApiHubPluginConnection() = default; + +StatusOr ApiHubPluginConnection::GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubPluginConnection::EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ApiHubPluginConnection::DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +std::shared_ptr MakeApiHubPluginConnection( + Options options) { + internal::CheckExpectedOptions(options, + __func__); + options = apihub_v1_internal::ApiHubPluginDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); + auto stub = apihub_v1_internal::CreateDefaultApiHubPluginStub(std::move(auth), + options); + return apihub_v1_internal::MakeApiHubPluginTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_plugin_connection.h b/google/cloud/apihub/v1/api_hub_plugin_connection.h new file mode 100644 index 0000000000000..a68e5cc6ebbad --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_plugin_connection.h @@ -0,0 +1,223 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_retry_traits.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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `ApiHubPluginConnection`. +class ApiHubPluginRetryPolicy : 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 `ApiHubPluginConnection` 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 ApiHubPluginLimitedErrorCountRetryPolicy + : public ApiHubPluginRetryPolicy { + 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 ApiHubPluginLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ApiHubPluginLimitedErrorCountRetryPolicy( + ApiHubPluginLimitedErrorCountRetryPolicy&& rhs) noexcept + : ApiHubPluginLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ApiHubPluginLimitedErrorCountRetryPolicy( + ApiHubPluginLimitedErrorCountRetryPolicy const& rhs) noexcept + : ApiHubPluginLimitedErrorCountRetryPolicy(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 = ApiHubPluginRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apihub_v1_internal::ApiHubPluginRetryTraits> + impl_; +}; + +/** + * A retry policy for `ApiHubPluginConnection` 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 ApiHubPluginLimitedTimeRetryPolicy : public ApiHubPluginRetryPolicy { + 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 ApiHubPluginLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ApiHubPluginLimitedTimeRetryPolicy( + ApiHubPluginLimitedTimeRetryPolicy&& rhs) noexcept + : ApiHubPluginLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ApiHubPluginLimitedTimeRetryPolicy( + ApiHubPluginLimitedTimeRetryPolicy const& rhs) noexcept + : ApiHubPluginLimitedTimeRetryPolicy(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 = ApiHubPluginRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apihub_v1_internal::ApiHubPluginRetryTraits> + impl_; +}; + +/** + * The `ApiHubPluginConnection` object for `ApiHubPluginClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `ApiHubPluginClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `ApiHubPluginClient`. + * + * To create a concrete instance, see `MakeApiHubPluginConnection()`. + * + * For mocking, see `apihub_v1_mocks::MockApiHubPluginConnection`. + */ +class ApiHubPluginConnection { + public: + virtual ~ApiHubPluginConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request); + + virtual StatusOr EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request); + + virtual StatusOr DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const& request); +}; + +/** + * A factory function to construct an object of type `ApiHubPluginConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of ApiHubPluginClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `ApiHubPluginConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::apihub_v1::ApiHubPluginPolicyOptionList` + * + * @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 `ApiHubPluginConnection` created by + * this function. + */ +std::shared_ptr MakeApiHubPluginConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CONNECTION_H diff --git a/google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.cc b/google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..82c76f2e5119f --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +ApiHubPluginConnectionIdempotencyPolicy:: + ~ApiHubPluginConnectionIdempotencyPolicy() = default; + +std::unique_ptr +ApiHubPluginConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency ApiHubPluginConnectionIdempotencyPolicy::GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ApiHubPluginConnectionIdempotencyPolicy::EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ApiHubPluginConnectionIdempotencyPolicy::DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const&) { + return Idempotency::kNonIdempotent; +} + +std::unique_ptr +MakeDefaultApiHubPluginConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.h b/google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.h new file mode 100644 index 0000000000000..a57e80cc7f3bc --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.h @@ -0,0 +1,58 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubPluginConnectionIdempotencyPolicy { + public: + virtual ~ApiHubPluginConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request); + + virtual google::cloud::Idempotency EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request); + + virtual google::cloud::Idempotency DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const& request); +}; + +std::unique_ptr +MakeDefaultApiHubPluginConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/apihub/v1/api_hub_plugin_options.h b/google/cloud/apihub/v1/api_hub_plugin_options.h new file mode 100644 index 0000000000000..717ce942c2f8f --- /dev/null +++ b/google/cloud/apihub/v1/api_hub_plugin_options.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_OPTIONS_H + +#include "google/cloud/apihub/v1/api_hub_plugin_connection.h" +#include "google/cloud/apihub/v1/api_hub_plugin_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubPluginRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubPluginBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-apihub-options + */ +struct ApiHubPluginConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to ApiHubPlugin. + * + * @ingroup google-cloud-apihub-options + */ +using ApiHubPluginPolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_API_HUB_PLUGIN_OPTIONS_H diff --git a/google/cloud/apihub/v1/host_project_registration_client.cc b/google/cloud/apihub/v1/host_project_registration_client.cc new file mode 100644 index 0000000000000..49ca83f2cc499 --- /dev/null +++ b/google/cloud/apihub/v1/host_project_registration_client.cc @@ -0,0 +1,97 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/host_project_registration_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +HostProjectRegistrationServiceClient::HostProjectRegistrationServiceClient( + std::shared_ptr connection, + Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +HostProjectRegistrationServiceClient::~HostProjectRegistrationServiceClient() = + default; + +StatusOr +HostProjectRegistrationServiceClient::CreateHostProjectRegistration( + std::string const& parent, + google::cloud::apihub::v1::HostProjectRegistration const& + host_project_registration, + std::string const& host_project_registration_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest request; + request.set_parent(parent); + *request.mutable_host_project_registration() = host_project_registration; + request.set_host_project_registration_id(host_project_registration_id); + return connection_->CreateHostProjectRegistration(request); +} + +StatusOr +HostProjectRegistrationServiceClient::CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateHostProjectRegistration(request); +} + +StatusOr +HostProjectRegistrationServiceClient::GetHostProjectRegistration( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetHostProjectRegistrationRequest request; + request.set_name(name); + return connection_->GetHostProjectRegistration(request); +} + +StatusOr +HostProjectRegistrationServiceClient::GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetHostProjectRegistration(request); +} + +StreamRange +HostProjectRegistrationServiceClient::ListHostProjectRegistrations( + std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request; + request.set_parent(parent); + return connection_->ListHostProjectRegistrations(request); +} + +StreamRange +HostProjectRegistrationServiceClient::ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListHostProjectRegistrations(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/host_project_registration_client.h b/google/cloud/apihub/v1/host_project_registration_client.h new file mode 100644 index 0000000000000..9db62ebaa0a60 --- /dev/null +++ b/google/cloud/apihub/v1/host_project_registration_client.h @@ -0,0 +1,314 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CLIENT_H + +#include "google/cloud/apihub/v1/host_project_registration_connection.h" +#include "google/cloud/future.h" +#include "google/cloud/options.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This service is used for managing the host project registrations. +/// +/// @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 HostProjectRegistrationServiceClient { + public: + explicit HostProjectRegistrationServiceClient( + std::shared_ptr connection, + Options opts = {}); + ~HostProjectRegistrationServiceClient(); + + ///@{ + /// @name Copy and move support + HostProjectRegistrationServiceClient( + HostProjectRegistrationServiceClient const&) = default; + HostProjectRegistrationServiceClient& operator=( + HostProjectRegistrationServiceClient const&) = default; + HostProjectRegistrationServiceClient(HostProjectRegistrationServiceClient&&) = + default; + HostProjectRegistrationServiceClient& operator=( + HostProjectRegistrationServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(HostProjectRegistrationServiceClient const& a, + HostProjectRegistrationServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(HostProjectRegistrationServiceClient const& a, + HostProjectRegistrationServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Create a host project registration. + /// A Google cloud project can be registered as a host project if it is not + /// attached as a runtime project to another host project. + /// A project can be registered as a host project only once. Subsequent + /// register calls for the same project will fail. + /// + /// @param parent Required. The parent resource for the host project. + /// Format: `projects/{project}/locations/{location}` + /// @param host_project_registration Required. The host project registration to register. + /// @param host_project_registration_id Required. The ID to use for the Host Project Registration, which will + /// become the final component of the host project registration's resource + /// name. The ID must be the same as the Google cloud project specified in the + /// host_project_registration.gcp_project field. + /// @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.apihub.v1.HostProjectRegistration]) + /// 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 + /// [`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.apihub.v1.CreateHostProjectRegistrationRequest]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L76} + /// [google.cloud.apihub.v1.HostProjectRegistration]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L179} + /// + // clang-format on + StatusOr + CreateHostProjectRegistration( + std::string const& parent, + google::cloud::apihub::v1::HostProjectRegistration const& + host_project_registration, + std::string const& host_project_registration_id, Options opts = {}); + + // clang-format off + /// + /// Create a host project registration. + /// A Google cloud project can be registered as a host project if it is not + /// attached as a runtime project to another host project. + /// A project can be registered as a host project only once. Subsequent + /// register calls for the same project will fail. + /// + /// @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.apihub.v1.CreateHostProjectRegistrationRequest]. + /// 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.apihub.v1.HostProjectRegistration]) + /// 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 + /// [`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.apihub.v1.CreateHostProjectRegistrationRequest]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L76} + /// [google.cloud.apihub.v1.HostProjectRegistration]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L179} + /// + // clang-format on + StatusOr + CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request, + Options opts = {}); + + // clang-format off + /// + /// Get a host project registration. + /// + /// @param name Required. Host project registration resource name. + /// projects/{project}/locations/{location}/hostProjectRegistrations/{host_project_registration_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.cloud.apihub.v1.HostProjectRegistration]) + /// 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 + /// [`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.apihub.v1.GetHostProjectRegistrationRequest]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L101} + /// [google.cloud.apihub.v1.HostProjectRegistration]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L179} + /// + // clang-format on + StatusOr + GetHostProjectRegistration(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get a host project registration. + /// + /// @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.apihub.v1.GetHostProjectRegistrationRequest]. + /// 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.apihub.v1.HostProjectRegistration]) + /// 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 + /// [`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.apihub.v1.GetHostProjectRegistrationRequest]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L101} + /// [google.cloud.apihub.v1.HostProjectRegistration]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L179} + /// + // clang-format on + StatusOr + GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request, + Options opts = {}); + + // clang-format off + /// + /// Lists host project registrations. + /// + /// @param parent Required. The parent, which owns this collection of host projects. + /// Format: `projects/*/locations/*` + /// @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.cloud.apihub.v1.HostProjectRegistration], 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 + /// [`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.apihub.v1.HostProjectRegistration]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L179} + /// [google.cloud.apihub.v1.ListHostProjectRegistrationsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L115} + /// + // clang-format on + StreamRange + ListHostProjectRegistrations(std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// Lists host project registrations. + /// + /// @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.apihub.v1.ListHostProjectRegistrationsRequest]. + /// 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.cloud.apihub.v1.HostProjectRegistration], 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 + /// [`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.apihub.v1.HostProjectRegistration]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L179} + /// [google.cloud.apihub.v1.ListHostProjectRegistrationsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/host_project_registration_service.proto#L115} + /// + // clang-format on + StreamRange + ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CLIENT_H diff --git a/google/cloud/apihub/v1/host_project_registration_connection.cc b/google/cloud/apihub/v1/host_project_registration_connection.cc new file mode 100644 index 0000000000000..3bccbb749fa66 --- /dev/null +++ b/google/cloud/apihub/v1/host_project_registration_connection.cc @@ -0,0 +1,84 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/host_project_registration_connection.h" +#include "google/cloud/apihub/v1/host_project_registration_options.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_connection_impl.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_option_defaults.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_stub_factory.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +HostProjectRegistrationServiceConnection:: + ~HostProjectRegistrationServiceConnection() = default; + +StatusOr +HostProjectRegistrationServiceConnection::CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +HostProjectRegistrationServiceConnection::GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +HostProjectRegistrationServiceConnection::ListHostProjectRegistrations( + google::cloud::apihub::v1:: + ListHostProjectRegistrationsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +std::shared_ptr +MakeHostProjectRegistrationServiceConnection(Options options) { + internal::CheckExpectedOptions< + CommonOptionList, GrpcOptionList, UnifiedCredentialsOptionList, + HostProjectRegistrationServicePolicyOptionList>(options, __func__); + options = apihub_v1_internal::HostProjectRegistrationServiceDefaultOptions( + std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); + auto stub = + apihub_v1_internal::CreateDefaultHostProjectRegistrationServiceStub( + std::move(auth), options); + return apihub_v1_internal:: + MakeHostProjectRegistrationServiceTracingConnection( + std::make_shared< + apihub_v1_internal::HostProjectRegistrationServiceConnectionImpl>( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/host_project_registration_connection.h b/google/cloud/apihub/v1/host_project_registration_connection.h new file mode 100644 index 0000000000000..3654cfa26f4da --- /dev/null +++ b/google/cloud/apihub/v1/host_project_registration_connection.h @@ -0,0 +1,249 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CONNECTION_H + +#include "google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_retry_traits.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/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `HostProjectRegistrationServiceConnection`. +class HostProjectRegistrationServiceRetryPolicy + : 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 `HostProjectRegistrationServiceConnection` 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 HostProjectRegistrationServiceLimitedErrorCountRetryPolicy + : public HostProjectRegistrationServiceRetryPolicy { + 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 HostProjectRegistrationServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + HostProjectRegistrationServiceLimitedErrorCountRetryPolicy( + HostProjectRegistrationServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : HostProjectRegistrationServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + HostProjectRegistrationServiceLimitedErrorCountRetryPolicy( + HostProjectRegistrationServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : HostProjectRegistrationServiceLimitedErrorCountRetryPolicy( + 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< + HostProjectRegistrationServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = HostProjectRegistrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apihub_v1_internal::HostProjectRegistrationServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `HostProjectRegistrationServiceConnection` 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 HostProjectRegistrationServiceLimitedTimeRetryPolicy + : public HostProjectRegistrationServiceRetryPolicy { + 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 HostProjectRegistrationServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + HostProjectRegistrationServiceLimitedTimeRetryPolicy( + HostProjectRegistrationServiceLimitedTimeRetryPolicy&& rhs) noexcept + : HostProjectRegistrationServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + HostProjectRegistrationServiceLimitedTimeRetryPolicy( + HostProjectRegistrationServiceLimitedTimeRetryPolicy const& rhs) noexcept + : HostProjectRegistrationServiceLimitedTimeRetryPolicy( + 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< + HostProjectRegistrationServiceLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = HostProjectRegistrationServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apihub_v1_internal::HostProjectRegistrationServiceRetryTraits> + impl_; +}; + +/** + * The `HostProjectRegistrationServiceConnection` object for + * `HostProjectRegistrationServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `HostProjectRegistrationServiceClient`. This allows users to inject + * custom behavior (e.g., with a Google Mock object) when writing tests that use + * objects of type `HostProjectRegistrationServiceClient`. + * + * To create a concrete instance, see + * `MakeHostProjectRegistrationServiceConnection()`. + * + * For mocking, see + * `apihub_v1_mocks::MockHostProjectRegistrationServiceConnection`. + */ +class HostProjectRegistrationServiceConnection { + public: + virtual ~HostProjectRegistrationServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr + CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request); + + virtual StatusOr + GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request); + + virtual StreamRange + ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request); +}; + +/** + * A factory function to construct an object of type + * `HostProjectRegistrationServiceConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of + * HostProjectRegistrationServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `HostProjectRegistrationServiceConnection`. Expected options are any + * of the types in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::apihub_v1::HostProjectRegistrationServicePolicyOptionList` + * + * @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 + * `HostProjectRegistrationServiceConnection` created by this function. + */ +std::shared_ptr +MakeHostProjectRegistrationServiceConnection(Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CONNECTION_H diff --git a/google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.cc b/google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..f655584500a19 --- /dev/null +++ b/google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.cc @@ -0,0 +1,67 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +HostProjectRegistrationServiceConnectionIdempotencyPolicy:: + ~HostProjectRegistrationServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +HostProjectRegistrationServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique< + HostProjectRegistrationServiceConnectionIdempotencyPolicy>(*this); +} + +Idempotency HostProjectRegistrationServiceConnectionIdempotencyPolicy:: + CreateHostProjectRegistration( + google::cloud::apihub::v1:: + CreateHostProjectRegistrationRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency HostProjectRegistrationServiceConnectionIdempotencyPolicy:: + GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency HostProjectRegistrationServiceConnectionIdempotencyPolicy:: + ListHostProjectRegistrations( + google::cloud::apihub::v1:: + ListHostProjectRegistrationsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultHostProjectRegistrationServiceConnectionIdempotencyPolicy() { + return std::make_unique< + HostProjectRegistrationServiceConnectionIdempotencyPolicy>(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.h b/google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.h new file mode 100644 index 0000000000000..53ddd22ec73b1 --- /dev/null +++ b/google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.h @@ -0,0 +1,61 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class HostProjectRegistrationServiceConnectionIdempotencyPolicy { + public: + virtual ~HostProjectRegistrationServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr< + HostProjectRegistrationServiceConnectionIdempotencyPolicy> + clone() const; + + virtual google::cloud::Idempotency CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request); + + virtual google::cloud::Idempotency GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request); + + virtual google::cloud::Idempotency ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request); +}; + +std::unique_ptr +MakeDefaultHostProjectRegistrationServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/apihub/v1/host_project_registration_options.h b/google/cloud/apihub/v1/host_project_registration_options.h new file mode 100644 index 0000000000000..01789da5f1a8e --- /dev/null +++ b/google/cloud/apihub/v1/host_project_registration_options.h @@ -0,0 +1,77 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_OPTIONS_H + +#include "google/cloud/apihub/v1/host_project_registration_connection.h" +#include "google/cloud/apihub/v1/host_project_registration_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-apihub-options + */ +struct HostProjectRegistrationServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-apihub-options + */ +struct HostProjectRegistrationServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-apihub-options + */ +struct HostProjectRegistrationServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr< + HostProjectRegistrationServiceConnectionIdempotencyPolicy>; +}; + +/** + * The options applicable to HostProjectRegistrationService. + * + * @ingroup google-cloud-apihub-options + */ +using HostProjectRegistrationServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_HOST_PROJECT_REGISTRATION_OPTIONS_H diff --git a/google/cloud/apihub/v1/internal/api_hub_auth_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_auth_decorator.cc new file mode 100644 index 0000000000000..46ed1eba78cb8 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_auth_decorator.cc @@ -0,0 +1,323 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_auth_decorator.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubAuth::ApiHubAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr ApiHubAuth::CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateApi(context, options, request); +} + +StatusOr ApiHubAuth::GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetApi(context, options, request); +} + +StatusOr ApiHubAuth::ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListApis(context, options, request); +} + +StatusOr ApiHubAuth::UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateApi(context, options, request); +} + +Status ApiHubAuth::DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteApi(context, options, request); +} + +StatusOr ApiHubAuth::CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateVersion(context, options, request); +} + +StatusOr ApiHubAuth::GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetVersion(context, options, request); +} + +StatusOr +ApiHubAuth::ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListVersions(context, options, request); +} + +StatusOr ApiHubAuth::UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateVersion(context, options, request); +} + +Status ApiHubAuth::DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteVersion(context, options, request); +} + +StatusOr ApiHubAuth::CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateSpec(context, options, request); +} + +StatusOr ApiHubAuth::GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetSpec(context, options, request); +} + +StatusOr ApiHubAuth::GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetSpecContents(context, options, request); +} + +StatusOr ApiHubAuth::ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListSpecs(context, options, request); +} + +StatusOr ApiHubAuth::UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateSpec(context, options, request); +} + +Status ApiHubAuth::DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteSpec(context, options, request); +} + +StatusOr ApiHubAuth::GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetApiOperation(context, options, request); +} + +StatusOr +ApiHubAuth::ListApiOperations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListApiOperations(context, options, request); +} + +StatusOr ApiHubAuth::GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetDefinition(context, options, request); +} + +StatusOr ApiHubAuth::CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateDeployment(context, options, request); +} + +StatusOr ApiHubAuth::GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetDeployment(context, options, request); +} + +StatusOr +ApiHubAuth::ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListDeployments(context, options, request); +} + +StatusOr ApiHubAuth::UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateDeployment(context, options, request); +} + +Status ApiHubAuth::DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteDeployment(context, options, request); +} + +StatusOr ApiHubAuth::CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateAttribute(context, options, request); +} + +StatusOr ApiHubAuth::GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetAttribute(context, options, request); +} + +StatusOr ApiHubAuth::UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateAttribute(context, options, request); +} + +Status ApiHubAuth::DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteAttribute(context, options, request); +} + +StatusOr +ApiHubAuth::ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListAttributes(context, options, request); +} + +StatusOr +ApiHubAuth::SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->SearchResources(context, options, request); +} + +StatusOr ApiHubAuth::CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateExternalApi(context, options, request); +} + +StatusOr ApiHubAuth::GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetExternalApi(context, options, request); +} + +StatusOr ApiHubAuth::UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateExternalApi(context, options, request); +} + +Status ApiHubAuth::DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteExternalApi(context, options, request); +} + +StatusOr +ApiHubAuth::ListExternalApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListExternalApis(context, options, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_auth_decorator.h b/google/cloud/apihub/v1/internal/api_hub_auth_decorator.h new file mode 100644 index 0000000000000..51dd16c8c5aec --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_auth_decorator.h @@ -0,0 +1,206 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_AUTH_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubAuth : public ApiHubStub { + public: + ~ApiHubAuth() override = default; + ApiHubAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) override; + + StatusOr GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) override; + + StatusOr ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) override; + + StatusOr UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) override; + + Status DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) override; + + StatusOr CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) override; + + StatusOr GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) override; + + StatusOr ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) override; + + StatusOr UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) override; + + Status DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) override; + + StatusOr CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) override; + + StatusOr GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) override; + + StatusOr GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) + override; + + StatusOr ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) override; + + StatusOr UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) override; + + Status DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) override; + + StatusOr GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) + override; + + StatusOr + ListApiOperations(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& + request) override; + + StatusOr GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) override; + + StatusOr CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) + override; + + StatusOr GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) override; + + StatusOr ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) + override; + + StatusOr UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) + override; + + Status DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) + override; + + StatusOr CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) + override; + + StatusOr GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) override; + + StatusOr UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) + override; + + Status DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) + override; + + StatusOr ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) override; + + StatusOr SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) + override; + + StatusOr CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) + override; + + StatusOr GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) override; + + StatusOr UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) + override; + + Status DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) + override; + + StatusOr + ListExternalApis(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& + request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_AUTH_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_connection_impl.cc b/google/cloud/apihub/v1/internal/api_hub_connection_impl.cc new file mode 100644 index 0000000000000..1b1f2ed47e3a8 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_connection_impl.cc @@ -0,0 +1,700 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_connection_impl.h" +#include "google/cloud/apihub/v1/internal/api_hub_option_defaults.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/retry_loop.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_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 + +ApiHubConnectionImpl::ApiHubConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + ApiHubConnection::options())) {} + +StatusOr ApiHubConnectionImpl::CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateApi(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) { + return stub_->CreateApi(context, options, request); + }, + *current, request, __func__); +} + +StatusOr ApiHubConnectionImpl::GetApi( + google::cloud::apihub::v1::GetApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetApi(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) { + return stub_->GetApi(context, options, request); + }, + *current, request, __func__); +} + +StreamRange ApiHubConnectionImpl::ListApis( + google::cloud::apihub::v1::ListApisRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListApis(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListApisRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) { + return stub->ListApis(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListApisResponse r) { + std::vector result(r.apis().size()); + auto& messages = *r.mutable_apis(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr ApiHubConnectionImpl::UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateApi(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) { + return stub_->UpdateApi(context, options, request); + }, + *current, request, __func__); +} + +Status ApiHubConnectionImpl::DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteApi(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) { + return stub_->DeleteApi(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateVersion(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) { + return stub_->CreateVersion(context, options, request); + }, + *current, request, __func__); +} + +StatusOr ApiHubConnectionImpl::GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetVersion(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) { + return stub_->GetVersion(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +ApiHubConnectionImpl::ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListVersions(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) { + return stub->ListVersions(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListVersionsResponse r) { + std::vector result( + r.versions().size()); + auto& messages = *r.mutable_versions(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +ApiHubConnectionImpl::UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateVersion(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + return stub_->UpdateVersion(context, options, request); + }, + *current, request, __func__); +} + +Status ApiHubConnectionImpl::DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteVersion(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + return stub_->DeleteVersion(context, options, request); + }, + *current, request, __func__); +} + +StatusOr ApiHubConnectionImpl::CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateSpec(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) { + return stub_->CreateSpec(context, options, request); + }, + *current, request, __func__); +} + +StatusOr ApiHubConnectionImpl::GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetSpec(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) { + return stub_->GetSpec(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetSpecContents(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + return stub_->GetSpecContents(context, options, request); + }, + *current, request, __func__); +} + +StreamRange ApiHubConnectionImpl::ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListSpecs(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) { + return stub->ListSpecs(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListSpecsResponse r) { + std::vector result(r.specs().size()); + auto& messages = *r.mutable_specs(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr ApiHubConnectionImpl::UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateSpec(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + return stub_->UpdateSpec(context, options, request); + }, + *current, request, __func__); +} + +Status ApiHubConnectionImpl::DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteSpec(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + return stub_->DeleteSpec(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetApiOperation(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + return stub_->GetApiOperation(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +ApiHubConnectionImpl::ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListApiOperations(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& + request) { + return stub->ListApiOperations(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListApiOperationsResponse r) { + std::vector result( + r.api_operations().size()); + auto& messages = *r.mutable_api_operations(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +ApiHubConnectionImpl::GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetDefinition(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + return stub_->GetDefinition(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateDeployment(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + return stub_->CreateDeployment(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetDeployment(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + return stub_->GetDeployment(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +ApiHubConnectionImpl::ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListDeployments(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& + request) { + return stub->ListDeployments(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListDeploymentsResponse r) { + std::vector result( + r.deployments().size()); + auto& messages = *r.mutable_deployments(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +ApiHubConnectionImpl::UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateDeployment(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + return stub_->UpdateDeployment(context, options, request); + }, + *current, request, __func__); +} + +Status ApiHubConnectionImpl::DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteDeployment(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + return stub_->DeleteDeployment(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateAttribute(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + return stub_->CreateAttribute(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetAttribute(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) { + return stub_->GetAttribute(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateAttribute(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + return stub_->UpdateAttribute(context, options, request); + }, + *current, request, __func__); +} + +Status ApiHubConnectionImpl::DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteAttribute(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + return stub_->DeleteAttribute(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +ApiHubConnectionImpl::ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListAttributes(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& + request) { + return stub->ListAttributes(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListAttributesResponse r) { + std::vector result( + r.attributes().size()); + auto& messages = *r.mutable_attributes(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StreamRange +ApiHubConnectionImpl::SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->SearchResources(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& + request) { + return stub->SearchResources(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::SearchResourcesResponse r) { + std::vector result( + r.search_results().size()); + auto& messages = *r.mutable_search_results(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +ApiHubConnectionImpl::CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateExternalApi(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + return stub_->CreateExternalApi(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetExternalApi(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + return stub_->GetExternalApi(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubConnectionImpl::UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateExternalApi(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + return stub_->UpdateExternalApi(context, options, request); + }, + *current, request, __func__); +} + +Status ApiHubConnectionImpl::DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteExternalApi(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + return stub_->DeleteExternalApi(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +ApiHubConnectionImpl::ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListExternalApis(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& + request) { + return stub->ListExternalApis(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListExternalApisResponse r) { + std::vector result( + r.external_apis().size()); + auto& messages = *r.mutable_external_apis(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_connection_impl.h b/google/cloud/apihub/v1/internal/api_hub_connection_impl.h new file mode 100644 index 0000000000000..6794e925f1005 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_connection_impl.h @@ -0,0 +1,177 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_CONNECTION_IMPL_H + +#include "google/cloud/apihub/v1/api_hub_connection.h" +#include "google/cloud/apihub/v1/api_hub_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/api_hub_options.h" +#include "google/cloud/apihub/v1/internal/api_hub_retry_traits.h" +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubConnectionImpl : public apihub_v1::ApiHubConnection { + public: + ~ApiHubConnectionImpl() override = default; + + ApiHubConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, Options options); + + Options options() override { return options_; } + + StatusOr CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request) override; + + StatusOr GetApi( + google::cloud::apihub::v1::GetApiRequest const& request) override; + + StreamRange ListApis( + google::cloud::apihub::v1::ListApisRequest request) override; + + StatusOr UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request) override; + + Status DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const& request) override; + + StatusOr CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request) override; + + StatusOr GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request) override; + + StreamRange ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request) override; + + StatusOr UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request) override; + + Status DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request) override; + + StatusOr CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request) override; + + StatusOr GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request) override; + + StatusOr GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request) + override; + + StreamRange ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request) override; + + StatusOr UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request) override; + + Status DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const& request) override; + + StatusOr GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request) + override; + + StreamRange ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request) override; + + StatusOr GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request) override; + + StatusOr CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request) + override; + + StatusOr GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request) override; + + StreamRange ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request) override; + + StatusOr UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) + override; + + Status DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) + override; + + StatusOr CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request) + override; + + StatusOr GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request) override; + + StatusOr UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request) + override; + + Status DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request) + override; + + StreamRange ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request) override; + + StreamRange SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request) override; + + StatusOr CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request) + override; + + StatusOr GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request) override; + + StatusOr UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) + override; + + Status DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) + override; + + StreamRange ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest request) override; + + private: + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_CONNECTION_IMPL_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.cc new file mode 100644 index 0000000000000..a467d74d4a266 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.cc @@ -0,0 +1,81 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubDependenciesAuth::ApiHubDependenciesAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +ApiHubDependenciesAuth::CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateDependency(context, options, request); +} + +StatusOr +ApiHubDependenciesAuth::GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetDependency(context, options, request); +} + +StatusOr +ApiHubDependenciesAuth::UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateDependency(context, options, request); +} + +Status ApiHubDependenciesAuth::DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteDependency(context, options, request); +} + +StatusOr +ApiHubDependenciesAuth::ListDependencies( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListDependencies(context, options, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.h new file mode 100644 index 0000000000000..67994a4962d22 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_AUTH_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubDependenciesAuth : public ApiHubDependenciesStub { + public: + ~ApiHubDependenciesAuth() override = default; + ApiHubDependenciesAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) + override; + + StatusOr GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) override; + + StatusOr UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) + override; + + Status DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) + override; + + StatusOr + ListDependencies(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& + request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_AUTH_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.cc new file mode 100644 index 0000000000000..9bb11e95c3439 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.cc @@ -0,0 +1,158 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/retry_loop.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_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 + +ApiHubDependenciesConnectionImpl::ApiHubDependenciesConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions( + std::move(options), ApiHubDependenciesConnection::options())) {} + +StatusOr +ApiHubDependenciesConnectionImpl::CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateDependency(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + return stub_->CreateDependency(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubDependenciesConnectionImpl::GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetDependency(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) { + return stub_->GetDependency(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubDependenciesConnectionImpl::UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateDependency(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + return stub_->UpdateDependency(context, options, request); + }, + *current, request, __func__); +} + +Status ApiHubDependenciesConnectionImpl::DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteDependency(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + return stub_->DeleteDependency(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +ApiHubDependenciesConnectionImpl::ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListDependencies(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& + request) { + return stub->ListDependencies(context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListDependenciesResponse r) { + std::vector result( + r.dependencies().size()); + auto& messages = *r.mutable_dependencies(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.h new file mode 100644 index 0000000000000..161deed092bcf --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.h @@ -0,0 +1,81 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_CONNECTION_IMPL_H + +#include "google/cloud/apihub/v1/api_hub_dependencies_connection.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_options.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_retry_traits.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubDependenciesConnectionImpl + : public apihub_v1::ApiHubDependenciesConnection { + public: + ~ApiHubDependenciesConnectionImpl() override = default; + + ApiHubDependenciesConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StatusOr CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request) + override; + + StatusOr GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request) override; + + StatusOr UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request) + override; + + Status DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request) + override; + + StreamRange ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest request) override; + + private: + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_CONNECTION_IMPL_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.cc new file mode 100644 index 0000000000000..dac35ab9e54b2 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.cc @@ -0,0 +1,104 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubDependenciesLogging::ApiHubDependenciesLogging( + std::shared_ptr child, + TracingOptions tracing_options, std::set const&) + : child_(std::move(child)), tracing_options_(std::move(tracing_options)) {} + +StatusOr +ApiHubDependenciesLogging::CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + return child_->CreateDependency(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubDependenciesLogging::GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) { + return child_->GetDependency(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubDependenciesLogging::UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + return child_->UpdateDependency(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status ApiHubDependenciesLogging::DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + return child_->DeleteDependency(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubDependenciesLogging::ListDependencies( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& request) { + return child_->ListDependencies(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.h new file mode 100644 index 0000000000000..e484e96fd3e42 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_LOGGING_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubDependenciesLogging : public ApiHubDependenciesStub { + public: + ~ApiHubDependenciesLogging() override = default; + ApiHubDependenciesLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components); + + StatusOr CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) + override; + + StatusOr GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) override; + + StatusOr UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) + override; + + Status DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) + override; + + StatusOr + ListDependencies(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& + request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; +}; // ApiHubDependenciesLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_LOGGING_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.cc new file mode 100644 index 0000000000000..926b1ffd93d54 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.cc @@ -0,0 +1,108 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/url_encode.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubDependenciesMetadata::ApiHubDependenciesMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +ApiHubDependenciesMetadata::CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateDependency(context, options, request); +} + +StatusOr +ApiHubDependenciesMetadata::GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetDependency(context, options, request); +} + +StatusOr +ApiHubDependenciesMetadata::UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + SetMetadata(context, options, + absl::StrCat("dependency.name=", + internal::UrlEncode(request.dependency().name()))); + return child_->UpdateDependency(context, options, request); +} + +Status ApiHubDependenciesMetadata::DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteDependency(context, options, request); +} + +StatusOr +ApiHubDependenciesMetadata::ListDependencies( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListDependencies(context, options, request); +} + +void ApiHubDependenciesMetadata::SetMetadata( + grpc::ClientContext& context, Options const& options, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context, options); +} + +void ApiHubDependenciesMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options) { + google::cloud::internal::SetMetadata(context, options, fixed_metadata_, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.h new file mode 100644 index 0000000000000..9b5bbb52788f6 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.h @@ -0,0 +1,81 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_METADATA_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubDependenciesMetadata : public ApiHubDependenciesStub { + public: + ~ApiHubDependenciesMetadata() override = default; + ApiHubDependenciesMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header = ""); + + StatusOr CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) + override; + + StatusOr GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) override; + + StatusOr UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) + override; + + Status DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) + override; + + StatusOr + ListDependencies(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& + request) override; + + private: + void SetMetadata(grpc::ClientContext& context, Options const& options, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context, Options const& options); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_METADATA_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.cc new file mode 100644 index 0000000000000..ec521014693e6 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.cc @@ -0,0 +1,67 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_connection.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options ApiHubDependenciesDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_API_HUB_DEPENDENCIES_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_API_HUB_DEPENDENCIES_AUTHORITY", + "apihub.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + apihub_v1::ApiHubDependenciesLimitedTimeRetryPolicy( + 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< + apihub_v1::ApiHubDependenciesConnectionIdempotencyPolicyOption>()) { + options.set( + apihub_v1::MakeDefaultApiHubDependenciesConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.h new file mode 100644 index 0000000000000..d29074e886a82 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options ApiHubDependenciesDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_OPTION_DEFAULTS_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_retry_traits.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_retry_traits.h new file mode 100644 index 0000000000000..dcf7d0b4c45fc --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct ApiHubDependenciesRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_RETRY_TRAITS_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_sources.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_sources.cc new file mode 100644 index 0000000000000..82de5f701b54b --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_sources.cc @@ -0,0 +1,32 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/apihub/v1/api_hub_dependencies_client.cc" +#include "google/cloud/apihub/v1/api_hub_dependencies_connection.cc" +#include "google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_connection_impl.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_option_defaults.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.cc" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_stub.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub.cc new file mode 100644 index 0000000000000..10928904f6ba1 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub.cc @@ -0,0 +1,95 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubDependenciesStub::~ApiHubDependenciesStub() = default; + +StatusOr +DefaultApiHubDependenciesStub::CreateDependency( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + google::cloud::apihub::v1::Dependency response; + auto status = grpc_stub_->CreateDependency(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubDependenciesStub::GetDependency( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetDependencyRequest const& request) { + google::cloud::apihub::v1::Dependency response; + auto status = grpc_stub_->GetDependency(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubDependenciesStub::UpdateDependency( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + google::cloud::apihub::v1::Dependency response; + auto status = grpc_stub_->UpdateDependency(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultApiHubDependenciesStub::DeleteDependency( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->DeleteDependency(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr +DefaultApiHubDependenciesStub::ListDependencies( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListDependenciesRequest const& request) { + google::cloud::apihub::v1::ListDependenciesResponse response; + auto status = grpc_stub_->ListDependencies(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h new file mode 100644 index 0000000000000..56fb376d4ff07 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h @@ -0,0 +1,102 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_STUB_H + +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubDependenciesStub { + public: + virtual ~ApiHubDependenciesStub() = 0; + + virtual StatusOr CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) = 0; + + virtual StatusOr GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) = 0; + + virtual StatusOr UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) = 0; + + virtual Status DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) = 0; + + virtual StatusOr + ListDependencies( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& request) = 0; +}; + +class DefaultApiHubDependenciesStub : public ApiHubDependenciesStub { + public: + explicit DefaultApiHubDependenciesStub( + std::unique_ptr< + google::cloud::apihub::v1::ApiHubDependencies::StubInterface> + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) + override; + + StatusOr GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) override; + + StatusOr UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) + override; + + Status DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) + override; + + StatusOr + ListDependencies(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& + request) override; + + private: + std::unique_ptr + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_STUB_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.cc new file mode 100644 index 0000000000000..c7d4080790d6d --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.cc @@ -0,0 +1,72 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_auth_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_logging_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_metadata_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultApiHubDependenciesStub( + std::shared_ptr auth, + Options const& options) { + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = + google::cloud::apihub::v1::ApiHubDependencies::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 = MakeApiHubDependenciesTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.h new file mode 100644 index 0000000000000..1edae286f7d42 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_STUB_FACTORY_H + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultApiHubDependenciesStub( + std::shared_ptr auth, + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_STUB_FACTORY_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.cc new file mode 100644 index 0000000000000..c8b2499b77034 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.cc @@ -0,0 +1,99 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ApiHubDependenciesTracingConnection::ApiHubDependenciesTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +ApiHubDependenciesTracingConnection::CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ApiHubDependenciesConnection::CreateDependency"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CreateDependency(request)); +} + +StatusOr +ApiHubDependenciesTracingConnection::GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ApiHubDependenciesConnection::GetDependency"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetDependency(request)); +} + +StatusOr +ApiHubDependenciesTracingConnection::UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ApiHubDependenciesConnection::UpdateDependency"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateDependency(request)); +} + +Status ApiHubDependenciesTracingConnection::DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ApiHubDependenciesConnection::DeleteDependency"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteDependency(request)); +} + +StreamRange +ApiHubDependenciesTracingConnection::ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest request) { + auto span = internal::MakeSpan( + "apihub_v1::ApiHubDependenciesConnection::ListDependencies"); + internal::OTelScope scope(span); + auto sr = child_->ListDependencies(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeApiHubDependenciesTracingConnection( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.h new file mode 100644 index 0000000000000..b05b625d7b53f --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_connection.h @@ -0,0 +1,82 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_TRACING_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_dependencies_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ApiHubDependenciesTracingConnection + : public apihub_v1::ApiHubDependenciesConnection { + public: + ~ApiHubDependenciesTracingConnection() override = default; + + explicit ApiHubDependenciesTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr CreateDependency( + google::cloud::apihub::v1::CreateDependencyRequest const& request) + override; + + StatusOr GetDependency( + google::cloud::apihub::v1::GetDependencyRequest const& request) override; + + StatusOr UpdateDependency( + google::cloud::apihub::v1::UpdateDependencyRequest const& request) + override; + + Status DeleteDependency( + google::cloud::apihub::v1::DeleteDependencyRequest const& request) + override; + + StreamRange ListDependencies( + google::cloud::apihub::v1::ListDependenciesRequest 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 +MakeApiHubDependenciesTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_TRACING_CONNECTION_H diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.cc b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.cc new file mode 100644 index 0000000000000..8b0797c41422b --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.cc @@ -0,0 +1,108 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ApiHubDependenciesTracingStub::ApiHubDependenciesTracingStub( + std::shared_ptr child) + : child_(std::move(child)), propagator_(internal::MakePropagator()) {} + +StatusOr +ApiHubDependenciesTracingStub::CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.ApiHubDependencies", "CreateDependency"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->CreateDependency(context, options, request)); +} + +StatusOr +ApiHubDependenciesTracingStub::GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.ApiHubDependencies", "GetDependency"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetDependency(context, options, request)); +} + +StatusOr +ApiHubDependenciesTracingStub::UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.ApiHubDependencies", "UpdateDependency"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->UpdateDependency(context, options, request)); +} + +Status ApiHubDependenciesTracingStub::DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.ApiHubDependencies", "DeleteDependency"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->DeleteDependency(context, options, request)); +} + +StatusOr +ApiHubDependenciesTracingStub::ListDependencies( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.ApiHubDependencies", "ListDependencies"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->ListDependencies(context, options, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeApiHubDependenciesTracingStub( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.h b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.h new file mode 100644 index 0000000000000..de64544b915a0 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_dependencies_tracing_stub.h @@ -0,0 +1,88 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_TRACING_STUB_H + +#include "google/cloud/apihub/v1/internal/api_hub_dependencies_stub.h" +#include "google/cloud/internal/trace_propagator.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ApiHubDependenciesTracingStub : public ApiHubDependenciesStub { + public: + ~ApiHubDependenciesTracingStub() override = default; + + explicit ApiHubDependenciesTracingStub( + std::shared_ptr child); + + StatusOr CreateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDependencyRequest const& request) + override; + + StatusOr GetDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDependencyRequest const& request) override; + + StatusOr UpdateDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDependencyRequest const& request) + override; + + Status DeleteDependency( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDependencyRequest const& request) + override; + + StatusOr + ListDependencies(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDependenciesRequest const& + request) override; + + private: + std::shared_ptr child_; + std::shared_ptr + propagator_; +}; + +#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 MakeApiHubDependenciesTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_DEPENDENCIES_TRACING_STUB_H diff --git a/google/cloud/apihub/v1/internal/api_hub_logging_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_logging_decorator.cc new file mode 100644 index 0000000000000..0c2906f4d557f --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_logging_decorator.cc @@ -0,0 +1,444 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubLogging::ApiHubLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const&) + : child_(std::move(child)), tracing_options_(std::move(tracing_options)) {} + +StatusOr ApiHubLogging::CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) { + return child_->CreateApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) { + return child_->GetApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) { + return child_->ListApis(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) { + return child_->UpdateApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status ApiHubLogging::DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) { + return child_->DeleteApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) { + return child_->CreateVersion(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) { + return child_->GetVersion(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) { + return child_->ListVersions(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + return child_->UpdateVersion(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status ApiHubLogging::DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + return child_->DeleteVersion(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) { + return child_->CreateSpec(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) { + return child_->GetSpec(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + return child_->GetSpecContents(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) { + return child_->ListSpecs(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + return child_->UpdateSpec(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status ApiHubLogging::DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + return child_->DeleteSpec(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + return child_->GetApiOperation(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::ListApiOperations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& request) { + return child_->ListApiOperations(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + return child_->GetDefinition(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + return child_->CreateDeployment(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + return child_->GetDeployment(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) { + return child_->ListDeployments(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + return child_->UpdateDeployment(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status ApiHubLogging::DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + return child_->DeleteDeployment(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + return child_->CreateAttribute(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) { + return child_->GetAttribute(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + return child_->UpdateAttribute(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status ApiHubLogging::DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + return child_->DeleteAttribute(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) { + return child_->ListAttributes(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) { + return child_->SearchResources(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + return child_->CreateExternalApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubLogging::GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + return child_->GetExternalApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + return child_->UpdateExternalApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status ApiHubLogging::DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + return child_->DeleteExternalApi(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ApiHubLogging::ListExternalApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& request) { + return child_->ListExternalApis(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_logging_decorator.h b/google/cloud/apihub/v1/internal/api_hub_logging_decorator.h new file mode 100644 index 0000000000000..bb4b8bdc9e4da --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_logging_decorator.h @@ -0,0 +1,206 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_LOGGING_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubLogging : public ApiHubStub { + public: + ~ApiHubLogging() override = default; + ApiHubLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components); + + StatusOr CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) override; + + StatusOr GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) override; + + StatusOr ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) override; + + StatusOr UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) override; + + Status DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) override; + + StatusOr CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) override; + + StatusOr GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) override; + + StatusOr ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) override; + + StatusOr UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) override; + + Status DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) override; + + StatusOr CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) override; + + StatusOr GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) override; + + StatusOr GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) + override; + + StatusOr ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) override; + + StatusOr UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) override; + + Status DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) override; + + StatusOr GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) + override; + + StatusOr + ListApiOperations(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& + request) override; + + StatusOr GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) override; + + StatusOr CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) + override; + + StatusOr GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) override; + + StatusOr ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) + override; + + StatusOr UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) + override; + + Status DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) + override; + + StatusOr CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) + override; + + StatusOr GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) override; + + StatusOr UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) + override; + + Status DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) + override; + + StatusOr ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) override; + + StatusOr SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) + override; + + StatusOr CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) + override; + + StatusOr GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) override; + + StatusOr UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) + override; + + Status DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) + override; + + StatusOr + ListExternalApis(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& + request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; +}; // ApiHubLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_LOGGING_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_metadata_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_metadata_decorator.cc new file mode 100644 index 0000000000000..3595b8e7a05ac --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_metadata_decorator.cc @@ -0,0 +1,363 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_metadata_decorator.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/url_encode.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubMetadata::ApiHubMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr ApiHubMetadata::CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateApi(context, options, request); +} + +StatusOr ApiHubMetadata::GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetApi(context, options, request); +} + +StatusOr ApiHubMetadata::ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListApis(context, options, request); +} + +StatusOr ApiHubMetadata::UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) { + SetMetadata( + context, options, + absl::StrCat("api.name=", internal::UrlEncode(request.api().name()))); + return child_->UpdateApi(context, options, request); +} + +Status ApiHubMetadata::DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteApi(context, options, request); +} + +StatusOr ApiHubMetadata::CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateVersion(context, options, request); +} + +StatusOr ApiHubMetadata::GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetVersion(context, options, request); +} + +StatusOr +ApiHubMetadata::ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListVersions(context, options, request); +} + +StatusOr ApiHubMetadata::UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + SetMetadata(context, options, + absl::StrCat("version.name=", + internal::UrlEncode(request.version().name()))); + return child_->UpdateVersion(context, options, request); +} + +Status ApiHubMetadata::DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteVersion(context, options, request); +} + +StatusOr ApiHubMetadata::CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateSpec(context, options, request); +} + +StatusOr ApiHubMetadata::GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetSpec(context, options, request); +} + +StatusOr +ApiHubMetadata::GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetSpecContents(context, options, request); +} + +StatusOr +ApiHubMetadata::ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListSpecs(context, options, request); +} + +StatusOr ApiHubMetadata::UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + SetMetadata( + context, options, + absl::StrCat("spec.name=", internal::UrlEncode(request.spec().name()))); + return child_->UpdateSpec(context, options, request); +} + +Status ApiHubMetadata::DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteSpec(context, options, request); +} + +StatusOr +ApiHubMetadata::GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetApiOperation(context, options, request); +} + +StatusOr +ApiHubMetadata::ListApiOperations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListApiOperations(context, options, request); +} + +StatusOr ApiHubMetadata::GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetDefinition(context, options, request); +} + +StatusOr +ApiHubMetadata::CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateDeployment(context, options, request); +} + +StatusOr ApiHubMetadata::GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetDeployment(context, options, request); +} + +StatusOr +ApiHubMetadata::ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListDeployments(context, options, request); +} + +StatusOr +ApiHubMetadata::UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + SetMetadata(context, options, + absl::StrCat("deployment.name=", + internal::UrlEncode(request.deployment().name()))); + return child_->UpdateDeployment(context, options, request); +} + +Status ApiHubMetadata::DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteDeployment(context, options, request); +} + +StatusOr ApiHubMetadata::CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateAttribute(context, options, request); +} + +StatusOr ApiHubMetadata::GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetAttribute(context, options, request); +} + +StatusOr ApiHubMetadata::UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + SetMetadata(context, options, + absl::StrCat("attribute.name=", + internal::UrlEncode(request.attribute().name()))); + return child_->UpdateAttribute(context, options, request); +} + +Status ApiHubMetadata::DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteAttribute(context, options, request); +} + +StatusOr +ApiHubMetadata::ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListAttributes(context, options, request); +} + +StatusOr +ApiHubMetadata::SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) { + SetMetadata( + context, options, + absl::StrCat("location=", internal::UrlEncode(request.location()))); + return child_->SearchResources(context, options, request); +} + +StatusOr +ApiHubMetadata::CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateExternalApi(context, options, request); +} + +StatusOr ApiHubMetadata::GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetExternalApi(context, options, request); +} + +StatusOr +ApiHubMetadata::UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + SetMetadata(context, options, + absl::StrCat("external_api.name=", + internal::UrlEncode(request.external_api().name()))); + return child_->UpdateExternalApi(context, options, request); +} + +Status ApiHubMetadata::DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteExternalApi(context, options, request); +} + +StatusOr +ApiHubMetadata::ListExternalApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListExternalApis(context, options, request); +} + +void ApiHubMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context, options); +} + +void ApiHubMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options) { + google::cloud::internal::SetMetadata(context, options, fixed_metadata_, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_metadata_decorator.h b/google/cloud/apihub/v1/internal/api_hub_metadata_decorator.h new file mode 100644 index 0000000000000..fdb3212abe188 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_metadata_decorator.h @@ -0,0 +1,211 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_METADATA_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubMetadata : public ApiHubStub { + public: + ~ApiHubMetadata() override = default; + ApiHubMetadata(std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header = ""); + + StatusOr CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) override; + + StatusOr GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) override; + + StatusOr ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) override; + + StatusOr UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) override; + + Status DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) override; + + StatusOr CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) override; + + StatusOr GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) override; + + StatusOr ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) override; + + StatusOr UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) override; + + Status DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) override; + + StatusOr CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) override; + + StatusOr GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) override; + + StatusOr GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) + override; + + StatusOr ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) override; + + StatusOr UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) override; + + Status DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) override; + + StatusOr GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) + override; + + StatusOr + ListApiOperations(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& + request) override; + + StatusOr GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) override; + + StatusOr CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) + override; + + StatusOr GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) override; + + StatusOr ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) + override; + + StatusOr UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) + override; + + Status DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) + override; + + StatusOr CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) + override; + + StatusOr GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) override; + + StatusOr UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) + override; + + Status DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) + override; + + StatusOr ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) override; + + StatusOr SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) + override; + + StatusOr CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) + override; + + StatusOr GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) override; + + StatusOr UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) + override; + + Status DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) + override; + + StatusOr + ListExternalApis(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& + request) override; + + private: + void SetMetadata(grpc::ClientContext& context, Options const& options, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context, Options const& options); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_METADATA_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_option_defaults.cc b/google/cloud/apihub/v1/internal/api_hub_option_defaults.cc new file mode 100644 index 0000000000000..12270801e6dee --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_option_defaults.cc @@ -0,0 +1,64 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_option_defaults.h" +#include "google/cloud/apihub/v1/api_hub_connection.h" +#include "google/cloud/apihub/v1/api_hub_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options ApiHubDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_API_HUB_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_API_HUB_AUTHORITY", "apihub.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + apihub_v1::ApiHubLimitedTimeRetryPolicy(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( + apihub_v1::MakeDefaultApiHubConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_option_defaults.h b/google/cloud/apihub/v1/internal/api_hub_option_defaults.h new file mode 100644 index 0000000000000..b64e92363004d --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options ApiHubDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_OPTION_DEFAULTS_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.cc new file mode 100644 index 0000000000000..18b2813e0cee9 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.cc @@ -0,0 +1,61 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubPluginAuth::ApiHubPluginAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr ApiHubPluginAuth::GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetPlugin(context, options, request); +} + +StatusOr ApiHubPluginAuth::EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->EnablePlugin(context, options, request); +} + +StatusOr ApiHubPluginAuth::DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DisablePlugin(context, options, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.h b/google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.h new file mode 100644 index 0000000000000..71528aa224795 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.h @@ -0,0 +1,63 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_AUTH_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubPluginAuth : public ApiHubPluginStub { + public: + ~ApiHubPluginAuth() override = default; + ApiHubPluginAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) override; + + StatusOr EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) override; + + StatusOr DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_AUTH_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.cc new file mode 100644 index 0000000000000..45121b5dfd071 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.cc @@ -0,0 +1,105 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_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 + +ApiHubPluginConnectionImpl::ApiHubPluginConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + ApiHubPluginConnection::options())) {} + +StatusOr +ApiHubPluginConnectionImpl::GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetPlugin(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) { + return stub_->GetPlugin(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubPluginConnectionImpl::EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->EnablePlugin(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) { + return stub_->EnablePlugin(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ApiHubPluginConnectionImpl::DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DisablePlugin(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) { + return stub_->DisablePlugin(context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.h b/google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.h new file mode 100644 index 0000000000000..c5b81a1b60dcf --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.h @@ -0,0 +1,70 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_CONNECTION_IMPL_H + +#include "google/cloud/apihub/v1/api_hub_plugin_connection.h" +#include "google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/api_hub_plugin_options.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_retry_traits.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubPluginConnectionImpl : public apihub_v1::ApiHubPluginConnection { + public: + ~ApiHubPluginConnectionImpl() override = default; + + ApiHubPluginConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StatusOr GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request) override; + + StatusOr EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request) override; + + StatusOr DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const& request) override; + + private: + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_CONNECTION_IMPL_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.cc new file mode 100644 index 0000000000000..9b653f2b80ca5 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.cc @@ -0,0 +1,74 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubPluginLogging::ApiHubPluginLogging( + std::shared_ptr child, TracingOptions tracing_options, + std::set const&) + : child_(std::move(child)), tracing_options_(std::move(tracing_options)) {} + +StatusOr ApiHubPluginLogging::GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) { + return child_->GetPlugin(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubPluginLogging::EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) { + return child_->EnablePlugin(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr ApiHubPluginLogging::DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) { + return child_->DisablePlugin(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.h b/google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.h new file mode 100644 index 0000000000000..7e6f792bd44a4 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.h @@ -0,0 +1,63 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_LOGGING_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubPluginLogging : public ApiHubPluginStub { + public: + ~ApiHubPluginLogging() override = default; + ApiHubPluginLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components); + + StatusOr GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) override; + + StatusOr EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) override; + + StatusOr DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; +}; // ApiHubPluginLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_LOGGING_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.cc new file mode 100644 index 0000000000000..adf5fa8cf6eb1 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.cc @@ -0,0 +1,87 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/url_encode.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubPluginMetadata::ApiHubPluginMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr ApiHubPluginMetadata::GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetPlugin(context, options, request); +} + +StatusOr ApiHubPluginMetadata::EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->EnablePlugin(context, options, request); +} + +StatusOr ApiHubPluginMetadata::DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DisablePlugin(context, options, request); +} + +void ApiHubPluginMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context, options); +} + +void ApiHubPluginMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options) { + google::cloud::internal::SetMetadata(context, options, fixed_metadata_, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.h b/google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.h new file mode 100644 index 0000000000000..5ffb0b9569564 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.h @@ -0,0 +1,68 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_METADATA_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubPluginMetadata : public ApiHubPluginStub { + public: + ~ApiHubPluginMetadata() override = default; + ApiHubPluginMetadata(std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header = ""); + + StatusOr GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) override; + + StatusOr EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) override; + + StatusOr DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) override; + + private: + void SetMetadata(grpc::ClientContext& context, Options const& options, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context, Options const& options); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_METADATA_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.cc new file mode 100644 index 0000000000000..8a48bb57bb8b7 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.cc @@ -0,0 +1,65 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.h" +#include "google/cloud/apihub/v1/api_hub_plugin_connection.h" +#include "google/cloud/apihub/v1/api_hub_plugin_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options ApiHubPluginDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_API_HUB_PLUGIN_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_API_HUB_PLUGIN_AUTHORITY", "apihub.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + apihub_v1::ApiHubPluginLimitedTimeRetryPolicy(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( + apihub_v1::MakeDefaultApiHubPluginConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.h b/google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.h new file mode 100644 index 0000000000000..d9c095e05f803 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options ApiHubPluginDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_OPTION_DEFAULTS_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_retry_traits.h b/google/cloud/apihub/v1/internal/api_hub_plugin_retry_traits.h new file mode 100644 index 0000000000000..8ddd252e8d3a3 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct ApiHubPluginRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_RETRY_TRAITS_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_sources.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_sources.cc new file mode 100644 index 0000000000000..62c1f9edc06c5 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_sources.cc @@ -0,0 +1,32 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/apihub/v1/api_hub_plugin_client.cc" +#include "google/cloud/apihub/v1/api_hub_plugin_connection.cc" +#include "google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_connection_impl.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_option_defaults.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.cc" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_stub.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_stub.cc new file mode 100644 index 0000000000000..7d7473aeb0a71 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_stub.cc @@ -0,0 +1,71 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubPluginStub::~ApiHubPluginStub() = default; + +StatusOr DefaultApiHubPluginStub::GetPlugin( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetPluginRequest const& request) { + google::cloud::apihub::v1::Plugin response; + auto status = grpc_stub_->GetPlugin(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubPluginStub::EnablePlugin( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::EnablePluginRequest const& request) { + google::cloud::apihub::v1::Plugin response; + auto status = grpc_stub_->EnablePlugin(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubPluginStub::DisablePlugin( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DisablePluginRequest const& request) { + google::cloud::apihub::v1::Plugin response; + auto status = grpc_stub_->DisablePlugin(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_stub.h b/google/cloud/apihub/v1/internal/api_hub_plugin_stub.h new file mode 100644 index 0000000000000..7db9af047cea1 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_stub.h @@ -0,0 +1,80 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_STUB_H + +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubPluginStub { + public: + virtual ~ApiHubPluginStub() = 0; + + virtual StatusOr GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) = 0; + + virtual StatusOr EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) = 0; + + virtual StatusOr DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) = 0; +}; + +class DefaultApiHubPluginStub : public ApiHubPluginStub { + public: + explicit DefaultApiHubPluginStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) override; + + StatusOr EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) override; + + StatusOr DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) override; + + private: + std::unique_ptr + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_STUB_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.cc new file mode 100644 index 0000000000000..eedc99d3bc719 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.cc @@ -0,0 +1,70 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_auth_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_logging_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_metadata_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/apihub/v1/internal/api_hub_plugin_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultApiHubPluginStub( + std::shared_ptr auth, + Options const& options) { + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = + google::cloud::apihub::v1::ApiHubPlugin::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 = MakeApiHubPluginTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.h b/google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.h new file mode 100644 index 0000000000000..a618a811435f9 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_STUB_FACTORY_H + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultApiHubPluginStub( + std::shared_ptr auth, + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_STUB_FACTORY_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.cc new file mode 100644 index 0000000000000..7aa811a80b4b0 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.cc @@ -0,0 +1,78 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ApiHubPluginTracingConnection::ApiHubPluginTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +ApiHubPluginTracingConnection::GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubPluginConnection::GetPlugin"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetPlugin(request)); +} + +StatusOr +ApiHubPluginTracingConnection::EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubPluginConnection::EnablePlugin"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->EnablePlugin(request)); +} + +StatusOr +ApiHubPluginTracingConnection::DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubPluginConnection::DisablePlugin"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DisablePlugin(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeApiHubPluginTracingConnection( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.h b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.h new file mode 100644 index 0000000000000..adb1deabf445c --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_connection.h @@ -0,0 +1,72 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_TRACING_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_plugin_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ApiHubPluginTracingConnection : public apihub_v1::ApiHubPluginConnection { + public: + ~ApiHubPluginTracingConnection() override = default; + + explicit ApiHubPluginTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr GetPlugin( + google::cloud::apihub::v1::GetPluginRequest const& request) override; + + StatusOr EnablePlugin( + google::cloud::apihub::v1::EnablePluginRequest const& request) override; + + StatusOr DisablePlugin( + google::cloud::apihub::v1::DisablePluginRequest 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 +MakeApiHubPluginTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_TRACING_CONNECTION_H diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.cc b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.cc new file mode 100644 index 0000000000000..393ae7a71f9bc --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.cc @@ -0,0 +1,84 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ApiHubPluginTracingStub::ApiHubPluginTracingStub( + std::shared_ptr child) + : child_(std::move(child)), propagator_(internal::MakePropagator()) {} + +StatusOr ApiHubPluginTracingStub::GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHubPlugin", + "GetPlugin"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetPlugin(context, options, request)); +} + +StatusOr +ApiHubPluginTracingStub::EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHubPlugin", + "EnablePlugin"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->EnablePlugin(context, options, request)); +} + +StatusOr +ApiHubPluginTracingStub::DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHubPlugin", + "DisablePlugin"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->DisablePlugin(context, options, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeApiHubPluginTracingStub( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.h b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.h new file mode 100644 index 0000000000000..3784da3572d28 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_plugin_tracing_stub.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_TRACING_STUB_H + +#include "google/cloud/apihub/v1/internal/api_hub_plugin_stub.h" +#include "google/cloud/internal/trace_propagator.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ApiHubPluginTracingStub : public ApiHubPluginStub { + public: + ~ApiHubPluginTracingStub() override = default; + + explicit ApiHubPluginTracingStub(std::shared_ptr child); + + StatusOr GetPlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetPluginRequest const& request) override; + + StatusOr EnablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::EnablePluginRequest const& request) override; + + StatusOr DisablePlugin( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DisablePluginRequest const& request) override; + + private: + std::shared_ptr child_; + std::shared_ptr + propagator_; +}; + +#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 MakeApiHubPluginTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_PLUGIN_TRACING_STUB_H diff --git a/google/cloud/apihub/v1/internal/api_hub_retry_traits.h b/google/cloud/apihub/v1/internal/api_hub_retry_traits.h new file mode 100644 index 0000000000000..f2375e68354f5 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct ApiHubRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_RETRY_TRAITS_H diff --git a/google/cloud/apihub/v1/internal/api_hub_sources.cc b/google/cloud/apihub/v1/internal/api_hub_sources.cc new file mode 100644 index 0000000000000..1355d5503cf04 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_sources.cc @@ -0,0 +1,32 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/apihub/v1/api_hub_client.cc" +#include "google/cloud/apihub/v1/api_hub_connection.cc" +#include "google/cloud/apihub/v1/api_hub_connection_idempotency_policy.cc" +#include "google/cloud/apihub/v1/internal/api_hub_auth_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_connection_impl.cc" +#include "google/cloud/apihub/v1/internal/api_hub_logging_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_metadata_decorator.cc" +#include "google/cloud/apihub/v1/internal/api_hub_option_defaults.cc" +#include "google/cloud/apihub/v1/internal/api_hub_stub.cc" +#include "google/cloud/apihub/v1/internal/api_hub_stub_factory.cc" +#include "google/cloud/apihub/v1/internal/api_hub_tracing_connection.cc" +#include "google/cloud/apihub/v1/internal/api_hub_tracing_stub.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/apihub/v1/internal/api_hub_stub.cc b/google/cloud/apihub/v1/internal/api_hub_stub.cc new file mode 100644 index 0000000000000..cbca2457e2d66 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_stub.cc @@ -0,0 +1,440 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ApiHubStub::~ApiHubStub() = default; + +StatusOr DefaultApiHubStub::CreateApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateApiRequest const& request) { + google::cloud::apihub::v1::Api response; + auto status = grpc_stub_->CreateApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultApiHubStub::GetApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetApiRequest const& request) { + google::cloud::apihub::v1::Api response; + auto status = grpc_stub_->GetApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::ListApis( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListApisRequest const& request) { + google::cloud::apihub::v1::ListApisResponse response; + auto status = grpc_stub_->ListApis(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultApiHubStub::UpdateApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateApiRequest const& request) { + google::cloud::apihub::v1::Api response; + auto status = grpc_stub_->UpdateApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultApiHubStub::DeleteApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteApiRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->DeleteApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr DefaultApiHubStub::CreateVersion( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateVersionRequest const& request) { + google::cloud::apihub::v1::Version response; + auto status = grpc_stub_->CreateVersion(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultApiHubStub::GetVersion( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetVersionRequest const& request) { + google::cloud::apihub::v1::Version response; + auto status = grpc_stub_->GetVersion(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::ListVersions( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListVersionsRequest const& request) { + google::cloud::apihub::v1::ListVersionsResponse response; + auto status = grpc_stub_->ListVersions(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultApiHubStub::UpdateVersion( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + google::cloud::apihub::v1::Version response; + auto status = grpc_stub_->UpdateVersion(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultApiHubStub::DeleteVersion( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->DeleteVersion(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr DefaultApiHubStub::CreateSpec( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateSpecRequest const& request) { + google::cloud::apihub::v1::Spec response; + auto status = grpc_stub_->CreateSpec(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultApiHubStub::GetSpec( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetSpecRequest const& request) { + google::cloud::apihub::v1::Spec response; + auto status = grpc_stub_->GetSpec(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::GetSpecContents( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + google::cloud::apihub::v1::SpecContents response; + auto status = grpc_stub_->GetSpecContents(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::ListSpecs( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListSpecsRequest const& request) { + google::cloud::apihub::v1::ListSpecsResponse response; + auto status = grpc_stub_->ListSpecs(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultApiHubStub::UpdateSpec( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + google::cloud::apihub::v1::Spec response; + auto status = grpc_stub_->UpdateSpec(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultApiHubStub::DeleteSpec( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->DeleteSpec(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr +DefaultApiHubStub::GetApiOperation( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + google::cloud::apihub::v1::ApiOperation response; + auto status = grpc_stub_->GetApiOperation(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::ListApiOperations( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListApiOperationsRequest const& request) { + google::cloud::apihub::v1::ListApiOperationsResponse response; + auto status = grpc_stub_->ListApiOperations(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::GetDefinition( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + google::cloud::apihub::v1::Definition response; + auto status = grpc_stub_->GetDefinition(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::CreateDeployment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + google::cloud::apihub::v1::Deployment response; + auto status = grpc_stub_->CreateDeployment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::GetDeployment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + google::cloud::apihub::v1::Deployment response; + auto status = grpc_stub_->GetDeployment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::ListDeployments( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) { + google::cloud::apihub::v1::ListDeploymentsResponse response; + auto status = grpc_stub_->ListDeployments(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::UpdateDeployment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + google::cloud::apihub::v1::Deployment response; + auto status = grpc_stub_->UpdateDeployment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultApiHubStub::DeleteDeployment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->DeleteDeployment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr +DefaultApiHubStub::CreateAttribute( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + google::cloud::apihub::v1::Attribute response; + auto status = grpc_stub_->CreateAttribute(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr DefaultApiHubStub::GetAttribute( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetAttributeRequest const& request) { + google::cloud::apihub::v1::Attribute response; + auto status = grpc_stub_->GetAttribute(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::UpdateAttribute( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + google::cloud::apihub::v1::Attribute response; + auto status = grpc_stub_->UpdateAttribute(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultApiHubStub::DeleteAttribute( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->DeleteAttribute(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr +DefaultApiHubStub::ListAttributes( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListAttributesRequest const& request) { + google::cloud::apihub::v1::ListAttributesResponse response; + auto status = grpc_stub_->ListAttributes(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::SearchResources( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::SearchResourcesRequest const& request) { + google::cloud::apihub::v1::SearchResourcesResponse response; + auto status = grpc_stub_->SearchResources(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::CreateExternalApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + google::cloud::apihub::v1::ExternalApi response; + auto status = grpc_stub_->CreateExternalApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::GetExternalApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + google::cloud::apihub::v1::ExternalApi response; + auto status = grpc_stub_->GetExternalApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultApiHubStub::UpdateExternalApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + google::cloud::apihub::v1::ExternalApi response; + auto status = grpc_stub_->UpdateExternalApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultApiHubStub::DeleteExternalApi( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->DeleteExternalApi(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr +DefaultApiHubStub::ListExternalApis( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListExternalApisRequest const& request) { + google::cloud::apihub::v1::ListExternalApisResponse response; + auto status = grpc_stub_->ListExternalApis(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_stub.h b/google/cloud/apihub/v1/internal/api_hub_stub.h new file mode 100644 index 0000000000000..4de103c05c940 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_stub.h @@ -0,0 +1,356 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_STUB_H + +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ApiHubStub { + public: + virtual ~ApiHubStub() = 0; + + virtual StatusOr CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) = 0; + + virtual StatusOr GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) = 0; + + virtual StatusOr ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) = 0; + + virtual StatusOr UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) = 0; + + virtual Status DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) = 0; + + virtual StatusOr CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) = 0; + + virtual StatusOr GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) = 0; + + virtual StatusOr + ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) = 0; + + virtual StatusOr UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) = 0; + + virtual Status DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) = 0; + + virtual StatusOr CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) = 0; + + virtual StatusOr GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) = 0; + + virtual StatusOr GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) = 0; + + virtual StatusOr ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) = 0; + + virtual StatusOr UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) = 0; + + virtual Status DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) = 0; + + virtual StatusOr GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) = 0; + + virtual StatusOr + ListApiOperations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& request) = 0; + + virtual StatusOr GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) = 0; + + virtual StatusOr CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) = 0; + + virtual StatusOr GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) = 0; + + virtual StatusOr + ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) = 0; + + virtual StatusOr UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) = 0; + + virtual Status DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) = 0; + + virtual StatusOr CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) = 0; + + virtual StatusOr GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) = 0; + + virtual StatusOr UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) = 0; + + virtual Status DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) = 0; + + virtual StatusOr + ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) = 0; + + virtual StatusOr + SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) = 0; + + virtual StatusOr CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) = 0; + + virtual StatusOr GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) = 0; + + virtual StatusOr UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) = 0; + + virtual Status DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) = 0; + + virtual StatusOr + ListExternalApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& request) = 0; +}; + +class DefaultApiHubStub : public ApiHubStub { + public: + explicit DefaultApiHubStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) override; + + StatusOr GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) override; + + StatusOr ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) override; + + StatusOr UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) override; + + Status DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) override; + + StatusOr CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) override; + + StatusOr GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) override; + + StatusOr ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) override; + + StatusOr UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) override; + + Status DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) override; + + StatusOr CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) override; + + StatusOr GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) override; + + StatusOr GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) + override; + + StatusOr ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) override; + + StatusOr UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) override; + + Status DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) override; + + StatusOr GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) + override; + + StatusOr + ListApiOperations(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& + request) override; + + StatusOr GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) override; + + StatusOr CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) + override; + + StatusOr GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) override; + + StatusOr ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) + override; + + StatusOr UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) + override; + + Status DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) + override; + + StatusOr CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) + override; + + StatusOr GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) override; + + StatusOr UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) + override; + + Status DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) + override; + + StatusOr ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) override; + + StatusOr SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) + override; + + StatusOr CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) + override; + + StatusOr GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) override; + + StatusOr UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) + override; + + Status DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) + override; + + StatusOr + ListExternalApis(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& + request) override; + + private: + std::unique_ptr grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_STUB_H diff --git a/google/cloud/apihub/v1/internal/api_hub_stub_factory.cc b/google/cloud/apihub/v1/internal/api_hub_stub_factory.cc new file mode 100644 index 0000000000000..35b9606a9959e --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_stub_factory.cc @@ -0,0 +1,69 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_stub_factory.h" +#include "google/cloud/apihub/v1/internal/api_hub_auth_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_logging_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_metadata_decorator.h" +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/apihub/v1/internal/api_hub_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultApiHubStub( + std::shared_ptr auth, + Options const& options) { + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = google::cloud::apihub::v1::ApiHub::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 = MakeApiHubTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_stub_factory.h b/google/cloud/apihub/v1/internal/api_hub_stub_factory.h new file mode 100644 index 0000000000000..f3d9884e9bebc --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_STUB_FACTORY_H + +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultApiHubStub( + std::shared_ptr auth, + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_STUB_FACTORY_H diff --git a/google/cloud/apihub/v1/internal/api_hub_tracing_connection.cc b/google/cloud/apihub/v1/internal/api_hub_tracing_connection.cc new file mode 100644 index 0000000000000..15766bb0ff4d7 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_tracing_connection.cc @@ -0,0 +1,348 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ApiHubTracingConnection::ApiHubTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr ApiHubTracingConnection::CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::CreateApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CreateApi(request)); +} + +StatusOr ApiHubTracingConnection::GetApi( + google::cloud::apihub::v1::GetApiRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::GetApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetApi(request)); +} + +StreamRange ApiHubTracingConnection::ListApis( + google::cloud::apihub::v1::ListApisRequest request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::ListApis"); + internal::OTelScope scope(span); + auto sr = child_->ListApis(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +StatusOr ApiHubTracingConnection::UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::UpdateApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateApi(request)); +} + +Status ApiHubTracingConnection::DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::DeleteApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteApi(request)); +} + +StatusOr +ApiHubTracingConnection::CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::CreateVersion"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CreateVersion(request)); +} + +StatusOr +ApiHubTracingConnection::GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::GetVersion"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetVersion(request)); +} + +StreamRange +ApiHubTracingConnection::ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::ListVersions"); + internal::OTelScope scope(span); + auto sr = child_->ListVersions(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +StatusOr +ApiHubTracingConnection::UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::UpdateVersion"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateVersion(request)); +} + +Status ApiHubTracingConnection::DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::DeleteVersion"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteVersion(request)); +} + +StatusOr ApiHubTracingConnection::CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::CreateSpec"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CreateSpec(request)); +} + +StatusOr ApiHubTracingConnection::GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::GetSpec"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetSpec(request)); +} + +StatusOr +ApiHubTracingConnection::GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::GetSpecContents"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetSpecContents(request)); +} + +StreamRange ApiHubTracingConnection::ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::ListSpecs"); + internal::OTelScope scope(span); + auto sr = child_->ListSpecs(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +StatusOr ApiHubTracingConnection::UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::UpdateSpec"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateSpec(request)); +} + +Status ApiHubTracingConnection::DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::DeleteSpec"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteSpec(request)); +} + +StatusOr +ApiHubTracingConnection::GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::GetApiOperation"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetApiOperation(request)); +} + +StreamRange +ApiHubTracingConnection::ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::ListApiOperations"); + internal::OTelScope scope(span); + auto sr = child_->ListApiOperations(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::apihub::v1::ApiOperation>(std::move(span), std::move(sr)); +} + +StatusOr +ApiHubTracingConnection::GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::GetDefinition"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetDefinition(request)); +} + +StatusOr +ApiHubTracingConnection::CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::CreateDeployment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CreateDeployment(request)); +} + +StatusOr +ApiHubTracingConnection::GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::GetDeployment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetDeployment(request)); +} + +StreamRange +ApiHubTracingConnection::ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::ListDeployments"); + internal::OTelScope scope(span); + auto sr = child_->ListDeployments(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +StatusOr +ApiHubTracingConnection::UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::UpdateDeployment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateDeployment(request)); +} + +Status ApiHubTracingConnection::DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::DeleteDeployment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteDeployment(request)); +} + +StatusOr +ApiHubTracingConnection::CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::CreateAttribute"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CreateAttribute(request)); +} + +StatusOr +ApiHubTracingConnection::GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::GetAttribute"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetAttribute(request)); +} + +StatusOr +ApiHubTracingConnection::UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::UpdateAttribute"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateAttribute(request)); +} + +Status ApiHubTracingConnection::DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::DeleteAttribute"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteAttribute(request)); +} + +StreamRange +ApiHubTracingConnection::ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::ListAttributes"); + internal::OTelScope scope(span); + auto sr = child_->ListAttributes(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +StreamRange +ApiHubTracingConnection::SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::SearchResources"); + internal::OTelScope scope(span); + auto sr = child_->SearchResources(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::apihub::v1::SearchResult>(std::move(span), std::move(sr)); +} + +StatusOr +ApiHubTracingConnection::CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::CreateExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CreateExternalApi(request)); +} + +StatusOr +ApiHubTracingConnection::GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + auto span = internal::MakeSpan("apihub_v1::ApiHubConnection::GetExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetExternalApi(request)); +} + +StatusOr +ApiHubTracingConnection::UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::UpdateExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateExternalApi(request)); +} + +Status ApiHubTracingConnection::DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::DeleteExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteExternalApi(request)); +} + +StreamRange +ApiHubTracingConnection::ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest request) { + auto span = + internal::MakeSpan("apihub_v1::ApiHubConnection::ListExternalApis"); + internal::OTelScope scope(span); + auto sr = child_->ListExternalApis(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::apihub::v1::ExternalApi>(std::move(span), std::move(sr)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeApiHubTracingConnection( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_tracing_connection.h b/google/cloud/apihub/v1/internal/api_hub_tracing_connection.h new file mode 100644 index 0000000000000..4bdd9a6d5ff94 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_tracing_connection.h @@ -0,0 +1,178 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_TRACING_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ApiHubTracingConnection : public apihub_v1::ApiHubConnection { + public: + ~ApiHubTracingConnection() override = default; + + explicit ApiHubTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr CreateApi( + google::cloud::apihub::v1::CreateApiRequest const& request) override; + + StatusOr GetApi( + google::cloud::apihub::v1::GetApiRequest const& request) override; + + StreamRange ListApis( + google::cloud::apihub::v1::ListApisRequest request) override; + + StatusOr UpdateApi( + google::cloud::apihub::v1::UpdateApiRequest const& request) override; + + Status DeleteApi( + google::cloud::apihub::v1::DeleteApiRequest const& request) override; + + StatusOr CreateVersion( + google::cloud::apihub::v1::CreateVersionRequest const& request) override; + + StatusOr GetVersion( + google::cloud::apihub::v1::GetVersionRequest const& request) override; + + StreamRange ListVersions( + google::cloud::apihub::v1::ListVersionsRequest request) override; + + StatusOr UpdateVersion( + google::cloud::apihub::v1::UpdateVersionRequest const& request) override; + + Status DeleteVersion( + google::cloud::apihub::v1::DeleteVersionRequest const& request) override; + + StatusOr CreateSpec( + google::cloud::apihub::v1::CreateSpecRequest const& request) override; + + StatusOr GetSpec( + google::cloud::apihub::v1::GetSpecRequest const& request) override; + + StatusOr GetSpecContents( + google::cloud::apihub::v1::GetSpecContentsRequest const& request) + override; + + StreamRange ListSpecs( + google::cloud::apihub::v1::ListSpecsRequest request) override; + + StatusOr UpdateSpec( + google::cloud::apihub::v1::UpdateSpecRequest const& request) override; + + Status DeleteSpec( + google::cloud::apihub::v1::DeleteSpecRequest const& request) override; + + StatusOr GetApiOperation( + google::cloud::apihub::v1::GetApiOperationRequest const& request) + override; + + StreamRange ListApiOperations( + google::cloud::apihub::v1::ListApiOperationsRequest request) override; + + StatusOr GetDefinition( + google::cloud::apihub::v1::GetDefinitionRequest const& request) override; + + StatusOr CreateDeployment( + google::cloud::apihub::v1::CreateDeploymentRequest const& request) + override; + + StatusOr GetDeployment( + google::cloud::apihub::v1::GetDeploymentRequest const& request) override; + + StreamRange ListDeployments( + google::cloud::apihub::v1::ListDeploymentsRequest request) override; + + StatusOr UpdateDeployment( + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) + override; + + Status DeleteDeployment( + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) + override; + + StatusOr CreateAttribute( + google::cloud::apihub::v1::CreateAttributeRequest const& request) + override; + + StatusOr GetAttribute( + google::cloud::apihub::v1::GetAttributeRequest const& request) override; + + StatusOr UpdateAttribute( + google::cloud::apihub::v1::UpdateAttributeRequest const& request) + override; + + Status DeleteAttribute( + google::cloud::apihub::v1::DeleteAttributeRequest const& request) + override; + + StreamRange ListAttributes( + google::cloud::apihub::v1::ListAttributesRequest request) override; + + StreamRange SearchResources( + google::cloud::apihub::v1::SearchResourcesRequest request) override; + + StatusOr CreateExternalApi( + google::cloud::apihub::v1::CreateExternalApiRequest const& request) + override; + + StatusOr GetExternalApi( + google::cloud::apihub::v1::GetExternalApiRequest const& request) override; + + StatusOr UpdateExternalApi( + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) + override; + + Status DeleteExternalApi( + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) + override; + + StreamRange ListExternalApis( + google::cloud::apihub::v1::ListExternalApisRequest 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 MakeApiHubTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_TRACING_CONNECTION_H diff --git a/google/cloud/apihub/v1/internal/api_hub_tracing_stub.cc b/google/cloud/apihub/v1/internal/api_hub_tracing_stub.cc new file mode 100644 index 0000000000000..02a6202f14920 --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_tracing_stub.cc @@ -0,0 +1,451 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/internal/api_hub_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ApiHubTracingStub::ApiHubTracingStub(std::shared_ptr child) + : child_(std::move(child)), propagator_(internal::MakePropagator()) {} + +StatusOr ApiHubTracingStub::CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "CreateApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->CreateApi(context, options, request)); +} + +StatusOr ApiHubTracingStub::GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "GetApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetApi(context, options, request)); +} + +StatusOr +ApiHubTracingStub::ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "ListApis"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->ListApis(context, options, request)); +} + +StatusOr ApiHubTracingStub::UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "UpdateApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->UpdateApi(context, options, request)); +} + +Status ApiHubTracingStub::DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "DeleteApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->DeleteApi(context, options, request)); +} + +StatusOr ApiHubTracingStub::CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "CreateVersion"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->CreateVersion(context, options, request)); +} + +StatusOr ApiHubTracingStub::GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "GetVersion"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetVersion(context, options, request)); +} + +StatusOr +ApiHubTracingStub::ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "ListVersions"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->ListVersions(context, options, request)); +} + +StatusOr ApiHubTracingStub::UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "UpdateVersion"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->UpdateVersion(context, options, request)); +} + +Status ApiHubTracingStub::DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "DeleteVersion"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->DeleteVersion(context, options, request)); +} + +StatusOr ApiHubTracingStub::CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "CreateSpec"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->CreateSpec(context, options, request)); +} + +StatusOr ApiHubTracingStub::GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "GetSpec"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetSpec(context, options, request)); +} + +StatusOr +ApiHubTracingStub::GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "GetSpecContents"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetSpecContents(context, options, request)); +} + +StatusOr +ApiHubTracingStub::ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "ListSpecs"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->ListSpecs(context, options, request)); +} + +StatusOr ApiHubTracingStub::UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "UpdateSpec"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->UpdateSpec(context, options, request)); +} + +Status ApiHubTracingStub::DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "DeleteSpec"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->DeleteSpec(context, options, request)); +} + +StatusOr +ApiHubTracingStub::GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "GetApiOperation"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetApiOperation(context, options, request)); +} + +StatusOr +ApiHubTracingStub::ListApiOperations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "ListApiOperations"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->ListApiOperations(context, options, request)); +} + +StatusOr +ApiHubTracingStub::GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "GetDefinition"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetDefinition(context, options, request)); +} + +StatusOr +ApiHubTracingStub::CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "CreateDeployment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->CreateDeployment(context, options, request)); +} + +StatusOr +ApiHubTracingStub::GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "GetDeployment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetDeployment(context, options, request)); +} + +StatusOr +ApiHubTracingStub::ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "ListDeployments"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->ListDeployments(context, options, request)); +} + +StatusOr +ApiHubTracingStub::UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "UpdateDeployment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->UpdateDeployment(context, options, request)); +} + +Status ApiHubTracingStub::DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "DeleteDeployment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->DeleteDeployment(context, options, request)); +} + +StatusOr +ApiHubTracingStub::CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "CreateAttribute"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->CreateAttribute(context, options, request)); +} + +StatusOr ApiHubTracingStub::GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "GetAttribute"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetAttribute(context, options, request)); +} + +StatusOr +ApiHubTracingStub::UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "UpdateAttribute"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->UpdateAttribute(context, options, request)); +} + +Status ApiHubTracingStub::DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "DeleteAttribute"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->DeleteAttribute(context, options, request)); +} + +StatusOr +ApiHubTracingStub::ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "ListAttributes"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->ListAttributes(context, options, request)); +} + +StatusOr +ApiHubTracingStub::SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "SearchResources"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->SearchResources(context, options, request)); +} + +StatusOr +ApiHubTracingStub::CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "CreateExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->CreateExternalApi(context, options, request)); +} + +StatusOr +ApiHubTracingStub::GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", "GetExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetExternalApi(context, options, request)); +} + +StatusOr +ApiHubTracingStub::UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "UpdateExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->UpdateExternalApi(context, options, request)); +} + +Status ApiHubTracingStub::DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "DeleteExternalApi"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->DeleteExternalApi(context, options, request)); +} + +StatusOr +ApiHubTracingStub::ListExternalApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.ApiHub", + "ListExternalApis"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->ListExternalApis(context, options, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeApiHubTracingStub( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/api_hub_tracing_stub.h b/google/cloud/apihub/v1/internal/api_hub_tracing_stub.h new file mode 100644 index 0000000000000..261645e415b0f --- /dev/null +++ b/google/cloud/apihub/v1/internal/api_hub_tracing_stub.h @@ -0,0 +1,218 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_TRACING_STUB_H + +#include "google/cloud/apihub/v1/internal/api_hub_stub.h" +#include "google/cloud/internal/trace_propagator.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ApiHubTracingStub : public ApiHubStub { + public: + ~ApiHubTracingStub() override = default; + + explicit ApiHubTracingStub(std::shared_ptr child); + + StatusOr CreateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiRequest const& request) override; + + StatusOr GetApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiRequest const& request) override; + + StatusOr ListApis( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApisRequest const& request) override; + + StatusOr UpdateApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateApiRequest const& request) override; + + Status DeleteApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteApiRequest const& request) override; + + StatusOr CreateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateVersionRequest const& request) override; + + StatusOr GetVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetVersionRequest const& request) override; + + StatusOr ListVersions( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListVersionsRequest const& request) override; + + StatusOr UpdateVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateVersionRequest const& request) override; + + Status DeleteVersion( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteVersionRequest const& request) override; + + StatusOr CreateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateSpecRequest const& request) override; + + StatusOr GetSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecRequest const& request) override; + + StatusOr GetSpecContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetSpecContentsRequest const& request) + override; + + StatusOr ListSpecs( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListSpecsRequest const& request) override; + + StatusOr UpdateSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateSpecRequest const& request) override; + + Status DeleteSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteSpecRequest const& request) override; + + StatusOr GetApiOperation( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiOperationRequest const& request) + override; + + StatusOr + ListApiOperations(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListApiOperationsRequest const& + request) override; + + StatusOr GetDefinition( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDefinitionRequest const& request) override; + + StatusOr CreateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateDeploymentRequest const& request) + override; + + StatusOr GetDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetDeploymentRequest const& request) override; + + StatusOr ListDeployments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListDeploymentsRequest const& request) + override; + + StatusOr UpdateDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateDeploymentRequest const& request) + override; + + Status DeleteDeployment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteDeploymentRequest const& request) + override; + + StatusOr CreateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateAttributeRequest const& request) + override; + + StatusOr GetAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetAttributeRequest const& request) override; + + StatusOr UpdateAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateAttributeRequest const& request) + override; + + Status DeleteAttribute( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteAttributeRequest const& request) + override; + + StatusOr ListAttributes( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListAttributesRequest const& request) override; + + StatusOr SearchResources( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::SearchResourcesRequest const& request) + override; + + StatusOr CreateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateExternalApiRequest const& request) + override; + + StatusOr GetExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetExternalApiRequest const& request) override; + + StatusOr UpdateExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateExternalApiRequest const& request) + override; + + Status DeleteExternalApi( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteExternalApiRequest const& request) + override; + + StatusOr + ListExternalApis(grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListExternalApisRequest const& + request) override; + + private: + std::shared_ptr child_; + std::shared_ptr + propagator_; +}; + +#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 MakeApiHubTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_API_HUB_TRACING_STUB_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.cc b/google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.cc new file mode 100644 index 0000000000000..dbcbe043e81ef --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.cc @@ -0,0 +1,67 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +HostProjectRegistrationServiceAuth::HostProjectRegistrationServiceAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +HostProjectRegistrationServiceAuth::CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateHostProjectRegistration(context, options, request); +} + +StatusOr +HostProjectRegistrationServiceAuth::GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetHostProjectRegistration(context, options, request); +} + +StatusOr +HostProjectRegistrationServiceAuth::ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListHostProjectRegistrations(context, options, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.h b/google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.h new file mode 100644 index 0000000000000..be001a00f6478 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.h @@ -0,0 +1,70 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_AUTH_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class HostProjectRegistrationServiceAuth + : public HostProjectRegistrationServiceStub { + public: + ~HostProjectRegistrationServiceAuth() override = default; + HostProjectRegistrationServiceAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr + CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) override; + + StatusOr + GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) override; + + StatusOr + ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_AUTH_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_connection_impl.cc b/google/cloud/apihub/v1/internal/host_project_registration_connection_impl.cc new file mode 100644 index 0000000000000..d3547494b7e27 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_connection_impl.cc @@ -0,0 +1,146 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_connection_impl.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_option_defaults.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/retry_loop.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_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< + apihub_v1::HostProjectRegistrationServiceConnectionIdempotencyPolicy> +idempotency_policy(Options const& options) { + return options + .get< + apihub_v1:: + HostProjectRegistrationServiceConnectionIdempotencyPolicyOption>() + ->clone(); +} + +} // namespace + +HostProjectRegistrationServiceConnectionImpl:: + HostProjectRegistrationServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions( + std::move(options), + HostProjectRegistrationServiceConnection::options())) {} + +StatusOr +HostProjectRegistrationServiceConnectionImpl::CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateHostProjectRegistration(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + return stub_->CreateHostProjectRegistration(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +HostProjectRegistrationServiceConnectionImpl::GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetHostProjectRegistration(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + return stub_->GetHostProjectRegistration(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +HostProjectRegistrationServiceConnectionImpl::ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = + idempotency_policy(*current)->ListHostProjectRegistrations(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr< + apihub_v1::HostProjectRegistrationServiceRetryPolicy>( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + ListHostProjectRegistrationsRequest const& request) { + return stub->ListHostProjectRegistrations(context, options, + request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListHostProjectRegistrationsResponse r) { + std::vector result( + r.host_project_registrations().size()); + auto& messages = *r.mutable_host_project_registrations(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_connection_impl.h b/google/cloud/apihub/v1/internal/host_project_registration_connection_impl.h new file mode 100644 index 0000000000000..a7dff65d55981 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_connection_impl.h @@ -0,0 +1,79 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_CONNECTION_IMPL_H + +#include "google/cloud/apihub/v1/host_project_registration_connection.h" +#include "google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/host_project_registration_options.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_retry_traits.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class HostProjectRegistrationServiceConnectionImpl + : public apihub_v1::HostProjectRegistrationServiceConnection { + public: + ~HostProjectRegistrationServiceConnectionImpl() override = default; + + HostProjectRegistrationServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options); + + Options options() override { return options_; } + + StatusOr + CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) override; + + StatusOr + GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) override; + + StreamRange + ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request) + override; + + private: + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_CONNECTION_IMPL_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.cc b/google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.cc new file mode 100644 index 0000000000000..0a63ebfc50efc --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.cc @@ -0,0 +1,85 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +HostProjectRegistrationServiceLogging::HostProjectRegistrationServiceLogging( + std::shared_ptr child, + TracingOptions tracing_options, std::set const&) + : child_(std::move(child)), tracing_options_(std::move(tracing_options)) {} + +StatusOr +HostProjectRegistrationServiceLogging::CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + return child_->CreateHostProjectRegistration(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +HostProjectRegistrationServiceLogging::GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + return child_->GetHostProjectRegistration(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +HostProjectRegistrationServiceLogging::ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) { + return child_->ListHostProjectRegistrations(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.h b/google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.h new file mode 100644 index 0000000000000..3ca381df5ac89 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.h @@ -0,0 +1,70 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_LOGGING_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class HostProjectRegistrationServiceLogging + : public HostProjectRegistrationServiceStub { + public: + ~HostProjectRegistrationServiceLogging() override = default; + HostProjectRegistrationServiceLogging( + std::shared_ptr child, + TracingOptions tracing_options, std::set const& components); + + StatusOr + CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) override; + + StatusOr + GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) override; + + StatusOr + ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; +}; // HostProjectRegistrationServiceLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_LOGGING_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.cc b/google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.cc new file mode 100644 index 0000000000000..88c43253f5bf4 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.cc @@ -0,0 +1,93 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/url_encode.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +HostProjectRegistrationServiceMetadata::HostProjectRegistrationServiceMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +HostProjectRegistrationServiceMetadata::CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateHostProjectRegistration(context, options, request); +} + +StatusOr +HostProjectRegistrationServiceMetadata::GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetHostProjectRegistration(context, options, request); +} + +StatusOr +HostProjectRegistrationServiceMetadata::ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListHostProjectRegistrations(context, options, request); +} + +void HostProjectRegistrationServiceMetadata::SetMetadata( + grpc::ClientContext& context, Options const& options, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context, options); +} + +void HostProjectRegistrationServiceMetadata::SetMetadata( + grpc::ClientContext& context, Options const& options) { + google::cloud::internal::SetMetadata(context, options, fixed_metadata_, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.h b/google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.h new file mode 100644 index 0000000000000..a3d8c8347e979 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_METADATA_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class HostProjectRegistrationServiceMetadata + : public HostProjectRegistrationServiceStub { + public: + ~HostProjectRegistrationServiceMetadata() override = default; + HostProjectRegistrationServiceMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header = ""); + + StatusOr + CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) override; + + StatusOr + GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) override; + + StatusOr + ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) override; + + private: + void SetMetadata(grpc::ClientContext& context, Options const& options, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context, Options const& options); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_METADATA_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_option_defaults.cc b/google/cloud/apihub/v1/internal/host_project_registration_option_defaults.cc new file mode 100644 index 0000000000000..319c3961a4628 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_option_defaults.cc @@ -0,0 +1,74 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_option_defaults.h" +#include "google/cloud/apihub/v1/host_project_registration_connection.h" +#include "google/cloud/apihub/v1/host_project_registration_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options HostProjectRegistrationServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), + "GOOGLE_CLOUD_CPP_HOST_PROJECT_REGISTRATION_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_HOST_PROJECT_REGISTRATION_SERVICE_AUTHORITY", + "apihub.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options + .has()) { + options.set( + apihub_v1::HostProjectRegistrationServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has< + apihub_v1::HostProjectRegistrationServiceBackoffPolicyOption>()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has< + apihub_v1:: + HostProjectRegistrationServiceConnectionIdempotencyPolicyOption>()) { + options.set< + apihub_v1:: + HostProjectRegistrationServiceConnectionIdempotencyPolicyOption>( + apihub_v1:: + MakeDefaultHostProjectRegistrationServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_option_defaults.h b/google/cloud/apihub/v1/internal/host_project_registration_option_defaults.h new file mode 100644 index 0000000000000..6c6304abd8103 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options HostProjectRegistrationServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_OPTION_DEFAULTS_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_retry_traits.h b/google/cloud/apihub/v1/internal/host_project_registration_retry_traits.h new file mode 100644 index 0000000000000..e83e4116c7461 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct HostProjectRegistrationServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_RETRY_TRAITS_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_sources.cc b/google/cloud/apihub/v1/internal/host_project_registration_sources.cc new file mode 100644 index 0000000000000..ad35e893410f7 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_sources.cc @@ -0,0 +1,32 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/apihub/v1/host_project_registration_client.cc" +#include "google/cloud/apihub/v1/host_project_registration_connection.cc" +#include "google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_connection_impl.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_option_defaults.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_stub_factory.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.cc" +#include "google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/apihub/v1/internal/host_project_registration_stub.cc b/google/cloud/apihub/v1/internal/host_project_registration_stub.cc new file mode 100644 index 0000000000000..5b2136bb7fdaa --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_stub.cc @@ -0,0 +1,79 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +HostProjectRegistrationServiceStub::~HostProjectRegistrationServiceStub() = + default; + +StatusOr +DefaultHostProjectRegistrationServiceStub::CreateHostProjectRegistration( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + google::cloud::apihub::v1::HostProjectRegistration response; + auto status = + grpc_stub_->CreateHostProjectRegistration(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultHostProjectRegistrationServiceStub::GetHostProjectRegistration( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + google::cloud::apihub::v1::HostProjectRegistration response; + auto status = + grpc_stub_->GetHostProjectRegistration(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultHostProjectRegistrationServiceStub::ListHostProjectRegistrations( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) { + google::cloud::apihub::v1::ListHostProjectRegistrationsResponse response; + auto status = + grpc_stub_->ListHostProjectRegistrations(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_stub.h b/google/cloud/apihub/v1/internal/host_project_registration_stub.h new file mode 100644 index 0000000000000..c8dcbe3784c11 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_stub.h @@ -0,0 +1,96 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_STUB_H + +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class HostProjectRegistrationServiceStub { + public: + virtual ~HostProjectRegistrationServiceStub() = 0; + + virtual StatusOr + CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) = 0; + + virtual StatusOr + GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) = 0; + + virtual StatusOr< + google::cloud::apihub::v1::ListHostProjectRegistrationsResponse> + ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) = 0; +}; + +class DefaultHostProjectRegistrationServiceStub + : public HostProjectRegistrationServiceStub { + public: + explicit DefaultHostProjectRegistrationServiceStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr + CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) override; + + StatusOr + GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) override; + + StatusOr + ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) override; + + private: + std::unique_ptr< + google::cloud::apihub::v1::HostProjectRegistrationService::StubInterface> + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_STUB_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_stub_factory.cc b/google/cloud/apihub/v1/internal/host_project_registration_stub_factory.cc new file mode 100644 index 0000000000000..a77dde73d17d9 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_stub_factory.cc @@ -0,0 +1,74 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_stub_factory.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_auth_decorator.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_logging_decorator.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_metadata_decorator.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/apihub/v1/internal/host_project_registration_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr +CreateDefaultHostProjectRegistrationServiceStub( + std::shared_ptr auth, + Options const& options) { + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = + google::cloud::apihub::v1::HostProjectRegistrationService::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 = MakeHostProjectRegistrationServiceTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_stub_factory.h b/google/cloud/apihub/v1/internal/host_project_registration_stub_factory.h new file mode 100644 index 0000000000000..75662cb833fbf --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_stub_factory.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_STUB_FACTORY_H + +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr +CreateDefaultHostProjectRegistrationServiceStub( + std::shared_ptr auth, + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_STUB_FACTORY_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.cc b/google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.cc new file mode 100644 index 0000000000000..f40797596e1a0 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.cc @@ -0,0 +1,91 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +HostProjectRegistrationServiceTracingConnection:: + HostProjectRegistrationServiceTracingConnection( + std::shared_ptr + child) + : child_(std::move(child)) {} + +StatusOr +HostProjectRegistrationServiceTracingConnection::CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + auto span = internal::MakeSpan( + "apihub_v1::HostProjectRegistrationServiceConnection::" + "CreateHostProjectRegistration"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, + child_->CreateHostProjectRegistration(request)); +} + +StatusOr +HostProjectRegistrationServiceTracingConnection::GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + auto span = internal::MakeSpan( + "apihub_v1::HostProjectRegistrationServiceConnection::" + "GetHostProjectRegistration"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetHostProjectRegistration(request)); +} + +StreamRange +HostProjectRegistrationServiceTracingConnection::ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request) { + auto span = internal::MakeSpan( + "apihub_v1::HostProjectRegistrationServiceConnection::" + "ListHostProjectRegistrations"); + internal::OTelScope scope(span); + auto sr = child_->ListHostProjectRegistrations(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::apihub::v1::HostProjectRegistration>(std::move(span), + std::move(sr)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeHostProjectRegistrationServiceTracingConnection( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.h b/google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.h new file mode 100644 index 0000000000000..c62103756cc32 --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_tracing_connection.h @@ -0,0 +1,80 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_TRACING_CONNECTION_H + +#include "google/cloud/apihub/v1/host_project_registration_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class HostProjectRegistrationServiceTracingConnection + : public apihub_v1::HostProjectRegistrationServiceConnection { + public: + ~HostProjectRegistrationServiceTracingConnection() override = default; + + explicit HostProjectRegistrationServiceTracingConnection( + std::shared_ptr + child); + + Options options() override { return child_->options(); } + + StatusOr + CreateHostProjectRegistration( + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) override; + + StatusOr + GetHostProjectRegistration( + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) override; + + StreamRange + ListHostProjectRegistrations( + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest 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 +MakeHostProjectRegistrationServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_TRACING_CONNECTION_H diff --git a/google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.cc b/google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.cc new file mode 100644 index 0000000000000..f489d713bdd0a --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.cc @@ -0,0 +1,97 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +HostProjectRegistrationServiceTracingStub:: + HostProjectRegistrationServiceTracingStub( + std::shared_ptr child) + : child_(std::move(child)), propagator_(internal::MakePropagator()) {} + +StatusOr +HostProjectRegistrationServiceTracingStub::CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.HostProjectRegistrationService", + "CreateHostProjectRegistration"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->CreateHostProjectRegistration(context, options, request)); +} + +StatusOr +HostProjectRegistrationServiceTracingStub::GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.HostProjectRegistrationService", + "GetHostProjectRegistration"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->GetHostProjectRegistration(context, options, request)); +} + +StatusOr +HostProjectRegistrationServiceTracingStub::ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.HostProjectRegistrationService", + "ListHostProjectRegistrations"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->ListHostProjectRegistrations(context, options, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeHostProjectRegistrationServiceTracingStub( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.h b/google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.h new file mode 100644 index 0000000000000..fb1a8e38a626d --- /dev/null +++ b/google/cloud/apihub/v1/internal/host_project_registration_tracing_stub.h @@ -0,0 +1,84 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_TRACING_STUB_H + +#include "google/cloud/apihub/v1/internal/host_project_registration_stub.h" +#include "google/cloud/internal/trace_propagator.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class HostProjectRegistrationServiceTracingStub + : public HostProjectRegistrationServiceStub { + public: + ~HostProjectRegistrationServiceTracingStub() override = default; + + explicit HostProjectRegistrationServiceTracingStub( + std::shared_ptr child); + + StatusOr + CreateHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request) override; + + StatusOr + GetHostProjectRegistration( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request) override; + + StatusOr + ListHostProjectRegistrations( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListHostProjectRegistrationsRequest const& + request) override; + + private: + std::shared_ptr child_; + std::shared_ptr + propagator_; +}; + +#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 +MakeHostProjectRegistrationServiceTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_HOST_PROJECT_REGISTRATION_TRACING_STUB_H diff --git a/google/cloud/apihub/v1/internal/linting_auth_decorator.cc b/google/cloud/apihub/v1/internal/linting_auth_decorator.cc new file mode 100644 index 0000000000000..4c4260955be8d --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_auth_decorator.cc @@ -0,0 +1,72 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_auth_decorator.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +LintingServiceAuth::LintingServiceAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +LintingServiceAuth::GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetStyleGuide(context, options, request); +} + +StatusOr +LintingServiceAuth::UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->UpdateStyleGuide(context, options, request); +} + +StatusOr +LintingServiceAuth::GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetStyleGuideContents(context, options, request); +} + +Status LintingServiceAuth::LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->LintSpec(context, options, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_auth_decorator.h b/google/cloud/apihub/v1/internal/linting_auth_decorator.h new file mode 100644 index 0000000000000..01ac45d74327f --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_auth_decorator.h @@ -0,0 +1,69 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_AUTH_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class LintingServiceAuth : public LintingServiceStub { + public: + ~LintingServiceAuth() override = default; + LintingServiceAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) override; + + StatusOr UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) + override; + + StatusOr GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) + override; + + Status LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_AUTH_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/linting_connection_impl.cc b/google/cloud/apihub/v1/internal/linting_connection_impl.cc new file mode 100644 index 0000000000000..f3c6316ca85d8 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_connection_impl.cc @@ -0,0 +1,121 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_connection_impl.h" +#include "google/cloud/apihub/v1/internal/linting_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_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 + +LintingServiceConnectionImpl::LintingServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + LintingServiceConnection::options())) {} + +StatusOr +LintingServiceConnectionImpl::GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetStyleGuide(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + return stub_->GetStyleGuide(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +LintingServiceConnectionImpl::UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateStyleGuide(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + return stub_->UpdateStyleGuide(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +LintingServiceConnectionImpl::GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetStyleGuideContents(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& + request) { + return stub_->GetStyleGuideContents(context, options, request); + }, + *current, request, __func__); +} + +Status LintingServiceConnectionImpl::LintSpec( + google::cloud::apihub::v1::LintSpecRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->LintSpec(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) { + return stub_->LintSpec(context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_connection_impl.h b/google/cloud/apihub/v1/internal/linting_connection_impl.h new file mode 100644 index 0000000000000..53f5675178816 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_connection_impl.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_CONNECTION_IMPL_H + +#include "google/cloud/apihub/v1/internal/linting_retry_traits.h" +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/apihub/v1/linting_connection.h" +#include "google/cloud/apihub/v1/linting_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/linting_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 apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class LintingServiceConnectionImpl + : public apihub_v1::LintingServiceConnection { + public: + ~LintingServiceConnectionImpl() override = default; + + LintingServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StatusOr GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request) override; + + StatusOr UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) + override; + + StatusOr GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) + override; + + Status LintSpec( + google::cloud::apihub::v1::LintSpecRequest const& request) override; + + private: + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_CONNECTION_IMPL_H diff --git a/google/cloud/apihub/v1/internal/linting_logging_decorator.cc b/google/cloud/apihub/v1/internal/linting_logging_decorator.cc new file mode 100644 index 0000000000000..e9fee407ee6d6 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_logging_decorator.cc @@ -0,0 +1,90 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +LintingServiceLogging::LintingServiceLogging( + std::shared_ptr child, TracingOptions tracing_options, + std::set const&) + : child_(std::move(child)), tracing_options_(std::move(tracing_options)) {} + +StatusOr +LintingServiceLogging::GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + return child_->GetStyleGuide(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +LintingServiceLogging::UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + return child_->UpdateStyleGuide(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +LintingServiceLogging::GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& + request) { + return child_->GetStyleGuideContents(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status LintingServiceLogging::LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) { + return child_->LintSpec(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_logging_decorator.h b/google/cloud/apihub/v1/internal/linting_logging_decorator.h new file mode 100644 index 0000000000000..f3b9ccbaf8ce1 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_logging_decorator.h @@ -0,0 +1,69 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_LOGGING_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class LintingServiceLogging : public LintingServiceStub { + public: + ~LintingServiceLogging() override = default; + LintingServiceLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components); + + StatusOr GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) override; + + StatusOr UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) + override; + + StatusOr GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) + override; + + Status LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; +}; // LintingServiceLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_LOGGING_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/linting_metadata_decorator.cc b/google/cloud/apihub/v1/internal/linting_metadata_decorator.cc new file mode 100644 index 0000000000000..325a98e6a0e80 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_metadata_decorator.cc @@ -0,0 +1,99 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_metadata_decorator.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/url_encode.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +LintingServiceMetadata::LintingServiceMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +LintingServiceMetadata::GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetStyleGuide(context, options, request); +} + +StatusOr +LintingServiceMetadata::UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + SetMetadata(context, options, + absl::StrCat("style_guide.name=", + internal::UrlEncode(request.style_guide().name()))); + return child_->UpdateStyleGuide(context, options, request); +} + +StatusOr +LintingServiceMetadata::GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetStyleGuideContents(context, options, request); +} + +Status LintingServiceMetadata::LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->LintSpec(context, options, request); +} + +void LintingServiceMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context, options); +} + +void LintingServiceMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options) { + google::cloud::internal::SetMetadata(context, options, fixed_metadata_, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_metadata_decorator.h b/google/cloud/apihub/v1/internal/linting_metadata_decorator.h new file mode 100644 index 0000000000000..5842ff5c80704 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_metadata_decorator.h @@ -0,0 +1,74 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_METADATA_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class LintingServiceMetadata : public LintingServiceStub { + public: + ~LintingServiceMetadata() override = default; + LintingServiceMetadata(std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header = ""); + + StatusOr GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) override; + + StatusOr UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) + override; + + StatusOr GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) + override; + + Status LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) override; + + private: + void SetMetadata(grpc::ClientContext& context, Options const& options, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context, Options const& options); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_METADATA_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/linting_option_defaults.cc b/google/cloud/apihub/v1/internal/linting_option_defaults.cc new file mode 100644 index 0000000000000..5a47cba9db119 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_option_defaults.cc @@ -0,0 +1,66 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_option_defaults.h" +#include "google/cloud/apihub/v1/linting_connection.h" +#include "google/cloud/apihub/v1/linting_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options LintingServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_LINTING_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_LINTING_SERVICE_AUTHORITY", "apihub.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + apihub_v1::LintingServiceLimitedTimeRetryPolicy( + 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( + apihub_v1::MakeDefaultLintingServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_option_defaults.h b/google/cloud/apihub/v1/internal/linting_option_defaults.h new file mode 100644 index 0000000000000..93d2432b72775 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options LintingServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_OPTION_DEFAULTS_H diff --git a/google/cloud/apihub/v1/internal/linting_retry_traits.h b/google/cloud/apihub/v1/internal/linting_retry_traits.h new file mode 100644 index 0000000000000..25412692e1a70 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct LintingServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_RETRY_TRAITS_H diff --git a/google/cloud/apihub/v1/internal/linting_sources.cc b/google/cloud/apihub/v1/internal/linting_sources.cc new file mode 100644 index 0000000000000..38c36e33706f1 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_sources.cc @@ -0,0 +1,32 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/apihub/v1/internal/linting_auth_decorator.cc" +#include "google/cloud/apihub/v1/internal/linting_connection_impl.cc" +#include "google/cloud/apihub/v1/internal/linting_logging_decorator.cc" +#include "google/cloud/apihub/v1/internal/linting_metadata_decorator.cc" +#include "google/cloud/apihub/v1/internal/linting_option_defaults.cc" +#include "google/cloud/apihub/v1/internal/linting_stub.cc" +#include "google/cloud/apihub/v1/internal/linting_stub_factory.cc" +#include "google/cloud/apihub/v1/internal/linting_tracing_connection.cc" +#include "google/cloud/apihub/v1/internal/linting_tracing_stub.cc" +#include "google/cloud/apihub/v1/linting_client.cc" +#include "google/cloud/apihub/v1/linting_connection.cc" +#include "google/cloud/apihub/v1/linting_connection_idempotency_policy.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/apihub/v1/internal/linting_stub.cc b/google/cloud/apihub/v1/internal/linting_stub.cc new file mode 100644 index 0000000000000..3233ddb11a380 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_stub.cc @@ -0,0 +1,83 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +LintingServiceStub::~LintingServiceStub() = default; + +StatusOr +DefaultLintingServiceStub::GetStyleGuide( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + google::cloud::apihub::v1::StyleGuide response; + auto status = grpc_stub_->GetStyleGuide(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultLintingServiceStub::UpdateStyleGuide( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + google::cloud::apihub::v1::StyleGuide response; + auto status = grpc_stub_->UpdateStyleGuide(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultLintingServiceStub::GetStyleGuideContents( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) { + google::cloud::apihub::v1::StyleGuideContents response; + auto status = grpc_stub_->GetStyleGuideContents(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultLintingServiceStub::LintSpec( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::LintSpecRequest const& request) { + google::protobuf::Empty response; + auto status = grpc_stub_->LintSpec(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_stub.h b/google/cloud/apihub/v1/internal/linting_stub.h new file mode 100644 index 0000000000000..c527f0acc7a5e --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_stub.h @@ -0,0 +1,92 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_STUB_H + +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class LintingServiceStub { + public: + virtual ~LintingServiceStub() = 0; + + virtual StatusOr GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) = 0; + + virtual StatusOr UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) = 0; + + virtual StatusOr + GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& + request) = 0; + + virtual Status LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) = 0; +}; + +class DefaultLintingServiceStub : public LintingServiceStub { + public: + explicit DefaultLintingServiceStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) override; + + StatusOr UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) + override; + + StatusOr GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) + override; + + Status LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) override; + + private: + std::unique_ptr + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_STUB_H diff --git a/google/cloud/apihub/v1/internal/linting_stub_factory.cc b/google/cloud/apihub/v1/internal/linting_stub_factory.cc new file mode 100644 index 0000000000000..46896430def88 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_stub_factory.cc @@ -0,0 +1,71 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_stub_factory.h" +#include "google/cloud/apihub/v1/internal/linting_auth_decorator.h" +#include "google/cloud/apihub/v1/internal/linting_logging_decorator.h" +#include "google/cloud/apihub/v1/internal/linting_metadata_decorator.h" +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/apihub/v1/internal/linting_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultLintingServiceStub( + std::shared_ptr auth, + Options const& options) { + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = + google::cloud::apihub::v1::LintingService::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 = MakeLintingServiceTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_stub_factory.h b/google/cloud/apihub/v1/internal/linting_stub_factory.h new file mode 100644 index 0000000000000..bc6d4762c8e26 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_STUB_FACTORY_H + +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultLintingServiceStub( + std::shared_ptr auth, + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_STUB_FACTORY_H diff --git a/google/cloud/apihub/v1/internal/linting_tracing_connection.cc b/google/cloud/apihub/v1/internal/linting_tracing_connection.cc new file mode 100644 index 0000000000000..68a701fd64193 --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_tracing_connection.cc @@ -0,0 +1,86 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +LintingServiceTracingConnection::LintingServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +LintingServiceTracingConnection::GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::LintingServiceConnection::GetStyleGuide"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetStyleGuide(request)); +} + +StatusOr +LintingServiceTracingConnection::UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::LintingServiceConnection::UpdateStyleGuide"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateStyleGuide(request)); +} + +StatusOr +LintingServiceTracingConnection::GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::LintingServiceConnection::GetStyleGuideContents"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetStyleGuideContents(request)); +} + +Status LintingServiceTracingConnection::LintSpec( + google::cloud::apihub::v1::LintSpecRequest const& request) { + auto span = + internal::MakeSpan("apihub_v1::LintingServiceConnection::LintSpec"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->LintSpec(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeLintingServiceTracingConnection( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_tracing_connection.h b/google/cloud/apihub/v1/internal/linting_tracing_connection.h new file mode 100644 index 0000000000000..536accdc33fec --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_tracing_connection.h @@ -0,0 +1,78 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_TRACING_CONNECTION_H + +#include "google/cloud/apihub/v1/linting_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class LintingServiceTracingConnection + : public apihub_v1::LintingServiceConnection { + public: + ~LintingServiceTracingConnection() override = default; + + explicit LintingServiceTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request) override; + + StatusOr UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) + override; + + StatusOr GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) + override; + + Status LintSpec( + google::cloud::apihub::v1::LintSpecRequest 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 +MakeLintingServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_TRACING_CONNECTION_H diff --git a/google/cloud/apihub/v1/internal/linting_tracing_stub.cc b/google/cloud/apihub/v1/internal/linting_tracing_stub.cc new file mode 100644 index 0000000000000..cf495a39452ea --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_tracing_stub.cc @@ -0,0 +1,96 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/internal/linting_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +LintingServiceTracingStub::LintingServiceTracingStub( + std::shared_ptr child) + : child_(std::move(child)), propagator_(internal::MakePropagator()) {} + +StatusOr +LintingServiceTracingStub::GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.LintingService", + "GetStyleGuide"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->GetStyleGuide(context, options, request)); +} + +StatusOr +LintingServiceTracingStub::UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.LintingService", + "UpdateStyleGuide"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->UpdateStyleGuide(context, options, request)); +} + +StatusOr +LintingServiceTracingStub::GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.LintingService", + "GetStyleGuideContents"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->GetStyleGuideContents(context, options, request)); +} + +Status LintingServiceTracingStub::LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.LintingService", + "LintSpec"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan(context, *span, + child_->LintSpec(context, options, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeLintingServiceTracingStub( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/linting_tracing_stub.h b/google/cloud/apihub/v1/internal/linting_tracing_stub.h new file mode 100644 index 0000000000000..0d17fe626b06e --- /dev/null +++ b/google/cloud/apihub/v1/internal/linting_tracing_stub.h @@ -0,0 +1,81 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_TRACING_STUB_H + +#include "google/cloud/apihub/v1/internal/linting_stub.h" +#include "google/cloud/internal/trace_propagator.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class LintingServiceTracingStub : public LintingServiceStub { + public: + ~LintingServiceTracingStub() override = default; + + explicit LintingServiceTracingStub(std::shared_ptr child); + + StatusOr GetStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideRequest const& request) override; + + StatusOr UpdateStyleGuide( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request) + override; + + StatusOr GetStyleGuideContents( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request) + override; + + Status LintSpec( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LintSpecRequest const& request) override; + + private: + std::shared_ptr child_; + std::shared_ptr + propagator_; +}; + +#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 MakeLintingServiceTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_LINTING_TRACING_STUB_H diff --git a/google/cloud/apihub/v1/internal/provisioning_auth_decorator.cc b/google/cloud/apihub/v1/internal/provisioning_auth_decorator.cc new file mode 100644 index 0000000000000..051b157889acf --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_auth_decorator.cc @@ -0,0 +1,119 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_auth_decorator.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProvisioningAuth::ProvisioningAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +future> +ProvisioningAuth::AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + using ReturnType = StatusOr; + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child = child_, options = std::move(options), + request](future>> + f) mutable { + auto context = f.get(); + if (!context) { + return make_ready_future(ReturnType(std::move(context).status())); + } + return child->AsyncCreateApiHubInstance(cq, *std::move(context), + std::move(options), request); + }); +} + +StatusOr ProvisioningAuth::CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateApiHubInstance(context, options, request); +} + +StatusOr +ProvisioningAuth::GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetApiHubInstance(context, options, request); +} + +StatusOr +ProvisioningAuth::LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->LookupApiHubInstance(context, options, request); +} + +future> +ProvisioningAuth::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) { + using ReturnType = StatusOr; + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child = child_, options = std::move(options), + 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), + std::move(options), request); + }); +} + +future ProvisioningAuth::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) { + return auth_->AsyncConfigureContext(std::move(context)) + .then([cq, child = child_, options = std::move(options), + 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), + std::move(options), request); + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_auth_decorator.h b/google/cloud/apihub/v1/internal/provisioning_auth_decorator.h new file mode 100644 index 0000000000000..41ccf2f8c771d --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_auth_decorator.h @@ -0,0 +1,87 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_AUTH_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProvisioningAuth : public ProvisioningStub { + public: + ~ProvisioningAuth() override = default; + ProvisioningAuth( + std::shared_ptr auth, + std::shared_ptr child); + + future> AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) + override; + + StatusOr + LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) + override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_AUTH_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/provisioning_connection_impl.cc b/google/cloud/apihub/v1/internal/provisioning_connection_impl.cc new file mode 100644 index 0000000000000..3b1efa107c684 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_connection_impl.cc @@ -0,0 +1,191 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_connection_impl.h" +#include "google/cloud/apihub/v1/internal/provisioning_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/retry_loop.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_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(); +} + +std::unique_ptr polling_policy(Options const& options) { + return options.get()->clone(); +} + +} // namespace + +ProvisioningConnectionImpl::ProvisioningConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + ProvisioningConnection::options())) {} + +future> +ProvisioningConnectionImpl::CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + auto request_copy = request; + auto const idempotent = + idempotency_policy(*current)->CreateApiHubInstance(request_copy); + return google::cloud::internal::AsyncLongRunningOperation< + google::cloud::apihub::v1::ApiHubInstance>( + background_->cq(), current, std::move(request_copy), + [stub = stub_]( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& + request) { + return stub->AsyncCreateApiHubInstance(cq, std::move(context), + std::move(options), request); + }, + [stub = stub_](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) { + return stub->AsyncGetOperation(cq, std::move(context), + std::move(options), request); + }, + [stub = stub_]( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) { + return stub->AsyncCancelOperation(cq, std::move(context), + std::move(options), request); + }, + &google::cloud::internal::ExtractLongRunningResultResponse< + google::cloud::apihub::v1::ApiHubInstance>, + retry_policy(*current), backoff_policy(*current), idempotent, + polling_policy(*current), __func__); +} + +StatusOr +ProvisioningConnectionImpl::CreateApiHubInstance( + NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateApiHubInstance(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& + request) { + return stub_->CreateApiHubInstance(context, options, request); + }, + *current, request, __func__); +} + +future> +ProvisioningConnectionImpl::CreateApiHubInstance( + google::longrunning::Operation const& operation) { + auto current = google::cloud::internal::SaveCurrentOptions(); + if (!operation.metadata() + .Is()) { + return make_ready_future< + StatusOr>( + internal::InvalidArgumentError( + "operation does not correspond to CreateApiHubInstance", + GCP_ERROR_INFO().WithMetadata("operation", + operation.metadata().DebugString()))); + } + + return google::cloud::internal::AsyncAwaitLongRunningOperation< + google::cloud::apihub::v1::ApiHubInstance>( + background_->cq(), current, operation, + [stub = stub_](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) { + return stub->AsyncGetOperation(cq, std::move(context), + std::move(options), request); + }, + [stub = stub_]( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) { + return stub->AsyncCancelOperation(cq, std::move(context), + std::move(options), request); + }, + &google::cloud::internal::ExtractLongRunningResultResponse< + google::cloud::apihub::v1::ApiHubInstance>, + polling_policy(*current), __func__); +} + +StatusOr +ProvisioningConnectionImpl::GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetApiHubInstance(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + return stub_->GetApiHubInstance(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +ProvisioningConnectionImpl::LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->LookupApiHubInstance(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& + request) { + return stub_->LookupApiHubInstance(context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_connection_impl.h b/google/cloud/apihub/v1/internal/provisioning_connection_impl.h new file mode 100644 index 0000000000000..233dd67babd4e --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_connection_impl.h @@ -0,0 +1,87 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_CONNECTION_IMPL_H + +#include "google/cloud/apihub/v1/internal/provisioning_retry_traits.h" +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/apihub/v1/provisioning_connection.h" +#include "google/cloud/apihub/v1/provisioning_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/provisioning_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/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProvisioningConnectionImpl : public apihub_v1::ProvisioningConnection { + public: + ~ProvisioningConnectionImpl() override = default; + + ProvisioningConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + future> + CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr CreateApiHubInstance( + NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + future> + CreateApiHubInstance( + google::longrunning::Operation const& operation) override; + + StatusOr GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) + override; + + StatusOr + LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) + override; + + private: + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_CONNECTION_IMPL_H diff --git a/google/cloud/apihub/v1/internal/provisioning_logging_decorator.cc b/google/cloud/apihub/v1/internal/provisioning_logging_decorator.cc new file mode 100644 index 0000000000000..56826321e01d2 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_logging_decorator.cc @@ -0,0 +1,134 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProvisioningLogging::ProvisioningLogging( + std::shared_ptr child, TracingOptions tracing_options, + std::set const&) + : child_(std::move(child)), tracing_options_(std::move(tracing_options)) {} + +future> +ProvisioningLogging::AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& + request) { + return child_->AsyncCreateApiHubInstance(cq, std::move(context), + std::move(options), request); + }, + cq, std::move(context), std::move(options), request, __func__, + tracing_options_); +} + +StatusOr +ProvisioningLogging::CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& + request) { + return child_->CreateApiHubInstance(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ProvisioningLogging::GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + return child_->GetApiHubInstance(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +ProvisioningLogging::LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& + request) { + return child_->LookupApiHubInstance(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +future> +ProvisioningLogging::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) { + return child_->AsyncGetOperation(cq, std::move(context), + std::move(options), request); + }, + cq, std::move(context), std::move(options), request, __func__, + tracing_options_); +} + +future ProvisioningLogging::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) { + return child_->AsyncCancelOperation(cq, std::move(context), + std::move(options), request); + }, + cq, std::move(context), std::move(options), request, __func__, + tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_logging_decorator.h b/google/cloud/apihub/v1/internal/provisioning_logging_decorator.h new file mode 100644 index 0000000000000..3244cc1b1b9f1 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_logging_decorator.h @@ -0,0 +1,87 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_LOGGING_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProvisioningLogging : public ProvisioningStub { + public: + ~ProvisioningLogging() override = default; + ProvisioningLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set const& components); + + future> AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) + override; + + StatusOr + LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) + override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; +}; // ProvisioningLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_LOGGING_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/provisioning_metadata_decorator.cc b/google/cloud/apihub/v1/internal/provisioning_metadata_decorator.cc new file mode 100644 index 0000000000000..aa9967c73af8e --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_metadata_decorator.cc @@ -0,0 +1,125 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_metadata_decorator.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/url_encode.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProvisioningMetadata::ProvisioningMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +future> +ProvisioningMetadata::AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + SetMetadata(*context, *options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->AsyncCreateApiHubInstance(cq, std::move(context), + std::move(options), request); +} + +StatusOr +ProvisioningMetadata::CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateApiHubInstance(context, options, request); +} + +StatusOr +ProvisioningMetadata::GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetApiHubInstance(context, options, request); +} + +StatusOr +ProvisioningMetadata::LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->LookupApiHubInstance(context, options, request); +} + +future> +ProvisioningMetadata::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) { + SetMetadata(*context, *options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->AsyncGetOperation(cq, std::move(context), std::move(options), + request); +} + +future ProvisioningMetadata::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) { + SetMetadata(*context, *options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->AsyncCancelOperation(cq, std::move(context), + std::move(options), request); +} + +void ProvisioningMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context, options); +} + +void ProvisioningMetadata::SetMetadata(grpc::ClientContext& context, + Options const& options) { + google::cloud::internal::SetMetadata(context, options, fixed_metadata_, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_metadata_decorator.h b/google/cloud/apihub/v1/internal/provisioning_metadata_decorator.h new file mode 100644 index 0000000000000..c1a1654f9c1e2 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_metadata_decorator.h @@ -0,0 +1,92 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_METADATA_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProvisioningMetadata : public ProvisioningStub { + public: + ~ProvisioningMetadata() override = default; + ProvisioningMetadata(std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header = ""); + + future> AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) + override; + + StatusOr + LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) + override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) override; + + private: + void SetMetadata(grpc::ClientContext& context, Options const& options, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context, Options const& options); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_METADATA_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/provisioning_option_defaults.cc b/google/cloud/apihub/v1/internal/provisioning_option_defaults.cc new file mode 100644 index 0000000000000..cdc654bdd1894 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_option_defaults.cc @@ -0,0 +1,75 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_option_defaults.h" +#include "google/cloud/apihub/v1/provisioning_connection.h" +#include "google/cloud/apihub/v1/provisioning_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options ProvisioningDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_PROVISIONING_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_PROVISIONING_AUTHORITY", "apihub.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + apihub_v1::ProvisioningLimitedTimeRetryPolicy(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( + options.get()->clone(), + ExponentialBackoffPolicy(std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling) + .clone()) + .clone()); + } + if (!options + .has()) { + options.set( + apihub_v1::MakeDefaultProvisioningConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_option_defaults.h b/google/cloud/apihub/v1/internal/provisioning_option_defaults.h new file mode 100644 index 0000000000000..56bdfa6fe544d --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options ProvisioningDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_OPTION_DEFAULTS_H diff --git a/google/cloud/apihub/v1/internal/provisioning_retry_traits.h b/google/cloud/apihub/v1/internal/provisioning_retry_traits.h new file mode 100644 index 0000000000000..af0ca8515968c --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct ProvisioningRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_RETRY_TRAITS_H diff --git a/google/cloud/apihub/v1/internal/provisioning_sources.cc b/google/cloud/apihub/v1/internal/provisioning_sources.cc new file mode 100644 index 0000000000000..8b18639aee22e --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_sources.cc @@ -0,0 +1,32 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/apihub/v1/internal/provisioning_auth_decorator.cc" +#include "google/cloud/apihub/v1/internal/provisioning_connection_impl.cc" +#include "google/cloud/apihub/v1/internal/provisioning_logging_decorator.cc" +#include "google/cloud/apihub/v1/internal/provisioning_metadata_decorator.cc" +#include "google/cloud/apihub/v1/internal/provisioning_option_defaults.cc" +#include "google/cloud/apihub/v1/internal/provisioning_stub.cc" +#include "google/cloud/apihub/v1/internal/provisioning_stub_factory.cc" +#include "google/cloud/apihub/v1/internal/provisioning_tracing_connection.cc" +#include "google/cloud/apihub/v1/internal/provisioning_tracing_stub.cc" +#include "google/cloud/apihub/v1/provisioning_client.cc" +#include "google/cloud/apihub/v1/provisioning_connection.cc" +#include "google/cloud/apihub/v1/provisioning_connection_idempotency_policy.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/apihub/v1/internal/provisioning_stub.cc b/google/cloud/apihub/v1/internal/provisioning_stub.cc new file mode 100644 index 0000000000000..5e21de3faf0dd --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_stub.cc @@ -0,0 +1,130 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProvisioningStub::~ProvisioningStub() = default; + +future> +DefaultProvisioningStub::AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + return internal::MakeUnaryRpcImpl< + google::cloud::apihub::v1::CreateApiHubInstanceRequest, + google::longrunning::Operation>( + cq, + [this]( + grpc::ClientContext* context, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request, + grpc::CompletionQueue* cq) { + return grpc_stub_->AsyncCreateApiHubInstance(context, request, cq); + }, + request, std::move(context)); +} + +StatusOr +DefaultProvisioningStub::CreateApiHubInstance( + grpc::ClientContext& context, Options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + google::longrunning::Operation response; + auto status = grpc_stub_->CreateApiHubInstance(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultProvisioningStub::GetApiHubInstance( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + google::cloud::apihub::v1::ApiHubInstance response; + auto status = grpc_stub_->GetApiHubInstance(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultProvisioningStub::LookupApiHubInstance( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) { + google::cloud::apihub::v1::LookupApiHubInstanceResponse response; + auto status = grpc_stub_->LookupApiHubInstance(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +future> +DefaultProvisioningStub::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + // NOLINTNEXTLINE(performance-unnecessary-value-param) + google::cloud::internal::ImmutableOptions, + 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 DefaultProvisioningStub::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + // NOLINTNEXTLINE(performance-unnecessary-value-param) + google::cloud::internal::ImmutableOptions, + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_stub.h b/google/cloud/apihub/v1/internal/provisioning_stub.h new file mode 100644 index 0000000000000..d4d94fddde847 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_stub.h @@ -0,0 +1,132 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/future.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProvisioningStub { + public: + virtual ~ProvisioningStub() = 0; + + virtual future> + AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& + request) = 0; + + virtual StatusOr CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& + request) = 0; + + virtual StatusOr GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) = 0; + + virtual StatusOr + LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& + request) = 0; + + virtual future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) = 0; + + virtual future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) = 0; +}; + +class DefaultProvisioningStub : public ProvisioningStub { + public: + DefaultProvisioningStub( + std::unique_ptr + grpc_stub, + std::unique_ptr + operations) + : grpc_stub_(std::move(grpc_stub)), operations_(std::move(operations)) {} + + future> AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) + override; + + StatusOr + LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) + override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) override; + + private: + std::unique_ptr + grpc_stub_; + std::unique_ptr operations_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_STUB_H diff --git a/google/cloud/apihub/v1/internal/provisioning_stub_factory.cc b/google/cloud/apihub/v1/internal/provisioning_stub_factory.cc new file mode 100644 index 0000000000000..8a50004404d70 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_stub_factory.cc @@ -0,0 +1,72 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_stub_factory.h" +#include "google/cloud/apihub/v1/internal/provisioning_auth_decorator.h" +#include "google/cloud/apihub/v1/internal/provisioning_logging_decorator.h" +#include "google/cloud/apihub/v1/internal/provisioning_metadata_decorator.h" +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/apihub/v1/internal/provisioning_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultProvisioningStub( + std::shared_ptr auth, + Options const& options) { + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = + google::cloud::apihub::v1::Provisioning::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 = MakeProvisioningTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_stub_factory.h b/google/cloud/apihub/v1/internal/provisioning_stub_factory.h new file mode 100644 index 0000000000000..28aa5bb43f84c --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_STUB_FACTORY_H + +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultProvisioningStub( + std::shared_ptr auth, + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_STUB_FACTORY_H diff --git a/google/cloud/apihub/v1/internal/provisioning_tracing_connection.cc b/google/cloud/apihub/v1/internal/provisioning_tracing_connection.cc new file mode 100644 index 0000000000000..8969e28fbdf62 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_tracing_connection.cc @@ -0,0 +1,100 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ProvisioningTracingConnection::ProvisioningTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +future> +ProvisioningTracingConnection::CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ProvisioningConnection::CreateApiHubInstance"); + internal::OTelScope scope(span); + return internal::EndSpan(std::move(span), + child_->CreateApiHubInstance(request)); +} + +StatusOr +ProvisioningTracingConnection::CreateApiHubInstance( + NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ProvisioningConnection::CreateApiHubInstance"); + opentelemetry::trace::Scope scope(span); + return internal::EndSpan(*span, + child_->CreateApiHubInstance(NoAwaitTag{}, request)); +} + +future> +ProvisioningTracingConnection::CreateApiHubInstance( + google::longrunning::Operation const& operation) { + auto span = internal::MakeSpan( + "apihub_v1::ProvisioningConnection::CreateApiHubInstance"); + internal::OTelScope scope(span); + return internal::EndSpan(std::move(span), + child_->CreateApiHubInstance(operation)); +} + +StatusOr +ProvisioningTracingConnection::GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ProvisioningConnection::GetApiHubInstance"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetApiHubInstance(request)); +} + +StatusOr +ProvisioningTracingConnection::LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) { + auto span = internal::MakeSpan( + "apihub_v1::ProvisioningConnection::LookupApiHubInstance"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->LookupApiHubInstance(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeProvisioningTracingConnection( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_tracing_connection.h b/google/cloud/apihub/v1/internal/provisioning_tracing_connection.h new file mode 100644 index 0000000000000..7e8cc3e642204 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_tracing_connection.h @@ -0,0 +1,86 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_TRACING_CONNECTION_H + +#include "google/cloud/apihub/v1/provisioning_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ProvisioningTracingConnection : public apihub_v1::ProvisioningConnection { + public: + ~ProvisioningTracingConnection() override = default; + + explicit ProvisioningTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + future> + CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr CreateApiHubInstance( + NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + future> + CreateApiHubInstance( + google::longrunning::Operation const& operation) override; + + StatusOr GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) + override; + + StatusOr + LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest 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 +MakeProvisioningTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_TRACING_CONNECTION_H diff --git a/google/cloud/apihub/v1/internal/provisioning_tracing_stub.cc b/google/cloud/apihub/v1/internal/provisioning_tracing_stub.cc new file mode 100644 index 0000000000000..21bf53f2fa885 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_tracing_stub.cc @@ -0,0 +1,128 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/internal/provisioning_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ProvisioningTracingStub::ProvisioningTracingStub( + std::shared_ptr child) + : child_(std::move(child)), propagator_(internal::MakePropagator()) {} + +future> +ProvisioningTracingStub::AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.Provisioning", + "CreateApiHubInstance"); + internal::OTelScope scope(span); + internal::InjectTraceContext(*context, *propagator_); + auto f = child_->AsyncCreateApiHubInstance(cq, context, std::move(options), + request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +StatusOr +ProvisioningTracingStub::CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.Provisioning", + "CreateApiHubInstance"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->CreateApiHubInstance(context, options, request)); +} + +StatusOr +ProvisioningTracingStub::GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.Provisioning", + "GetApiHubInstance"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->GetApiHubInstance(context, options, request)); +} + +StatusOr +ProvisioningTracingStub::LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) { + auto span = internal::MakeSpanGrpc("google.cloud.apihub.v1.Provisioning", + "LookupApiHubInstance"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, child_->LookupApiHubInstance(context, options, request)); +} + +future> +ProvisioningTracingStub::AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) { + auto span = + internal::MakeSpanGrpc("google.longrunning.Operations", "GetOperation"); + internal::OTelScope scope(span); + internal::InjectTraceContext(*context, *propagator_); + auto f = child_->AsyncGetOperation(cq, context, std::move(options), request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +future ProvisioningTracingStub::AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) { + auto span = internal::MakeSpanGrpc("google.longrunning.Operations", + "CancelOperation"); + internal::OTelScope scope(span); + internal::InjectTraceContext(*context, *propagator_); + auto f = + child_->AsyncCancelOperation(cq, context, std::move(options), request); + return internal::EndSpan(std::move(context), std::move(span), std::move(f)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr MakeProvisioningTracingStub( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/provisioning_tracing_stub.h b/google/cloud/apihub/v1/internal/provisioning_tracing_stub.h new file mode 100644 index 0000000000000..0c058596c80d2 --- /dev/null +++ b/google/cloud/apihub/v1/internal/provisioning_tracing_stub.h @@ -0,0 +1,98 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_TRACING_STUB_H + +#include "google/cloud/apihub/v1/internal/provisioning_stub.h" +#include "google/cloud/internal/trace_propagator.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ProvisioningTracingStub : public ProvisioningStub { + public: + ~ProvisioningTracingStub() override = default; + + explicit ProvisioningTracingStub(std::shared_ptr child); + + future> AsyncCreateApiHubInstance( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr CreateApiHubInstance( + grpc::ClientContext& context, Options options, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request) + override; + + StatusOr GetApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request) + override; + + StatusOr + LookupApiHubInstance( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request) + override; + + future> AsyncGetOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::GetOperationRequest const& request) override; + + future AsyncCancelOperation( + google::cloud::CompletionQueue& cq, + std::shared_ptr context, + google::cloud::internal::ImmutableOptions options, + google::longrunning::CancelOperationRequest const& request) override; + + private: + std::shared_ptr child_; + std::shared_ptr + propagator_; +}; + +#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 MakeProvisioningTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_PROVISIONING_TRACING_STUB_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.cc new file mode 100644 index 0000000000000..0b039c660c841 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.cc @@ -0,0 +1,86 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RuntimeProjectAttachmentServiceAuth::RuntimeProjectAttachmentServiceAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +RuntimeProjectAttachmentServiceAuth::CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateRuntimeProjectAttachment(context, options, request); +} + +StatusOr +RuntimeProjectAttachmentServiceAuth::GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetRuntimeProjectAttachment(context, options, request); +} + +StatusOr +RuntimeProjectAttachmentServiceAuth::ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListRuntimeProjectAttachments(context, options, request); +} + +Status RuntimeProjectAttachmentServiceAuth::DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteRuntimeProjectAttachment(context, options, request); +} + +StatusOr +RuntimeProjectAttachmentServiceAuth::LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->LookupRuntimeProjectAttachment(context, options, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.h new file mode 100644 index 0000000000000..b6ff56a35e72e --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.h @@ -0,0 +1,81 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_AUTH_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RuntimeProjectAttachmentServiceAuth + : public RuntimeProjectAttachmentServiceStub { + public: + ~RuntimeProjectAttachmentServiceAuth() override = default; + RuntimeProjectAttachmentServiceAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr + CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) override; + + Status DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_AUTH_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.cc new file mode 100644 index 0000000000000..9e3b72a427887 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.cc @@ -0,0 +1,178 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/retry_loop.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_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< + apihub_v1::RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy> +idempotency_policy(Options const& options) { + return options + .get< + apihub_v1:: + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicyOption>() + ->clone(); +} + +} // namespace + +RuntimeProjectAttachmentServiceConnectionImpl:: + RuntimeProjectAttachmentServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions( + std::move(options), + RuntimeProjectAttachmentServiceConnection::options())) {} + +StatusOr +RuntimeProjectAttachmentServiceConnectionImpl::CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CreateRuntimeProjectAttachment(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + CreateRuntimeProjectAttachmentRequest const& request) { + return stub_->CreateRuntimeProjectAttachment(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +RuntimeProjectAttachmentServiceConnectionImpl::GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetRuntimeProjectAttachment(request), + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + return stub_->GetRuntimeProjectAttachment(context, options, request); + }, + *current, request, __func__); +} + +StreamRange +RuntimeProjectAttachmentServiceConnectionImpl::ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = + idempotency_policy(*current)->ListRuntimeProjectAttachments(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr< + apihub_v1::RuntimeProjectAttachmentServiceRetryPolicy>( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + ListRuntimeProjectAttachmentsRequest const& request) { + return stub->ListRuntimeProjectAttachments(context, options, + request); + }, + options, r, function_name); + }, + [](google::cloud::apihub::v1::ListRuntimeProjectAttachmentsResponse r) { + std::vector result( + r.runtime_project_attachments().size()); + auto& messages = *r.mutable_runtime_project_attachments(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +Status +RuntimeProjectAttachmentServiceConnectionImpl::DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteRuntimeProjectAttachment(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + DeleteRuntimeProjectAttachmentRequest const& request) { + return stub_->DeleteRuntimeProjectAttachment(context, options, request); + }, + *current, request, __func__); +} + +StatusOr +RuntimeProjectAttachmentServiceConnectionImpl::LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::internal::RetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->LookupRuntimeProjectAttachment(request), + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + LookupRuntimeProjectAttachmentRequest const& request) { + return stub_->LookupRuntimeProjectAttachment(context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.h new file mode 100644 index 0000000000000..6ca04e8f83273 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.h @@ -0,0 +1,89 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_IMPL_H + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_retry_traits.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_options.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RuntimeProjectAttachmentServiceConnectionImpl + : public apihub_v1::RuntimeProjectAttachmentServiceConnection { + public: + ~RuntimeProjectAttachmentServiceConnectionImpl() override = default; + + RuntimeProjectAttachmentServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options); + + Options options() override { return options_; } + + StatusOr + CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) override; + + StreamRange + ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request) + override; + + Status DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) override; + + private: + std::unique_ptr background_; + std::shared_ptr + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_IMPL_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.cc new file mode 100644 index 0000000000000..8da6a1ef3ea0e --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.cc @@ -0,0 +1,115 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RuntimeProjectAttachmentServiceLogging::RuntimeProjectAttachmentServiceLogging( + std::shared_ptr child, + TracingOptions tracing_options, std::set const&) + : child_(std::move(child)), tracing_options_(std::move(tracing_options)) {} + +StatusOr +RuntimeProjectAttachmentServiceLogging::CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + CreateRuntimeProjectAttachmentRequest const& request) { + return child_->CreateRuntimeProjectAttachment(context, options, + request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +RuntimeProjectAttachmentServiceLogging::GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + return child_->GetRuntimeProjectAttachment(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +RuntimeProjectAttachmentServiceLogging::ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this]( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) { + return child_->ListRuntimeProjectAttachments(context, options, request); + }, + context, options, request, __func__, tracing_options_); +} + +Status RuntimeProjectAttachmentServiceLogging::DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + DeleteRuntimeProjectAttachmentRequest const& request) { + return child_->DeleteRuntimeProjectAttachment(context, options, + request); + }, + context, options, request, __func__, tracing_options_); +} + +StatusOr +RuntimeProjectAttachmentServiceLogging::LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1:: + LookupRuntimeProjectAttachmentRequest const& request) { + return child_->LookupRuntimeProjectAttachment(context, options, + request); + }, + context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.h new file mode 100644 index 0000000000000..0a37d0b6d77f2 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.h @@ -0,0 +1,81 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_LOGGING_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RuntimeProjectAttachmentServiceLogging + : public RuntimeProjectAttachmentServiceStub { + public: + ~RuntimeProjectAttachmentServiceLogging() override = default; + RuntimeProjectAttachmentServiceLogging( + std::shared_ptr child, + TracingOptions tracing_options, std::set const& components); + + StatusOr + CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) override; + + Status DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; +}; // RuntimeProjectAttachmentServiceLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_LOGGING_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.cc new file mode 100644 index 0000000000000..eae55d558d4a8 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.cc @@ -0,0 +1,113 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/url_encode.h" +#include "google/cloud/status_or.h" +#include +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RuntimeProjectAttachmentServiceMetadata:: + RuntimeProjectAttachmentServiceMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header) + : child_(std::move(child)), + fixed_metadata_(std::move(fixed_metadata)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +RuntimeProjectAttachmentServiceMetadata::CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->CreateRuntimeProjectAttachment(context, options, request); +} + +StatusOr +RuntimeProjectAttachmentServiceMetadata::GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->GetRuntimeProjectAttachment(context, options, request); +} + +StatusOr +RuntimeProjectAttachmentServiceMetadata::ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("parent=", internal::UrlEncode(request.parent()))); + return child_->ListRuntimeProjectAttachments(context, options, request); +} + +Status RuntimeProjectAttachmentServiceMetadata::DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->DeleteRuntimeProjectAttachment(context, options, request); +} + +StatusOr +RuntimeProjectAttachmentServiceMetadata::LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) { + SetMetadata(context, options, + absl::StrCat("name=", internal::UrlEncode(request.name()))); + return child_->LookupRuntimeProjectAttachment(context, options, request); +} + +void RuntimeProjectAttachmentServiceMetadata::SetMetadata( + grpc::ClientContext& context, Options const& options, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context, options); +} + +void RuntimeProjectAttachmentServiceMetadata::SetMetadata( + grpc::ClientContext& context, Options const& options) { + google::cloud::internal::SetMetadata(context, options, fixed_metadata_, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.h new file mode 100644 index 0000000000000..0ccb56120720b --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.h @@ -0,0 +1,87 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_METADATA_DECORATOR_H + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RuntimeProjectAttachmentServiceMetadata + : public RuntimeProjectAttachmentServiceStub { + public: + ~RuntimeProjectAttachmentServiceMetadata() override = default; + RuntimeProjectAttachmentServiceMetadata( + std::shared_ptr child, + std::multimap fixed_metadata, + std::string api_client_header = ""); + + StatusOr + CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) override; + + Status DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) override; + + private: + void SetMetadata(grpc::ClientContext& context, Options const& options, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context, Options const& options); + + std::shared_ptr child_; + std::multimap fixed_metadata_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_METADATA_DECORATOR_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.cc new file mode 100644 index 0000000000000..7f2c7f9f4a33a --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.cc @@ -0,0 +1,74 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options RuntimeProjectAttachmentServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), + "GOOGLE_CLOUD_CPP_RUNTIME_PROJECT_ATTACHMENT_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_RUNTIME_PROJECT_ATTACHMENT_SERVICE_AUTHORITY", + "apihub.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has< + apihub_v1::RuntimeProjectAttachmentServiceRetryPolicyOption>()) { + options.set( + apihub_v1::RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has< + apihub_v1::RuntimeProjectAttachmentServiceBackoffPolicyOption>()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has< + apihub_v1:: + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicyOption>()) { + options.set< + apihub_v1:: + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicyOption>( + apihub_v1:: + MakeDefaultRuntimeProjectAttachmentServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.h new file mode 100644 index 0000000000000..95a4fcacc38de --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options RuntimeProjectAttachmentServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_OPTION_DEFAULTS_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_retry_traits.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_retry_traits.h new file mode 100644 index 0000000000000..33b2b714f7b9f --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct RuntimeProjectAttachmentServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_RETRY_TRAITS_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_sources.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_sources.cc new file mode 100644 index 0000000000000..c612262aae2b2 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_sources.cc @@ -0,0 +1,32 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.cc" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.cc" +#include "google/cloud/apihub/v1/runtime_project_attachment_client.cc" +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.cc" +#include "google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_stub.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub.cc new file mode 100644 index 0000000000000..7405a17c21d6d --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub.cc @@ -0,0 +1,107 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RuntimeProjectAttachmentServiceStub::~RuntimeProjectAttachmentServiceStub() = + default; + +StatusOr +DefaultRuntimeProjectAttachmentServiceStub::CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) { + google::cloud::apihub::v1::RuntimeProjectAttachment response; + auto status = + grpc_stub_->CreateRuntimeProjectAttachment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultRuntimeProjectAttachmentServiceStub::GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + google::cloud::apihub::v1::RuntimeProjectAttachment response; + auto status = + grpc_stub_->GetRuntimeProjectAttachment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultRuntimeProjectAttachmentServiceStub::ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) { + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsResponse response; + auto status = + grpc_stub_->ListRuntimeProjectAttachments(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status +DefaultRuntimeProjectAttachmentServiceStub::DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) { + google::protobuf::Empty response; + auto status = + grpc_stub_->DeleteRuntimeProjectAttachment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr +DefaultRuntimeProjectAttachmentServiceStub::LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const&, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) { + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentResponse response; + auto status = + grpc_stub_->LookupRuntimeProjectAttachment(&context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h new file mode 100644 index 0000000000000..12afd4c81dccf --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h @@ -0,0 +1,119 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_STUB_H + +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RuntimeProjectAttachmentServiceStub { + public: + virtual ~RuntimeProjectAttachmentServiceStub() = 0; + + virtual StatusOr + CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) = 0; + + virtual StatusOr + GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) = 0; + + virtual StatusOr< + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsResponse> + ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) = 0; + + virtual Status DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) = 0; + + virtual StatusOr< + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentResponse> + LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) = 0; +}; + +class DefaultRuntimeProjectAttachmentServiceStub + : public RuntimeProjectAttachmentServiceStub { + public: + explicit DefaultRuntimeProjectAttachmentServiceStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr + CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) override; + + Status DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) override; + + private: + std::unique_ptr< + google::cloud::apihub::v1::RuntimeProjectAttachmentService::StubInterface> + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_STUB_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.cc new file mode 100644 index 0000000000000..b129d18b22679 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.cc @@ -0,0 +1,74 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_auth_decorator.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_logging_decorator.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_metadata_decorator.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr +CreateDefaultRuntimeProjectAttachmentServiceStub( + std::shared_ptr auth, + Options const& options) { + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = + google::cloud::apihub::v1::RuntimeProjectAttachmentService::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 = MakeRuntimeProjectAttachmentServiceTracingStub(std::move(stub)); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.h new file mode 100644 index 0000000000000..57b8c74c45bef --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_STUB_FACTORY_H + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr +CreateDefaultRuntimeProjectAttachmentServiceStub( + std::shared_ptr auth, + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_STUB_FACTORY_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.cc new file mode 100644 index 0000000000000..474bb1c6c5dbb --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.cc @@ -0,0 +1,118 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +RuntimeProjectAttachmentServiceTracingConnection:: + RuntimeProjectAttachmentServiceTracingConnection( + std::shared_ptr + child) + : child_(std::move(child)) {} + +StatusOr +RuntimeProjectAttachmentServiceTracingConnection:: + CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpan( + "apihub_v1::RuntimeProjectAttachmentServiceConnection::" + "CreateRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, + child_->CreateRuntimeProjectAttachment(request)); +} + +StatusOr +RuntimeProjectAttachmentServiceTracingConnection::GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpan( + "apihub_v1::RuntimeProjectAttachmentServiceConnection::" + "GetRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetRuntimeProjectAttachment(request)); +} + +StreamRange +RuntimeProjectAttachmentServiceTracingConnection::ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request) { + auto span = internal::MakeSpan( + "apihub_v1::RuntimeProjectAttachmentServiceConnection::" + "ListRuntimeProjectAttachments"); + internal::OTelScope scope(span); + auto sr = child_->ListRuntimeProjectAttachments(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::apihub::v1::RuntimeProjectAttachment>(std::move(span), + std::move(sr)); +} + +Status RuntimeProjectAttachmentServiceTracingConnection:: + DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpan( + "apihub_v1::RuntimeProjectAttachmentServiceConnection::" + "DeleteRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, + child_->DeleteRuntimeProjectAttachment(request)); +} + +StatusOr +RuntimeProjectAttachmentServiceTracingConnection:: + LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpan( + "apihub_v1::RuntimeProjectAttachmentServiceConnection::" + "LookupRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, + child_->LookupRuntimeProjectAttachment(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeRuntimeProjectAttachmentServiceTracingConnection( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.h new file mode 100644 index 0000000000000..d9d4b74e4df1c --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.h @@ -0,0 +1,89 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_TRACING_CONNECTION_H + +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class RuntimeProjectAttachmentServiceTracingConnection + : public apihub_v1::RuntimeProjectAttachmentServiceConnection { + public: + ~RuntimeProjectAttachmentServiceTracingConnection() override = default; + + explicit RuntimeProjectAttachmentServiceTracingConnection( + std::shared_ptr + child); + + Options options() override { return child_->options(); } + + StatusOr + CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) override; + + StreamRange + ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request) + override; + + Status DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest 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 +MakeRuntimeProjectAttachmentServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_TRACING_CONNECTION_H diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.cc b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.cc new file mode 100644 index 0000000000000..d52e242007fbc --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.cc @@ -0,0 +1,127 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.h" +#include "google/cloud/internal/grpc_opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +RuntimeProjectAttachmentServiceTracingStub:: + RuntimeProjectAttachmentServiceTracingStub( + std::shared_ptr child) + : child_(std::move(child)), propagator_(internal::MakePropagator()) {} + +StatusOr +RuntimeProjectAttachmentServiceTracingStub::CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.RuntimeProjectAttachmentService", + "CreateRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->CreateRuntimeProjectAttachment(context, options, request)); +} + +StatusOr +RuntimeProjectAttachmentServiceTracingStub::GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.RuntimeProjectAttachmentService", + "GetRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->GetRuntimeProjectAttachment(context, options, request)); +} + +StatusOr +RuntimeProjectAttachmentServiceTracingStub::ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.RuntimeProjectAttachmentService", + "ListRuntimeProjectAttachments"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->ListRuntimeProjectAttachments(context, options, request)); +} + +Status +RuntimeProjectAttachmentServiceTracingStub::DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.RuntimeProjectAttachmentService", + "DeleteRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->DeleteRuntimeProjectAttachment(context, options, request)); +} + +StatusOr +RuntimeProjectAttachmentServiceTracingStub::LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) { + auto span = internal::MakeSpanGrpc( + "google.cloud.apihub.v1.RuntimeProjectAttachmentService", + "LookupRuntimeProjectAttachment"); + auto scope = opentelemetry::trace::Scope(span); + internal::InjectTraceContext(context, *propagator_); + return internal::EndSpan( + context, *span, + child_->LookupRuntimeProjectAttachment(context, options, request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeRuntimeProjectAttachmentServiceTracingStub( + 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 apihub_v1_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.h b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.h new file mode 100644 index 0000000000000..2d2ae4cd6e0b2 --- /dev/null +++ b/google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_stub.h @@ -0,0 +1,95 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_TRACING_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_TRACING_STUB_H + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub.h" +#include "google/cloud/internal/trace_propagator.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class RuntimeProjectAttachmentServiceTracingStub + : public RuntimeProjectAttachmentServiceStub { + public: + ~RuntimeProjectAttachmentServiceTracingStub() override = default; + + explicit RuntimeProjectAttachmentServiceTracingStub( + std::shared_ptr child); + + StatusOr + CreateRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + GetRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + ListRuntimeProjectAttachments( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest const& + request) override; + + Status DeleteRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request) override; + + StatusOr + LookupRuntimeProjectAttachment( + grpc::ClientContext& context, Options const& options, + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request) override; + + private: + std::shared_ptr child_; + std::shared_ptr + propagator_; +}; + +#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 +MakeRuntimeProjectAttachmentServiceTracingStub( + std::shared_ptr stub); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_INTERNAL_RUNTIME_PROJECT_ATTACHMENT_TRACING_STUB_H diff --git a/google/cloud/apihub/v1/linting_client.cc b/google/cloud/apihub/v1/linting_client.cc new file mode 100644 index 0000000000000..01a5258a5aea8 --- /dev/null +++ b/google/cloud/apihub/v1/linting_client.cc @@ -0,0 +1,96 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/linting_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +LintingServiceClient::LintingServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +LintingServiceClient::~LintingServiceClient() = default; + +StatusOr +LintingServiceClient::GetStyleGuide(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetStyleGuideRequest request; + request.set_name(name); + return connection_->GetStyleGuide(request); +} + +StatusOr +LintingServiceClient::GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetStyleGuide(request); +} + +StatusOr +LintingServiceClient::UpdateStyleGuide( + google::cloud::apihub::v1::StyleGuide const& style_guide, + google::protobuf::FieldMask const& update_mask, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::UpdateStyleGuideRequest request; + *request.mutable_style_guide() = style_guide; + *request.mutable_update_mask() = update_mask; + return connection_->UpdateStyleGuide(request); +} + +StatusOr +LintingServiceClient::UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateStyleGuide(request); +} + +StatusOr +LintingServiceClient::GetStyleGuideContents(std::string const& name, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetStyleGuideContentsRequest request; + request.set_name(name); + return connection_->GetStyleGuideContents(request); +} + +StatusOr +LintingServiceClient::GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetStyleGuideContents(request); +} + +Status LintingServiceClient::LintSpec( + google::cloud::apihub::v1::LintSpecRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->LintSpec(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/linting_client.h b/google/cloud/apihub/v1/linting_client.h new file mode 100644 index 0000000000000..d6cd580f0817c --- /dev/null +++ b/google/cloud/apihub/v1/linting_client.h @@ -0,0 +1,302 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CLIENT_H + +#include "google/cloud/apihub/v1/linting_connection.h" +#include "google/cloud/future.h" +#include "google/cloud/options.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This service provides all methods related to the 1p Linter. +/// +/// @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 LintingServiceClient { + public: + explicit LintingServiceClient( + std::shared_ptr connection, Options opts = {}); + ~LintingServiceClient(); + + ///@{ + /// @name Copy and move support + LintingServiceClient(LintingServiceClient const&) = default; + LintingServiceClient& operator=(LintingServiceClient const&) = default; + LintingServiceClient(LintingServiceClient&&) = default; + LintingServiceClient& operator=(LintingServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(LintingServiceClient const& a, + LintingServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(LintingServiceClient const& a, + LintingServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Get the style guide being used for linting. + /// + /// @param name Required. The name of the spec to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/plugins/{plugin}/styleGuide`. + /// @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.apihub.v1.StyleGuide]) + /// 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 + /// [`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.apihub.v1.GetStyleGuideRequest]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L79} + /// [google.cloud.apihub.v1.StyleGuide]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L137} + /// + // clang-format on + StatusOr GetStyleGuide( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get the style guide being used for linting. + /// + /// @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.apihub.v1.GetStyleGuideRequest]. + /// 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.apihub.v1.StyleGuide]) + /// 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 + /// [`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.apihub.v1.GetStyleGuideRequest]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L79} + /// [google.cloud.apihub.v1.StyleGuide]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L137} + /// + // clang-format on + StatusOr GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Update the styleGuide to be used for liniting in by API hub. + /// + /// @param style_guide Required. The Style guide resource to update. + /// @param update_mask Optional. The list of fields to update. + /// @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.apihub.v1.StyleGuide]) + /// 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 + /// [`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.apihub.v1.StyleGuide]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L137} + /// [google.cloud.apihub.v1.UpdateStyleGuideRequest]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L92} + /// + // clang-format on + StatusOr UpdateStyleGuide( + google::cloud::apihub::v1::StyleGuide const& style_guide, + google::protobuf::FieldMask const& update_mask, Options opts = {}); + + // clang-format off + /// + /// Update the styleGuide to be used for liniting in by API hub. + /// + /// @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.apihub.v1.UpdateStyleGuideRequest]. + /// 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.apihub.v1.StyleGuide]) + /// 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 + /// [`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.apihub.v1.StyleGuide]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L137} + /// [google.cloud.apihub.v1.UpdateStyleGuideRequest]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L92} + /// + // clang-format on + StatusOr UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Get the contents of the style guide. + /// + /// @param name Required. The name of the StyleGuide whose contents need to be retrieved. + /// There is exactly one style guide resource per project per location. + /// The expected format is + /// `projects/{project}/locations/{location}/plugins/{plugin}/styleGuide`. + /// @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.apihub.v1.StyleGuideContents]) + /// 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 + /// [`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.apihub.v1.GetStyleGuideContentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L102} + /// [google.cloud.apihub.v1.StyleGuideContents]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L127} + /// + // clang-format on + StatusOr GetStyleGuideContents( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Get the contents of the style guide. + /// + /// @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.apihub.v1.GetStyleGuideContentsRequest]. + /// 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.apihub.v1.StyleGuideContents]) + /// 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 + /// [`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.apihub.v1.GetStyleGuideContentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L102} + /// [google.cloud.apihub.v1.StyleGuideContents]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L127} + /// + // clang-format on + StatusOr GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Lints the requested spec and updates the corresponding API Spec with the + /// lint response. This lint response will be available in all subsequent + /// Get and List Spec calls to Core service. + /// + /// @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.apihub.v1.LintSpecRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.LintSpecRequest]: @googleapis_reference_link{google/cloud/apihub/v1/linting_service.proto#L116} + /// + // clang-format on + Status LintSpec(google::cloud::apihub::v1::LintSpecRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CLIENT_H diff --git a/google/cloud/apihub/v1/linting_connection.cc b/google/cloud/apihub/v1/linting_connection.cc new file mode 100644 index 0000000000000..4d8910d98db8f --- /dev/null +++ b/google/cloud/apihub/v1/linting_connection.cc @@ -0,0 +1,83 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/linting_connection.h" +#include "google/cloud/apihub/v1/internal/linting_connection_impl.h" +#include "google/cloud/apihub/v1/internal/linting_option_defaults.h" +#include "google/cloud/apihub/v1/internal/linting_stub_factory.h" +#include "google/cloud/apihub/v1/internal/linting_tracing_connection.h" +#include "google/cloud/apihub/v1/linting_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/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +LintingServiceConnection::~LintingServiceConnection() = default; + +StatusOr +LintingServiceConnection::GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +LintingServiceConnection::UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +LintingServiceConnection::GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status LintingServiceConnection::LintSpec( + google::cloud::apihub::v1::LintSpecRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +std::shared_ptr MakeLintingServiceConnection( + Options options) { + internal::CheckExpectedOptions(options, + __func__); + options = + apihub_v1_internal::LintingServiceDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); + auto stub = apihub_v1_internal::CreateDefaultLintingServiceStub( + std::move(auth), options); + return apihub_v1_internal::MakeLintingServiceTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/linting_connection.h b/google/cloud/apihub/v1/linting_connection.h new file mode 100644 index 0000000000000..cf6c9b1d52bd9 --- /dev/null +++ b/google/cloud/apihub/v1/linting_connection.h @@ -0,0 +1,227 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CONNECTION_H + +#include "google/cloud/apihub/v1/internal/linting_retry_traits.h" +#include "google/cloud/apihub/v1/linting_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `LintingServiceConnection`. +class LintingServiceRetryPolicy : 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 `LintingServiceConnection` 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 LintingServiceLimitedErrorCountRetryPolicy + : public LintingServiceRetryPolicy { + 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 LintingServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + LintingServiceLimitedErrorCountRetryPolicy( + LintingServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : LintingServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + LintingServiceLimitedErrorCountRetryPolicy( + LintingServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : LintingServiceLimitedErrorCountRetryPolicy(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 = LintingServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apihub_v1_internal::LintingServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `LintingServiceConnection` 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 LintingServiceLimitedTimeRetryPolicy : public LintingServiceRetryPolicy { + 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 LintingServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + LintingServiceLimitedTimeRetryPolicy( + LintingServiceLimitedTimeRetryPolicy&& rhs) noexcept + : LintingServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + LintingServiceLimitedTimeRetryPolicy( + LintingServiceLimitedTimeRetryPolicy const& rhs) noexcept + : LintingServiceLimitedTimeRetryPolicy(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 = LintingServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apihub_v1_internal::LintingServiceRetryTraits> + impl_; +}; + +/** + * The `LintingServiceConnection` object for `LintingServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `LintingServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `LintingServiceClient`. + * + * To create a concrete instance, see `MakeLintingServiceConnection()`. + * + * For mocking, see `apihub_v1_mocks::MockLintingServiceConnection`. + */ +class LintingServiceConnection { + public: + virtual ~LintingServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request); + + virtual StatusOr UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request); + + virtual StatusOr + GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request); + + virtual Status LintSpec( + google::cloud::apihub::v1::LintSpecRequest const& request); +}; + +/** + * A factory function to construct an object of type `LintingServiceConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of LintingServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `LintingServiceConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::apihub_v1::LintingServicePolicyOptionList` + * + * @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 `LintingServiceConnection` created by + * this function. + */ +std::shared_ptr MakeLintingServiceConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CONNECTION_H diff --git a/google/cloud/apihub/v1/linting_connection_idempotency_policy.cc b/google/cloud/apihub/v1/linting_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..dfed2c582898c --- /dev/null +++ b/google/cloud/apihub/v1/linting_connection_idempotency_policy.cc @@ -0,0 +1,65 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/linting_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +LintingServiceConnectionIdempotencyPolicy:: + ~LintingServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +LintingServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency LintingServiceConnectionIdempotencyPolicy::GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency LintingServiceConnectionIdempotencyPolicy::UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency LintingServiceConnectionIdempotencyPolicy::GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency LintingServiceConnectionIdempotencyPolicy::LintSpec( + google::cloud::apihub::v1::LintSpecRequest const&) { + return Idempotency::kNonIdempotent; +} + +std::unique_ptr +MakeDefaultLintingServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/linting_connection_idempotency_policy.h b/google/cloud/apihub/v1/linting_connection_idempotency_policy.h new file mode 100644 index 0000000000000..3fe2b57ddac2e --- /dev/null +++ b/google/cloud/apihub/v1/linting_connection_idempotency_policy.h @@ -0,0 +1,61 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class LintingServiceConnectionIdempotencyPolicy { + public: + virtual ~LintingServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetStyleGuide( + google::cloud::apihub::v1::GetStyleGuideRequest const& request); + + virtual google::cloud::Idempotency UpdateStyleGuide( + google::cloud::apihub::v1::UpdateStyleGuideRequest const& request); + + virtual google::cloud::Idempotency GetStyleGuideContents( + google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request); + + virtual google::cloud::Idempotency LintSpec( + google::cloud::apihub::v1::LintSpecRequest const& request); +}; + +std::unique_ptr +MakeDefaultLintingServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/apihub/v1/linting_options.h b/google/cloud/apihub/v1/linting_options.h new file mode 100644 index 0000000000000..641387d5095fb --- /dev/null +++ b/google/cloud/apihub/v1/linting_options.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_OPTIONS_H + +#include "google/cloud/apihub/v1/linting_connection.h" +#include "google/cloud/apihub/v1/linting_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-apihub-options + */ +struct LintingServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-apihub-options + */ +struct LintingServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-apihub-options + */ +struct LintingServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to LintingService. + * + * @ingroup google-cloud-apihub-options + */ +using LintingServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_LINTING_OPTIONS_H diff --git a/google/cloud/apihub/v1/mocks/mock_api_hub_connection.h b/google/cloud/apihub/v1/mocks/mock_api_hub_connection.h new file mode 100644 index 0000000000000..16aa1111c9fe5 --- /dev/null +++ b/google/cloud/apihub/v1/mocks/mock_api_hub_connection.h @@ -0,0 +1,210 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_connection.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `ApiHubConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `ApiHubClient`. To do so, + * construct an object of type `ApiHubClient` 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 MockApiHubConnection : public apihub_v1::ApiHubConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, CreateApi, + (google::cloud::apihub::v1::CreateApiRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetApi, + (google::cloud::apihub::v1::GetApiRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), ListApis, + (google::cloud::apihub::v1::ListApisRequest request), (override)); + + MOCK_METHOD(StatusOr, UpdateApi, + (google::cloud::apihub::v1::UpdateApiRequest const& request), + (override)); + + MOCK_METHOD(Status, DeleteApi, + (google::cloud::apihub::v1::DeleteApiRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, CreateVersion, + (google::cloud::apihub::v1::CreateVersionRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetVersion, + (google::cloud::apihub::v1::GetVersionRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), ListVersions, + (google::cloud::apihub::v1::ListVersionsRequest request), + (override)); + + MOCK_METHOD(StatusOr, UpdateVersion, + (google::cloud::apihub::v1::UpdateVersionRequest const& request), + (override)); + + MOCK_METHOD(Status, DeleteVersion, + (google::cloud::apihub::v1::DeleteVersionRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, CreateSpec, + (google::cloud::apihub::v1::CreateSpecRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetSpec, + (google::cloud::apihub::v1::GetSpecRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, GetSpecContents, + (google::cloud::apihub::v1::GetSpecContentsRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), ListSpecs, + (google::cloud::apihub::v1::ListSpecsRequest request), + (override)); + + MOCK_METHOD(StatusOr, UpdateSpec, + (google::cloud::apihub::v1::UpdateSpecRequest const& request), + (override)); + + MOCK_METHOD(Status, DeleteSpec, + (google::cloud::apihub::v1::DeleteSpecRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, GetApiOperation, + (google::cloud::apihub::v1::GetApiOperationRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListApiOperations, + (google::cloud::apihub::v1::ListApiOperationsRequest request), + (override)); + + MOCK_METHOD(StatusOr, GetDefinition, + (google::cloud::apihub::v1::GetDefinitionRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, CreateDeployment, + (google::cloud::apihub::v1::CreateDeploymentRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetDeployment, + (google::cloud::apihub::v1::GetDeploymentRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListDeployments, + (google::cloud::apihub::v1::ListDeploymentsRequest request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateDeployment, + (google::cloud::apihub::v1::UpdateDeploymentRequest const& request), + (override)); + + MOCK_METHOD( + Status, DeleteDeployment, + (google::cloud::apihub::v1::DeleteDeploymentRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, CreateAttribute, + (google::cloud::apihub::v1::CreateAttributeRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetAttribute, + (google::cloud::apihub::v1::GetAttributeRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateAttribute, + (google::cloud::apihub::v1::UpdateAttributeRequest const& request), + (override)); + + MOCK_METHOD( + Status, DeleteAttribute, + (google::cloud::apihub::v1::DeleteAttributeRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListAttributes, + (google::cloud::apihub::v1::ListAttributesRequest request), + (override)); + + MOCK_METHOD((StreamRange), + SearchResources, + (google::cloud::apihub::v1::SearchResourcesRequest request), + (override)); + + MOCK_METHOD( + StatusOr, CreateExternalApi, + (google::cloud::apihub::v1::CreateExternalApiRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetExternalApi, + (google::cloud::apihub::v1::GetExternalApiRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateExternalApi, + (google::cloud::apihub::v1::UpdateExternalApiRequest const& request), + (override)); + + MOCK_METHOD( + Status, DeleteExternalApi, + (google::cloud::apihub::v1::DeleteExternalApiRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListExternalApis, + (google::cloud::apihub::v1::ListExternalApisRequest request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_CONNECTION_H diff --git a/google/cloud/apihub/v1/mocks/mock_api_hub_dependencies_connection.h b/google/cloud/apihub/v1/mocks/mock_api_hub_dependencies_connection.h new file mode 100644 index 0000000000000..1979de2e6aacf --- /dev/null +++ b/google/cloud/apihub/v1/mocks/mock_api_hub_dependencies_connection.h @@ -0,0 +1,80 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_DEPENDENCIES_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_DEPENDENCIES_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_dependencies_connection.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `ApiHubDependenciesConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `ApiHubDependenciesClient`. To do + * so, construct an object of type `ApiHubDependenciesClient` 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 MockApiHubDependenciesConnection + : public apihub_v1::ApiHubDependenciesConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + StatusOr, CreateDependency, + (google::cloud::apihub::v1::CreateDependencyRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetDependency, + (google::cloud::apihub::v1::GetDependencyRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateDependency, + (google::cloud::apihub::v1::UpdateDependencyRequest const& request), + (override)); + + MOCK_METHOD( + Status, DeleteDependency, + (google::cloud::apihub::v1::DeleteDependencyRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListDependencies, + (google::cloud::apihub::v1::ListDependenciesRequest request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_DEPENDENCIES_CONNECTION_H diff --git a/google/cloud/apihub/v1/mocks/mock_api_hub_plugin_connection.h b/google/cloud/apihub/v1/mocks/mock_api_hub_plugin_connection.h new file mode 100644 index 0000000000000..701f6df258b58 --- /dev/null +++ b/google/cloud/apihub/v1/mocks/mock_api_hub_plugin_connection.h @@ -0,0 +1,67 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_PLUGIN_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_PLUGIN_CONNECTION_H + +#include "google/cloud/apihub/v1/api_hub_plugin_connection.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `ApiHubPluginConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `ApiHubPluginClient`. To do so, + * construct an object of type `ApiHubPluginClient` 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 MockApiHubPluginConnection : public apihub_v1::ApiHubPluginConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, GetPlugin, + (google::cloud::apihub::v1::GetPluginRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, EnablePlugin, + (google::cloud::apihub::v1::EnablePluginRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, DisablePlugin, + (google::cloud::apihub::v1::DisablePluginRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_API_HUB_PLUGIN_CONNECTION_H diff --git a/google/cloud/apihub/v1/mocks/mock_host_project_registration_connection.h b/google/cloud/apihub/v1/mocks/mock_host_project_registration_connection.h new file mode 100644 index 0000000000000..ef95354f9098a --- /dev/null +++ b/google/cloud/apihub/v1/mocks/mock_host_project_registration_connection.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_HOST_PROJECT_REGISTRATION_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_HOST_PROJECT_REGISTRATION_CONNECTION_H + +#include "google/cloud/apihub/v1/host_project_registration_connection.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `HostProjectRegistrationServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type + * `HostProjectRegistrationServiceClient`. To do so, construct an object of type + * `HostProjectRegistrationServiceClient` 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 MockHostProjectRegistrationServiceConnection + : public apihub_v1::HostProjectRegistrationServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + StatusOr, + CreateHostProjectRegistration, + (google::cloud::apihub::v1::CreateHostProjectRegistrationRequest const& + request), + (override)); + + MOCK_METHOD( + StatusOr, + GetHostProjectRegistration, + (google::cloud::apihub::v1::GetHostProjectRegistrationRequest const& + request), + (override)); + + MOCK_METHOD( + (StreamRange), + ListHostProjectRegistrations, + (google::cloud::apihub::v1::ListHostProjectRegistrationsRequest request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_HOST_PROJECT_REGISTRATION_CONNECTION_H diff --git a/google/cloud/apihub/v1/mocks/mock_linting_connection.h b/google/cloud/apihub/v1/mocks/mock_linting_connection.h new file mode 100644 index 0000000000000..af78006983450 --- /dev/null +++ b/google/cloud/apihub/v1/mocks/mock_linting_connection.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_LINTING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_LINTING_CONNECTION_H + +#include "google/cloud/apihub/v1/linting_connection.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `LintingServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `LintingServiceClient`. To do so, + * construct an object of type `LintingServiceClient` 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 MockLintingServiceConnection + : public apihub_v1::LintingServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, GetStyleGuide, + (google::cloud::apihub::v1::GetStyleGuideRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateStyleGuide, + (google::cloud::apihub::v1::UpdateStyleGuideRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, + GetStyleGuideContents, + (google::cloud::apihub::v1::GetStyleGuideContentsRequest const& request), + (override)); + + MOCK_METHOD(Status, LintSpec, + (google::cloud::apihub::v1::LintSpecRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_LINTING_CONNECTION_H diff --git a/google/cloud/apihub/v1/mocks/mock_provisioning_connection.h b/google/cloud/apihub/v1/mocks/mock_provisioning_connection.h new file mode 100644 index 0000000000000..93ff25285c4c2 --- /dev/null +++ b/google/cloud/apihub/v1/mocks/mock_provisioning_connection.h @@ -0,0 +1,105 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_PROVISIONING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_PROVISIONING_CONNECTION_H + +#include "google/cloud/apihub/v1/provisioning_connection.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `ProvisioningConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `ProvisioningClient`. To do so, + * construct an object of type `ProvisioningClient` 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 MockProvisioningConnection : public apihub_v1::ProvisioningConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + /// To disambiguate calls, use: + /// + /// @code + /// using ::testing::_; + /// using ::testing::Matcher; + /// EXPECT_CALL(*mock, + /// CreateApiHubInstance(Matcher(_))) + /// @endcode + MOCK_METHOD( + future>, + CreateApiHubInstance, + (google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request), + (override)); + + /// To disambiguate calls, use: + /// + /// @code + /// using ::testing::_; + /// EXPECT_CALL(*mock, CreateApiHubInstance(_, _)) + /// @endcode + MOCK_METHOD( + StatusOr, CreateApiHubInstance, + (NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request), + (override)); + + /// To disambiguate calls, use: + /// + /// @code + /// using ::testing::_; + /// using ::testing::Matcher; + /// EXPECT_CALL(*mock, + /// CreateApiHubInstance(Matcher(_))) + /// @endcode + MOCK_METHOD(future>, + CreateApiHubInstance, + (google::longrunning::Operation const& operation), (override)); + + MOCK_METHOD( + StatusOr, GetApiHubInstance, + (google::cloud::apihub::v1::GetApiHubInstanceRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, + LookupApiHubInstance, + (google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_PROVISIONING_CONNECTION_H diff --git a/google/cloud/apihub/v1/mocks/mock_runtime_project_attachment_connection.h b/google/cloud/apihub/v1/mocks/mock_runtime_project_attachment_connection.h new file mode 100644 index 0000000000000..6b9f669c98242 --- /dev/null +++ b/google/cloud/apihub/v1/mocks/mock_runtime_project_attachment_connection.h @@ -0,0 +1,91 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_H + +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `RuntimeProjectAttachmentServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type + * `RuntimeProjectAttachmentServiceClient`. To do so, construct an object of + * type `RuntimeProjectAttachmentServiceClient` 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 MockRuntimeProjectAttachmentServiceConnection + : public apihub_v1::RuntimeProjectAttachmentServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + StatusOr, + CreateRuntimeProjectAttachment, + (google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request), + (override)); + + MOCK_METHOD( + StatusOr, + GetRuntimeProjectAttachment, + (google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request), + (override)); + + MOCK_METHOD( + (StreamRange), + ListRuntimeProjectAttachments, + (google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request), + (override)); + + MOCK_METHOD( + Status, DeleteRuntimeProjectAttachment, + (google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request), + (override)); + + MOCK_METHOD( + StatusOr< + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentResponse>, + LookupRuntimeProjectAttachment, + (google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_MOCKS_MOCK_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_H diff --git a/google/cloud/apihub/v1/provisioning_client.cc b/google/cloud/apihub/v1/provisioning_client.cc new file mode 100644 index 0000000000000..eb16ae0cc425b --- /dev/null +++ b/google/cloud/apihub/v1/provisioning_client.cc @@ -0,0 +1,121 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/provisioning_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProvisioningClient::ProvisioningClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +ProvisioningClient::~ProvisioningClient() = default; + +future> +ProvisioningClient::CreateApiHubInstance( + std::string const& parent, + google::cloud::apihub::v1::ApiHubInstance const& api_hub_instance, + std::string const& api_hub_instance_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateApiHubInstanceRequest request; + request.set_parent(parent); + *request.mutable_api_hub_instance() = api_hub_instance; + request.set_api_hub_instance_id(api_hub_instance_id); + return connection_->CreateApiHubInstance(request); +} + +StatusOr +ProvisioningClient::CreateApiHubInstance( + NoAwaitTag, std::string const& parent, + google::cloud::apihub::v1::ApiHubInstance const& api_hub_instance, + std::string const& api_hub_instance_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateApiHubInstanceRequest request; + request.set_parent(parent); + *request.mutable_api_hub_instance() = api_hub_instance; + request.set_api_hub_instance_id(api_hub_instance_id); + return connection_->CreateApiHubInstance(NoAwaitTag{}, request); +} + +future> +ProvisioningClient::CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateApiHubInstance(request); +} + +StatusOr +ProvisioningClient::CreateApiHubInstance( + NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateApiHubInstance(NoAwaitTag{}, request); +} + +future> +ProvisioningClient::CreateApiHubInstance( + google::longrunning::Operation const& operation, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateApiHubInstance(operation); +} + +StatusOr +ProvisioningClient::GetApiHubInstance(std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetApiHubInstanceRequest request; + request.set_name(name); + return connection_->GetApiHubInstance(request); +} + +StatusOr +ProvisioningClient::GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetApiHubInstance(request); +} + +StatusOr +ProvisioningClient::LookupApiHubInstance(std::string const& parent, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::LookupApiHubInstanceRequest request; + request.set_parent(parent); + return connection_->LookupApiHubInstance(request); +} + +StatusOr +ProvisioningClient::LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->LookupApiHubInstance(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/provisioning_client.h b/google/cloud/apihub/v1/provisioning_client.h new file mode 100644 index 0000000000000..94c6112b56fce --- /dev/null +++ b/google/cloud/apihub/v1/provisioning_client.h @@ -0,0 +1,349 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CLIENT_H + +#include "google/cloud/apihub/v1/provisioning_connection.h" +#include "google/cloud/future.h" +#include "google/cloud/no_await_tag.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 +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This service is used for managing the data plane provisioning of the API +/// hub. +/// +/// @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 ProvisioningClient { + public: + explicit ProvisioningClient( + std::shared_ptr connection, Options opts = {}); + ~ProvisioningClient(); + + ///@{ + /// @name Copy and move support + ProvisioningClient(ProvisioningClient const&) = default; + ProvisioningClient& operator=(ProvisioningClient const&) = default; + ProvisioningClient(ProvisioningClient&&) = default; + ProvisioningClient& operator=(ProvisioningClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(ProvisioningClient const& a, + ProvisioningClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(ProvisioningClient const& a, + ProvisioningClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Provisions instance resources for the API Hub. + /// + /// @param parent Required. The parent resource for the Api Hub instance resource. + /// Format: `projects/{project}/locations/{location}` + /// @param api_hub_instance Required. The ApiHub instance. + /// @param api_hub_instance_id Optional. Identifier to assign to the Api Hub instance. Must be unique + /// within scope of the parent resource. If the field is not provided, system + /// generated id will be used. + /// @n + /// This value should be 4-40 characters, and valid characters + /// are `/[a-z][A-Z][0-9]-_/`. + /// @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.cloud.apihub.v1.ApiHubInstance] 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.cloud.apihub.v1.ApiHubInstance]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1180} + /// [google.cloud.apihub.v1.CreateApiHubInstanceRequest]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L77} + /// + // clang-format on + future> + CreateApiHubInstance( + std::string const& parent, + google::cloud::apihub::v1::ApiHubInstance const& api_hub_instance, + std::string const& api_hub_instance_id, Options opts = {}); + + // clang-format off + /// + /// @copybrief CreateApiHubInstance + /// + /// Specifying the [`NoAwaitTag`] immediately returns the + /// [`google::longrunning::Operation`] that corresponds to the Long Running + /// Operation that has been started. No polling for operation status occurs. + /// + /// [`NoAwaitTag`]: @ref google::cloud::NoAwaitTag + /// + // clang-format on + StatusOr CreateApiHubInstance( + NoAwaitTag, std::string const& parent, + google::cloud::apihub::v1::ApiHubInstance const& api_hub_instance, + std::string const& api_hub_instance_id, Options opts = {}); + + // clang-format off + /// + /// Provisions instance resources for the API Hub. + /// + /// @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.apihub.v1.CreateApiHubInstanceRequest]. + /// 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.cloud.apihub.v1.ApiHubInstance] 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.cloud.apihub.v1.ApiHubInstance]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1180} + /// [google.cloud.apihub.v1.CreateApiHubInstanceRequest]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L77} + /// + // clang-format on + future> + CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// @copybrief CreateApiHubInstance + /// + /// Specifying the [`NoAwaitTag`] immediately returns the + /// [`google::longrunning::Operation`] that corresponds to the Long Running + /// Operation that has been started. No polling for operation status occurs. + /// + /// [`NoAwaitTag`]: @ref google::cloud::NoAwaitTag + /// + // clang-format on + StatusOr CreateApiHubInstance( + NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// @copybrief CreateApiHubInstance + /// + /// This method accepts a `google::longrunning::Operation` that corresponds + /// to a previously started Long Running Operation (LRO) and polls the status + /// of the LRO in the background. + /// + // clang-format on + future> + CreateApiHubInstance(google::longrunning::Operation const& operation, + Options opts = {}); + + // clang-format off + /// + /// Gets details of a single API Hub instance. + /// + /// @param name Required. The name of the Api Hub instance to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/apiHubInstances/{apiHubInstance}`. + /// @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.apihub.v1.ApiHubInstance]) + /// 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 + /// [`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.apihub.v1.ApiHubInstance]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1180} + /// [google.cloud.apihub.v1.GetApiHubInstanceRequest]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L102} + /// + // clang-format on + StatusOr GetApiHubInstance( + std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Gets details of a single API Hub instance. + /// + /// @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.apihub.v1.GetApiHubInstanceRequest]. + /// 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.apihub.v1.ApiHubInstance]) + /// 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 + /// [`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.apihub.v1.ApiHubInstance]: @googleapis_reference_link{google/cloud/apihub/v1/common_fields.proto#L1180} + /// [google.cloud.apihub.v1.GetApiHubInstanceRequest]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L102} + /// + // clang-format on + StatusOr GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Looks up an Api Hub instance in a given GCP project. There will always be + /// only one Api Hub instance for a GCP project across all locations. + /// + /// @param parent Required. There will always be only one Api Hub instance for a GCP project + /// across all locations. + /// The parent resource for the Api Hub instance resource. + /// Format: `projects/{project}/locations/{location}` + /// @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.apihub.v1.LookupApiHubInstanceResponse]) + /// 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 + /// [`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.apihub.v1.LookupApiHubInstanceRequest]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L117} + /// [google.cloud.apihub.v1.LookupApiHubInstanceResponse]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L133} + /// + // clang-format on + StatusOr + LookupApiHubInstance(std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// Looks up an Api Hub instance in a given GCP project. There will always be + /// only one Api Hub instance for a GCP project across all locations. + /// + /// @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.apihub.v1.LookupApiHubInstanceRequest]. + /// 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.apihub.v1.LookupApiHubInstanceResponse]) + /// 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 + /// [`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.apihub.v1.LookupApiHubInstanceRequest]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L117} + /// [google.cloud.apihub.v1.LookupApiHubInstanceResponse]: @googleapis_reference_link{google/cloud/apihub/v1/provisioning_service.proto#L133} + /// + // clang-format on + StatusOr + LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CLIENT_H diff --git a/google/cloud/apihub/v1/provisioning_connection.cc b/google/cloud/apihub/v1/provisioning_connection.cc new file mode 100644 index 0000000000000..6a6cb14eadfa9 --- /dev/null +++ b/google/cloud/apihub/v1/provisioning_connection.cc @@ -0,0 +1,94 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/provisioning_connection.h" +#include "google/cloud/apihub/v1/internal/provisioning_connection_impl.h" +#include "google/cloud/apihub/v1/internal/provisioning_option_defaults.h" +#include "google/cloud/apihub/v1/internal/provisioning_stub_factory.h" +#include "google/cloud/apihub/v1/internal/provisioning_tracing_connection.h" +#include "google/cloud/apihub/v1/provisioning_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/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProvisioningConnection::~ProvisioningConnection() = default; + +future> +ProvisioningConnection::CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const&) { + return google::cloud::make_ready_future< + StatusOr>( + Status(StatusCode::kUnimplemented, "not implemented")); +} + +StatusOr +ProvisioningConnection::CreateApiHubInstance( + NoAwaitTag, google::cloud::apihub::v1::CreateApiHubInstanceRequest const&) { + return StatusOr( + Status(StatusCode::kUnimplemented, "not implemented")); +} + +future> +ProvisioningConnection::CreateApiHubInstance( + google::longrunning::Operation const&) { + return google::cloud::make_ready_future< + StatusOr>( + Status(StatusCode::kUnimplemented, "not implemented")); +} + +StatusOr +ProvisioningConnection::GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +ProvisioningConnection::LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +std::shared_ptr MakeProvisioningConnection( + Options options) { + internal::CheckExpectedOptions(options, + __func__); + options = apihub_v1_internal::ProvisioningDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); + auto stub = apihub_v1_internal::CreateDefaultProvisioningStub(std::move(auth), + options); + return apihub_v1_internal::MakeProvisioningTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/provisioning_connection.h b/google/cloud/apihub/v1/provisioning_connection.h new file mode 100644 index 0000000000000..1cab6385d7e00 --- /dev/null +++ b/google/cloud/apihub/v1/provisioning_connection.h @@ -0,0 +1,236 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CONNECTION_H + +#include "google/cloud/apihub/v1/internal/provisioning_retry_traits.h" +#include "google/cloud/apihub/v1/provisioning_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/no_await_tag.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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `ProvisioningConnection`. +class ProvisioningRetryPolicy : 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 `ProvisioningConnection` 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 ProvisioningLimitedErrorCountRetryPolicy + : public ProvisioningRetryPolicy { + 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 ProvisioningLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ProvisioningLimitedErrorCountRetryPolicy( + ProvisioningLimitedErrorCountRetryPolicy&& rhs) noexcept + : ProvisioningLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ProvisioningLimitedErrorCountRetryPolicy( + ProvisioningLimitedErrorCountRetryPolicy const& rhs) noexcept + : ProvisioningLimitedErrorCountRetryPolicy(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 = ProvisioningRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apihub_v1_internal::ProvisioningRetryTraits> + impl_; +}; + +/** + * A retry policy for `ProvisioningConnection` 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 ProvisioningLimitedTimeRetryPolicy : public ProvisioningRetryPolicy { + 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 ProvisioningLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ProvisioningLimitedTimeRetryPolicy( + ProvisioningLimitedTimeRetryPolicy&& rhs) noexcept + : ProvisioningLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ProvisioningLimitedTimeRetryPolicy( + ProvisioningLimitedTimeRetryPolicy const& rhs) noexcept + : ProvisioningLimitedTimeRetryPolicy(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 = ProvisioningRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apihub_v1_internal::ProvisioningRetryTraits> + impl_; +}; + +/** + * The `ProvisioningConnection` object for `ProvisioningClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `ProvisioningClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `ProvisioningClient`. + * + * To create a concrete instance, see `MakeProvisioningConnection()`. + * + * For mocking, see `apihub_v1_mocks::MockProvisioningConnection`. + */ +class ProvisioningConnection { + public: + virtual ~ProvisioningConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual future> + CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request); + + virtual StatusOr CreateApiHubInstance( + NoAwaitTag, + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request); + + virtual future> + CreateApiHubInstance(google::longrunning::Operation const& operation); + + virtual StatusOr GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request); + + virtual StatusOr + LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request); +}; + +/** + * A factory function to construct an object of type `ProvisioningConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of ProvisioningClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `ProvisioningConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::apihub_v1::ProvisioningPolicyOptionList` + * + * @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 `ProvisioningConnection` created by + * this function. + */ +std::shared_ptr MakeProvisioningConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CONNECTION_H diff --git a/google/cloud/apihub/v1/provisioning_connection_idempotency_policy.cc b/google/cloud/apihub/v1/provisioning_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..b0c6e515a7506 --- /dev/null +++ b/google/cloud/apihub/v1/provisioning_connection_idempotency_policy.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/provisioning_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +ProvisioningConnectionIdempotencyPolicy:: + ~ProvisioningConnectionIdempotencyPolicy() = default; + +std::unique_ptr +ProvisioningConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency ProvisioningConnectionIdempotencyPolicy::CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ProvisioningConnectionIdempotencyPolicy::GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ProvisioningConnectionIdempotencyPolicy::LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const&) { + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultProvisioningConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/provisioning_connection_idempotency_policy.h b/google/cloud/apihub/v1/provisioning_connection_idempotency_policy.h new file mode 100644 index 0000000000000..edc8dc613c8fb --- /dev/null +++ b/google/cloud/apihub/v1/provisioning_connection_idempotency_policy.h @@ -0,0 +1,58 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProvisioningConnectionIdempotencyPolicy { + public: + virtual ~ProvisioningConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency CreateApiHubInstance( + google::cloud::apihub::v1::CreateApiHubInstanceRequest const& request); + + virtual google::cloud::Idempotency GetApiHubInstance( + google::cloud::apihub::v1::GetApiHubInstanceRequest const& request); + + virtual google::cloud::Idempotency LookupApiHubInstance( + google::cloud::apihub::v1::LookupApiHubInstanceRequest const& request); +}; + +std::unique_ptr +MakeDefaultProvisioningConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/apihub/v1/provisioning_options.h b/google/cloud/apihub/v1/provisioning_options.h new file mode 100644 index 0000000000000..94411dcaa7d0f --- /dev/null +++ b/google/cloud/apihub/v1/provisioning_options.h @@ -0,0 +1,86 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_OPTIONS_H + +#include "google/cloud/apihub/v1/provisioning_connection.h" +#include "google/cloud/apihub/v1/provisioning_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ProvisioningRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ProvisioningBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-apihub-options + */ +struct ProvisioningConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the long-running operations + * polling policy. + * + * @ingroup google-cloud-apihub-options + */ +struct ProvisioningPollingPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to Provisioning. + * + * @ingroup google-cloud-apihub-options + */ +using ProvisioningPolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_PROVISIONING_OPTIONS_H diff --git a/google/cloud/apihub/v1/runtime_project_attachment_client.cc b/google/cloud/apihub/v1/runtime_project_attachment_client.cc new file mode 100644 index 0000000000000..c10b636c63cb5 --- /dev/null +++ b/google/cloud/apihub/v1/runtime_project_attachment_client.cc @@ -0,0 +1,132 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/runtime_project_attachment_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RuntimeProjectAttachmentServiceClient::RuntimeProjectAttachmentServiceClient( + std::shared_ptr connection, + Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +RuntimeProjectAttachmentServiceClient:: + ~RuntimeProjectAttachmentServiceClient() = default; + +StatusOr +RuntimeProjectAttachmentServiceClient::CreateRuntimeProjectAttachment( + std::string const& parent, + google::cloud::apihub::v1::RuntimeProjectAttachment const& + runtime_project_attachment, + std::string const& runtime_project_attachment_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest request; + request.set_parent(parent); + *request.mutable_runtime_project_attachment() = runtime_project_attachment; + request.set_runtime_project_attachment_id(runtime_project_attachment_id); + return connection_->CreateRuntimeProjectAttachment(request); +} + +StatusOr +RuntimeProjectAttachmentServiceClient::CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateRuntimeProjectAttachment(request); +} + +StatusOr +RuntimeProjectAttachmentServiceClient::GetRuntimeProjectAttachment( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest request; + request.set_name(name); + return connection_->GetRuntimeProjectAttachment(request); +} + +StatusOr +RuntimeProjectAttachmentServiceClient::GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetRuntimeProjectAttachment(request); +} + +StreamRange +RuntimeProjectAttachmentServiceClient::ListRuntimeProjectAttachments( + std::string const& parent, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request; + request.set_parent(parent); + return connection_->ListRuntimeProjectAttachments(request); +} + +StreamRange +RuntimeProjectAttachmentServiceClient::ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListRuntimeProjectAttachments(std::move(request)); +} + +Status RuntimeProjectAttachmentServiceClient::DeleteRuntimeProjectAttachment( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest request; + request.set_name(name); + return connection_->DeleteRuntimeProjectAttachment(request); +} + +Status RuntimeProjectAttachmentServiceClient::DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteRuntimeProjectAttachment(request); +} + +StatusOr +RuntimeProjectAttachmentServiceClient::LookupRuntimeProjectAttachment( + std::string const& name, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest request; + request.set_name(name); + return connection_->LookupRuntimeProjectAttachment(request); +} + +StatusOr +RuntimeProjectAttachmentServiceClient::LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->LookupRuntimeProjectAttachment(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/runtime_project_attachment_client.h b/google/cloud/apihub/v1/runtime_project_attachment_client.h new file mode 100644 index 0000000000000..5f575a6cced2d --- /dev/null +++ b/google/cloud/apihub/v1/runtime_project_attachment_client.h @@ -0,0 +1,424 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CLIENT_H + +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.h" +#include "google/cloud/future.h" +#include "google/cloud/options.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This service is used for managing the runtime project attachments. +/// +/// @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 RuntimeProjectAttachmentServiceClient { + public: + explicit RuntimeProjectAttachmentServiceClient( + std::shared_ptr connection, + Options opts = {}); + ~RuntimeProjectAttachmentServiceClient(); + + ///@{ + /// @name Copy and move support + RuntimeProjectAttachmentServiceClient( + RuntimeProjectAttachmentServiceClient const&) = default; + RuntimeProjectAttachmentServiceClient& operator=( + RuntimeProjectAttachmentServiceClient const&) = default; + RuntimeProjectAttachmentServiceClient( + RuntimeProjectAttachmentServiceClient&&) = default; + RuntimeProjectAttachmentServiceClient& operator=( + RuntimeProjectAttachmentServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(RuntimeProjectAttachmentServiceClient const& a, + RuntimeProjectAttachmentServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(RuntimeProjectAttachmentServiceClient const& a, + RuntimeProjectAttachmentServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Attaches a runtime project to the host project. + /// + /// @param parent Required. The parent resource for the Runtime Project Attachment. + /// Format: `projects/{project}/locations/{location}` + /// @param runtime_project_attachment Required. The Runtime Project Attachment to create. + /// @param runtime_project_attachment_id Required. The ID to use for the Runtime Project Attachment, which will + /// become the final component of the Runtime Project Attachment's name. The ID + /// must be the same as the project ID of the Google cloud project specified in + /// the runtime_project_attachment.runtime_project field. + /// @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.apihub.v1.RuntimeProjectAttachment]) + /// 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 + /// [`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.apihub.v1.CreateRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L93} + /// [google.cloud.apihub.v1.RuntimeProjectAttachment]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L234} + /// + // clang-format on + StatusOr + CreateRuntimeProjectAttachment( + std::string const& parent, + google::cloud::apihub::v1::RuntimeProjectAttachment const& + runtime_project_attachment, + std::string const& runtime_project_attachment_id, Options opts = {}); + + // clang-format off + /// + /// Attaches a runtime project to the host project. + /// + /// @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.apihub.v1.CreateRuntimeProjectAttachmentRequest]. + /// 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.apihub.v1.RuntimeProjectAttachment]) + /// 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 + /// [`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.apihub.v1.CreateRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L93} + /// [google.cloud.apihub.v1.RuntimeProjectAttachment]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L234} + /// + // clang-format on + StatusOr + CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request, + Options opts = {}); + + // clang-format off + /// + /// Gets a runtime project attachment. + /// + /// @param name Required. The name of the API resource to retrieve. + /// Format: + /// `projects/{project}/locations/{location}/runtimeProjectAttachments/{runtime_project_attachment}` + /// @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.apihub.v1.RuntimeProjectAttachment]) + /// 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 + /// [`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.apihub.v1.GetRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L118} + /// [google.cloud.apihub.v1.RuntimeProjectAttachment]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L234} + /// + // clang-format on + StatusOr + GetRuntimeProjectAttachment(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Gets a runtime project attachment. + /// + /// @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.apihub.v1.GetRuntimeProjectAttachmentRequest]. + /// 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.apihub.v1.RuntimeProjectAttachment]) + /// 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 + /// [`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.apihub.v1.GetRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L118} + /// [google.cloud.apihub.v1.RuntimeProjectAttachment]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L234} + /// + // clang-format on + StatusOr + GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request, + Options opts = {}); + + // clang-format off + /// + /// List runtime projects attached to the host project. + /// + /// @param parent Required. The parent, which owns this collection of runtime project + /// attachments. Format: `projects/{project}/locations/{location}` + /// @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.cloud.apihub.v1.RuntimeProjectAttachment], 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 + /// [`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.apihub.v1.ListRuntimeProjectAttachmentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L133} + /// [google.cloud.apihub.v1.RuntimeProjectAttachment]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L234} + /// + // clang-format on + StreamRange + ListRuntimeProjectAttachments(std::string const& parent, Options opts = {}); + + // clang-format off + /// + /// List runtime projects attached to the host project. + /// + /// @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.apihub.v1.ListRuntimeProjectAttachmentsRequest]. + /// 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.cloud.apihub.v1.RuntimeProjectAttachment], 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 + /// [`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.apihub.v1.ListRuntimeProjectAttachmentsRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L133} + /// [google.cloud.apihub.v1.RuntimeProjectAttachment]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L234} + /// + // clang-format on + StreamRange + ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request, + Options opts = {}); + + // clang-format off + /// + /// Delete a runtime project attachment in the API Hub. This call will detach + /// the runtime project from the host project. + /// + /// @param name Required. The name of the Runtime Project Attachment to delete. + /// Format: + /// `projects/{project}/locations/{location}/runtimeProjectAttachments/{runtime_project_attachment}` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L195} + /// + // clang-format on + Status DeleteRuntimeProjectAttachment(std::string const& name, + Options opts = {}); + + // clang-format off + /// + /// Delete a runtime project attachment in the API Hub. This call will detach + /// the runtime project from the host project. + /// + /// @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.apihub.v1.DeleteRuntimeProjectAttachmentRequest]. + /// 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 [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`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.apihub.v1.DeleteRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L195} + /// + // clang-format on + Status DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request, + Options opts = {}); + + // clang-format off + /// + /// Look up a runtime project attachment. This API can be called in the context + /// of any project. + /// + /// @param name Required. Runtime project ID to look up runtime project attachment for. + /// Lookup happens across all regions. Expected format: + /// `projects/{project}/locations/{location}`. + /// @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.apihub.v1.LookupRuntimeProjectAttachmentResponse]) + /// 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 + /// [`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.apihub.v1.LookupRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L210} + /// [google.cloud.apihub.v1.LookupRuntimeProjectAttachmentResponse]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L225} + /// + // clang-format on + StatusOr + LookupRuntimeProjectAttachment(std::string const& name, Options opts = {}); + + // clang-format off + /// + /// Look up a runtime project attachment. This API can be called in the context + /// of any project. + /// + /// @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.apihub.v1.LookupRuntimeProjectAttachmentRequest]. + /// 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.apihub.v1.LookupRuntimeProjectAttachmentResponse]) + /// 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 + /// [`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.apihub.v1.LookupRuntimeProjectAttachmentRequest]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L210} + /// [google.cloud.apihub.v1.LookupRuntimeProjectAttachmentResponse]: @googleapis_reference_link{google/cloud/apihub/v1/runtime_project_attachment_service.proto#L225} + /// + // clang-format on + StatusOr + LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CLIENT_H diff --git a/google/cloud/apihub/v1/runtime_project_attachment_connection.cc b/google/cloud/apihub/v1/runtime_project_attachment_connection.cc new file mode 100644 index 0000000000000..d20c59ea8fd3b --- /dev/null +++ b/google/cloud/apihub/v1/runtime_project_attachment_connection.cc @@ -0,0 +1,96 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_connection_impl.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_option_defaults.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_stub_factory.h" +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_tracing_connection.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RuntimeProjectAttachmentServiceConnection:: + ~RuntimeProjectAttachmentServiceConnection() = default; + +StatusOr +RuntimeProjectAttachmentServiceConnection::CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +RuntimeProjectAttachmentServiceConnection::GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +RuntimeProjectAttachmentServiceConnection::ListRuntimeProjectAttachments( + google::cloud::apihub::v1:: + ListRuntimeProjectAttachmentsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +Status +RuntimeProjectAttachmentServiceConnection::DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +RuntimeProjectAttachmentServiceConnection::LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +std::shared_ptr +MakeRuntimeProjectAttachmentServiceConnection(Options options) { + internal::CheckExpectedOptions< + CommonOptionList, GrpcOptionList, UnifiedCredentialsOptionList, + RuntimeProjectAttachmentServicePolicyOptionList>(options, __func__); + options = apihub_v1_internal::RuntimeProjectAttachmentServiceDefaultOptions( + std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); + auto stub = + apihub_v1_internal::CreateDefaultRuntimeProjectAttachmentServiceStub( + std::move(auth), options); + return apihub_v1_internal:: + MakeRuntimeProjectAttachmentServiceTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/runtime_project_attachment_connection.h b/google/cloud/apihub/v1/runtime_project_attachment_connection.h new file mode 100644 index 0000000000000..b628ef79fc8f6 --- /dev/null +++ b/google/cloud/apihub/v1/runtime_project_attachment_connection.h @@ -0,0 +1,260 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_H + +#include "google/cloud/apihub/v1/internal/runtime_project_attachment_retry_traits.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_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/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `RuntimeProjectAttachmentServiceConnection`. +class RuntimeProjectAttachmentServiceRetryPolicy + : 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 `RuntimeProjectAttachmentServiceConnection` 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 RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy + : public RuntimeProjectAttachmentServiceRetryPolicy { + 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 RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy( + RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy&& + rhs) noexcept + : RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy( + RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy const& + rhs) noexcept + : RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy( + 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< + RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy>( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RuntimeProjectAttachmentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + apihub_v1_internal::RuntimeProjectAttachmentServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `RuntimeProjectAttachmentServiceConnection` 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 RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy + : public RuntimeProjectAttachmentServiceRetryPolicy { + 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 RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy( + RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy&& rhs) noexcept + : RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy( + rhs.maximum_duration()) {} + RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy( + RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy const& rhs) noexcept + : RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy( + 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< + RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy>( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RuntimeProjectAttachmentServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + apihub_v1_internal::RuntimeProjectAttachmentServiceRetryTraits> + impl_; +}; + +/** + * The `RuntimeProjectAttachmentServiceConnection` object for + * `RuntimeProjectAttachmentServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `RuntimeProjectAttachmentServiceClient`. This allows users to inject + * custom behavior (e.g., with a Google Mock object) when writing tests that use + * objects of type `RuntimeProjectAttachmentServiceClient`. + * + * To create a concrete instance, see + * `MakeRuntimeProjectAttachmentServiceConnection()`. + * + * For mocking, see + * `apihub_v1_mocks::MockRuntimeProjectAttachmentServiceConnection`. + */ +class RuntimeProjectAttachmentServiceConnection { + public: + virtual ~RuntimeProjectAttachmentServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr + CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request); + + virtual StatusOr + GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request); + + virtual StreamRange + ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request); + + virtual Status DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request); + + virtual StatusOr< + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentResponse> + LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request); +}; + +/** + * A factory function to construct an object of type + * `RuntimeProjectAttachmentServiceConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of + * RuntimeProjectAttachmentServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `RuntimeProjectAttachmentServiceConnection`. Expected options are + * any of the types in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::apihub_v1::RuntimeProjectAttachmentServicePolicyOptionList` + * + * @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 + * `RuntimeProjectAttachmentServiceConnection` created by this function. + */ +std::shared_ptr +MakeRuntimeProjectAttachmentServiceConnection(Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_H diff --git a/google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.cc b/google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..b1a5ffd8e20fe --- /dev/null +++ b/google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.cc @@ -0,0 +1,81 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy:: + ~RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique< + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy>(*this); +} + +Idempotency RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy:: + CreateRuntimeProjectAttachment( + google::cloud::apihub::v1:: + CreateRuntimeProjectAttachmentRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy:: + GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy:: + ListRuntimeProjectAttachments( + google::cloud::apihub::v1:: + ListRuntimeProjectAttachmentsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy:: + DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1:: + DeleteRuntimeProjectAttachmentRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy:: + LookupRuntimeProjectAttachment( + google::cloud::apihub::v1:: + LookupRuntimeProjectAttachmentRequest const&) { + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultRuntimeProjectAttachmentServiceConnectionIdempotencyPolicy() { + return std::make_unique< + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy>(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google diff --git a/google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.h b/google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.h new file mode 100644 index 0000000000000..35d9e28523dc4 --- /dev/null +++ b/google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.h @@ -0,0 +1,69 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy { + public: + virtual ~RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr< + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy> + clone() const; + + virtual google::cloud::Idempotency CreateRuntimeProjectAttachment( + google::cloud::apihub::v1::CreateRuntimeProjectAttachmentRequest const& + request); + + virtual google::cloud::Idempotency GetRuntimeProjectAttachment( + google::cloud::apihub::v1::GetRuntimeProjectAttachmentRequest const& + request); + + virtual google::cloud::Idempotency ListRuntimeProjectAttachments( + google::cloud::apihub::v1::ListRuntimeProjectAttachmentsRequest request); + + virtual google::cloud::Idempotency DeleteRuntimeProjectAttachment( + google::cloud::apihub::v1::DeleteRuntimeProjectAttachmentRequest const& + request); + + virtual google::cloud::Idempotency LookupRuntimeProjectAttachment( + google::cloud::apihub::v1::LookupRuntimeProjectAttachmentRequest const& + request); +}; + +std::unique_ptr +MakeDefaultRuntimeProjectAttachmentServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/apihub/v1/runtime_project_attachment_options.h b/google/cloud/apihub/v1/runtime_project_attachment_options.h new file mode 100644 index 0000000000000..041252bd1a2af --- /dev/null +++ b/google/cloud/apihub/v1/runtime_project_attachment_options.h @@ -0,0 +1,77 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_OPTIONS_H + +#include "google/cloud/apihub/v1/runtime_project_attachment_connection.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_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 apihub_v1 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-apihub-options + */ +struct RuntimeProjectAttachmentServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-apihub-options + */ +struct RuntimeProjectAttachmentServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-apihub-options + */ +struct RuntimeProjectAttachmentServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr< + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy>; +}; + +/** + * The options applicable to RuntimeProjectAttachmentService. + * + * @ingroup google-cloud-apihub-options + */ +using RuntimeProjectAttachmentServicePolicyOptionList = OptionList< + RuntimeProjectAttachmentServiceRetryPolicyOption, + RuntimeProjectAttachmentServiceBackoffPolicyOption, + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicyOption>; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace apihub_v1 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_APIHUB_V1_RUNTIME_PROJECT_ATTACHMENT_OPTIONS_H diff --git a/google/cloud/apihub/v1/samples/api_hub_client_samples.cc b/google/cloud/apihub/v1/samples/api_hub_client_samples.cc new file mode 100644 index 0000000000000..c9cf9e6652d19 --- /dev/null +++ b/google/cloud/apihub/v1/samples/api_hub_client_samples.cc @@ -0,0 +1,153 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_client.h" +#include "google/cloud/apihub/v1/api_hub_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/api_hub_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: apihub_v1::ApiHubClient +// 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::apihub_v1::ApiHubClient( + google::cloud::apihub_v1::MakeApiHubConnection(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::apihub_v1::ApiHubConnectionIdempotencyPolicy { + 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::apihub_v1::ApiHubLimitedErrorCountRetryPolicy(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::apihub_v1::MakeApiHubConnection(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::apihub_v1::ApiHubClient(connection); + auto c2 = google::cloud::apihub_v1::ApiHubClient(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::apihub_v1::ApiHubClient( + connection, + google::cloud::Options{} + .set( + google::cloud::apihub_v1::ApiHubLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::apihub_v1::ApiHubLimitedErrorCountRetryPolicy(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::apihub_v1::ApiHubClient( + google::cloud::apihub_v1::MakeApiHubConnection(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/apihub/v1/samples/api_hub_dependencies_client_samples.cc b/google/cloud/apihub/v1/samples/api_hub_dependencies_client_samples.cc new file mode 100644 index 0000000000000..f1050f60fb57d --- /dev/null +++ b/google/cloud/apihub/v1/samples/api_hub_dependencies_client_samples.cc @@ -0,0 +1,158 @@ +// Copyright 2024 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/apihub/v1/apihub_service.proto + +#include "google/cloud/apihub/v1/api_hub_dependencies_client.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/api_hub_dependencies_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: apihub_v1::ApiHubDependenciesClient +// 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::apihub_v1::ApiHubDependenciesClient( + google::cloud::apihub_v1::MakeApiHubDependenciesConnection(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::apihub_v1:: + ApiHubDependenciesConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr< + google::cloud::apihub_v1::ApiHubDependenciesConnectionIdempotencyPolicy> + 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::apihub_v1:: + ApiHubDependenciesLimitedErrorCountRetryPolicy(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::apihub_v1::MakeApiHubDependenciesConnection(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::apihub_v1::ApiHubDependenciesClient(connection); + auto c2 = google::cloud::apihub_v1::ApiHubDependenciesClient(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::apihub_v1::ApiHubDependenciesClient( + connection, + google::cloud::Options{} + .set( + google::cloud::apihub_v1:: + ApiHubDependenciesLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::apihub_v1::ApiHubDependenciesLimitedErrorCountRetryPolicy(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::apihub_v1::ApiHubDependenciesClient( + google::cloud::apihub_v1::MakeApiHubDependenciesConnection(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/apihub/v1/samples/api_hub_plugin_client_samples.cc b/google/cloud/apihub/v1/samples/api_hub_plugin_client_samples.cc new file mode 100644 index 0000000000000..ded870a392a58 --- /dev/null +++ b/google/cloud/apihub/v1/samples/api_hub_plugin_client_samples.cc @@ -0,0 +1,156 @@ +// Copyright 2024 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/apihub/v1/plugin_service.proto + +#include "google/cloud/apihub/v1/api_hub_plugin_client.h" +#include "google/cloud/apihub/v1/api_hub_plugin_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/api_hub_plugin_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: apihub_v1::ApiHubPluginClient +// 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::apihub_v1::ApiHubPluginClient( + google::cloud::apihub_v1::MakeApiHubPluginConnection(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::apihub_v1::ApiHubPluginConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr< + google::cloud::apihub_v1::ApiHubPluginConnectionIdempotencyPolicy> + 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::apihub_v1:: + ApiHubPluginLimitedErrorCountRetryPolicy(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::apihub_v1::MakeApiHubPluginConnection(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::apihub_v1::ApiHubPluginClient(connection); + auto c2 = google::cloud::apihub_v1::ApiHubPluginClient(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::apihub_v1::ApiHubPluginClient( + connection, + google::cloud::Options{} + .set( + google::cloud::apihub_v1::ApiHubPluginLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::apihub_v1::ApiHubPluginLimitedErrorCountRetryPolicy(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::apihub_v1::ApiHubPluginClient( + google::cloud::apihub_v1::MakeApiHubPluginConnection(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/apihub/v1/samples/host_project_registration_client_samples.cc b/google/cloud/apihub/v1/samples/host_project_registration_client_samples.cc new file mode 100644 index 0000000000000..3e021d0f797a3 --- /dev/null +++ b/google/cloud/apihub/v1/samples/host_project_registration_client_samples.cc @@ -0,0 +1,167 @@ +// Copyright 2024 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/apihub/v1/host_project_registration_service.proto + +#include "google/cloud/apihub/v1/host_project_registration_client.h" +#include "google/cloud/apihub/v1/host_project_registration_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/host_project_registration_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: apihub_v1::HostProjectRegistrationServiceClient +// 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::apihub_v1::HostProjectRegistrationServiceClient( + google::cloud::apihub_v1::MakeHostProjectRegistrationServiceConnection( + options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::apihub_v1:: + HostProjectRegistrationServiceConnectionIdempotencyPolicy { + 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< + google::cloud::apihub_v1:: + HostProjectRegistrationServiceConnectionIdempotencyPolicyOption>( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::apihub_v1:: + HostProjectRegistrationServiceLimitedErrorCountRetryPolicy(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::apihub_v1::MakeHostProjectRegistrationServiceConnection( + options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::apihub_v1::HostProjectRegistrationServiceClient( + connection); + auto c2 = google::cloud::apihub_v1::HostProjectRegistrationServiceClient( + 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::apihub_v1::HostProjectRegistrationServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::apihub_v1:: + HostProjectRegistrationServiceLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::apihub_v1::HostProjectRegistrationServiceLimitedErrorCountRetryPolicy(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::apihub_v1::HostProjectRegistrationServiceClient( + google::cloud::apihub_v1::MakeHostProjectRegistrationServiceConnection( + 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/apihub/v1/samples/linting_client_samples.cc b/google/cloud/apihub/v1/samples/linting_client_samples.cc new file mode 100644 index 0000000000000..d968230842166 --- /dev/null +++ b/google/cloud/apihub/v1/samples/linting_client_samples.cc @@ -0,0 +1,156 @@ +// Copyright 2024 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/apihub/v1/linting_service.proto + +#include "google/cloud/apihub/v1/linting_client.h" +#include "google/cloud/apihub/v1/linting_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/linting_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: apihub_v1::LintingServiceClient +// 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::apihub_v1::LintingServiceClient( + google::cloud::apihub_v1::MakeLintingServiceConnection(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy : public google::cloud::apihub_v1:: + LintingServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr< + google::cloud::apihub_v1::LintingServiceConnectionIdempotencyPolicy> + 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::apihub_v1:: + LintingServiceLimitedErrorCountRetryPolicy(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::apihub_v1::MakeLintingServiceConnection(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::apihub_v1::LintingServiceClient(connection); + auto c2 = google::cloud::apihub_v1::LintingServiceClient(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::apihub_v1::LintingServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::apihub_v1::LintingServiceLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::apihub_v1::LintingServiceLimitedErrorCountRetryPolicy(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::apihub_v1::LintingServiceClient( + google::cloud::apihub_v1::MakeLintingServiceConnection(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/apihub/v1/samples/provisioning_client_samples.cc b/google/cloud/apihub/v1/samples/provisioning_client_samples.cc new file mode 100644 index 0000000000000..b873b6118b4d0 --- /dev/null +++ b/google/cloud/apihub/v1/samples/provisioning_client_samples.cc @@ -0,0 +1,200 @@ +// Copyright 2024 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/apihub/v1/provisioning_service.proto + +#include "google/cloud/apihub/v1/provisioning_client.h" +#include "google/cloud/apihub/v1/provisioning_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/provisioning_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: apihub_v1::ProvisioningClient +// lro-marker: true +// 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::apihub_v1::ProvisioningClient( + google::cloud::apihub_v1::MakeProvisioningConnection(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::apihub_v1::ProvisioningConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr< + google::cloud::apihub_v1::ProvisioningConnectionIdempotencyPolicy> + 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::apihub_v1:: + ProvisioningLimitedErrorCountRetryPolicy(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::apihub_v1::MakeProvisioningConnection(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::apihub_v1::ProvisioningClient(connection); + auto c2 = google::cloud::apihub_v1::ProvisioningClient(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::apihub_v1::ProvisioningClient( + connection, + google::cloud::Options{} + .set( + google::cloud::apihub_v1::ProvisioningLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::apihub_v1::ProvisioningLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void SetPollingPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-policy-policy"}; + } + //! [set-polling-policy] + + // The polling policy controls how the client waits for long-running + // operations. `GenericPollingPolicy<>` combines existing policies. + // In this case, keep polling until the operation completes (with success + // or error) or 45 minutes, whichever happens first. Initially pause for + // 10 seconds between polling requests, increasing the pause by a factor + // of 4 until it becomes 2 minutes. + auto options = + google::cloud::Options{} + .set( + google::cloud::GenericPollingPolicy< + google::cloud::apihub_v1::ProvisioningRetryPolicyOption::Type, + google::cloud::apihub_v1::ProvisioningBackoffPolicyOption:: + Type>( + google::cloud::apihub_v1::ProvisioningLimitedTimeRetryPolicy( + /*maximum_duration=*/std::chrono::minutes(45)) + .clone(), + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::seconds(10), + /*maximum_delay=*/std::chrono::minutes(2), + /*scaling=*/4.0) + .clone()) + .clone()); + + auto connection = + google::cloud::apihub_v1::MakeProvisioningConnection(options); + + // c1 and c2 share the same polling policies. + auto c1 = google::cloud::apihub_v1::ProvisioningClient(connection); + auto c2 = google::cloud::apihub_v1::ProvisioningClient(connection); + //! [set-polling-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::apihub_v1::ProvisioningClient( + google::cloud::apihub_v1::MakeProvisioningConnection(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 SetPollingPolicy() example" << std::endl; + SetPollingPolicy({}); + + 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}, + {"set-polling-policy", SetPollingPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/apihub/v1/samples/runtime_project_attachment_client_samples.cc b/google/cloud/apihub/v1/samples/runtime_project_attachment_client_samples.cc new file mode 100644 index 0000000000000..03f9c10e6e965 --- /dev/null +++ b/google/cloud/apihub/v1/samples/runtime_project_attachment_client_samples.cc @@ -0,0 +1,168 @@ +// Copyright 2024 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/apihub/v1/runtime_project_attachment_service.proto + +#include "google/cloud/apihub/v1/runtime_project_attachment_client.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_connection_idempotency_policy.h" +#include "google/cloud/apihub/v1/runtime_project_attachment_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: apihub_v1::RuntimeProjectAttachmentServiceClient +// 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::apihub_v1::RuntimeProjectAttachmentServiceClient( + google::cloud::apihub_v1::MakeRuntimeProjectAttachmentServiceConnection( + options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::apihub_v1:: + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr< + google::cloud::apihub_v1:: + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicy> + 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< + google::cloud::apihub_v1:: + RuntimeProjectAttachmentServiceConnectionIdempotencyPolicyOption>( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::apihub_v1:: + RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy(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::apihub_v1::MakeRuntimeProjectAttachmentServiceConnection( + options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::apihub_v1::RuntimeProjectAttachmentServiceClient( + connection); + auto c2 = google::cloud::apihub_v1::RuntimeProjectAttachmentServiceClient( + 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::apihub_v1::RuntimeProjectAttachmentServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::apihub_v1:: + RuntimeProjectAttachmentServiceLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::apihub_v1::RuntimeProjectAttachmentServiceLimitedErrorCountRetryPolicy(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::apihub_v1::RuntimeProjectAttachmentServiceClient( + google::cloud::apihub_v1::MakeRuntimeProjectAttachmentServiceConnection( + 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/libraries.bzl b/libraries.bzl index f62c08aab10bb..6ac58b4d2f2ff 100644 --- a/libraries.bzl +++ b/libraries.bzl @@ -32,6 +32,7 @@ GOOGLE_CLOUD_CPP_GA_LIBRARIES = [ "alloydb", "apigateway", "apigeeconnect", + "apihub", "apikeys", "appengine", "apphub",