Skip to content

Commit 28a33ff

Browse files
authored
impl(generator): add support for services that support both global and location endpoints (#15184)
1 parent 654c3dc commit 28a33ff

File tree

487 files changed

+694
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

487 files changed

+694
-558
lines changed

generator/generator_config.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ message ServiceConfiguration {
9494
// but were subsequently acknowledged to be "LOCATION_DEPENDENT".
9595
// Do not use for new services.
9696
LOCATION_DEPENDENT_COMPAT = 2;
97+
98+
// Some services support both global and location specific endpoints.
99+
// This directs the generator to emit overloads for both:
100+
// `Make*Connection(Options options = {})`
101+
// `Make*Connection(std::string const& location, Options options = {})`
102+
LOCATION_OPTIONALLY_DEPENDENT = 3;
97103
}
98104
EndpointLocationStyle endpoint_location_style = 15;
99105

generator/integration_tests/golden/v1/golden_rest_only_rest_connection.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ namespace golden_v1 {
3535
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3636

3737
std::shared_ptr<GoldenRestOnlyConnection> MakeGoldenRestOnlyConnectionRest(
38-
Options options) {
38+
std::string const& location, Options options) {
3939
internal::CheckExpectedOptions<CommonOptionList, RestOptionList,
4040
UnifiedCredentialsOptionList, rest_internal::TargetApiVersionOption,
4141
GoldenRestOnlyPolicyOptionList>(options, __func__);
4242
options = golden_v1_internal::GoldenRestOnlyDefaultOptions(
43-
std::move(options));
43+
location, std::move(options));
4444
auto background = std::make_unique<
4545
rest_internal::AutomaticallyCreatedRestBackgroundThreads>();
4646
auto stub = golden_v1_internal::CreateDefaultGoldenRestOnlyRestStub(
@@ -51,6 +51,11 @@ std::shared_ptr<GoldenRestOnlyConnection> MakeGoldenRestOnlyConnectionRest(
5151
std::move(background), std::move(stub), std::move(options)));
5252
}
5353

54+
std::shared_ptr<GoldenRestOnlyConnection> MakeGoldenRestOnlyConnectionRest(
55+
Options options) {
56+
return MakeGoldenRestOnlyConnectionRest(std::string{}, std::move(options));
57+
}
58+
5459
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
5560
} // namespace golden_v1
5661
} // namespace cloud

generator/integration_tests/golden/v1/golden_rest_only_rest_connection.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "google/cloud/options.h"
2424
#include "google/cloud/version.h"
2525
#include <memory>
26+
#include <string>
2627

2728
namespace google {
2829
namespace cloud {
@@ -50,9 +51,19 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
5051
* @note Unexpected options will be ignored. To log unexpected options instead,
5152
* set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment.
5253
*
54+
* @param location Sets the prefix for the default `EndpointOption` value.
5355
* @param options (optional) Configure the `GoldenRestOnlyConnection` created by
5456
* this function.
5557
*/
58+
std::shared_ptr<GoldenRestOnlyConnection> MakeGoldenRestOnlyConnectionRest(
59+
std::string const& location, Options options = {});
60+
61+
/**
62+
* A factory function to construct an object of type `GoldenRestOnlyConnection`.
63+
*
64+
* This overload of `MakeGoldenRestOnlyConnectionRest` does not require a location
65+
* argument, creating a connection to the global service endpoint.
66+
*/
5667
std::shared_ptr<GoldenRestOnlyConnection> MakeGoldenRestOnlyConnectionRest(
5768
Options options = {});
5869

generator/integration_tests/golden/v1/internal/golden_rest_only_option_defaults.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "generator/integration_tests/golden/v1/golden_rest_only_options.h"
2222
#include "google/cloud/internal/populate_common_options.h"
2323
#include "google/cloud/internal/populate_grpc_options.h"
24+
#include "google/cloud/internal/absl_str_cat_quiet.h"
2425
#include <memory>
2526
#include <utility>
2627

@@ -33,11 +34,11 @@ namespace {
3334
auto constexpr kBackoffScaling = 2.0;
3435
} // namespace
3536

36-
Options GoldenRestOnlyDefaultOptions(Options options) {
37+
Options GoldenRestOnlyDefaultOptions(std::string const& location, Options options) {
3738
options = internal::PopulateCommonOptions(
3839
std::move(options), "GOOGLE_CLOUD_CPP_GOLDEN_REST_ONLY_ENDPOINT",
3940
"", "GOOGLE_CLOUD_CPP_GOLDEN_REST_ONLY_AUTHORITY",
40-
"goldenrestonly.googleapis.com");
41+
absl::StrCat(location, location.empty() ? "" : "-", "goldenrestonly.googleapis.com"));
4142
options = internal::PopulateGrpcOptions(std::move(options));
4243
if (!options.has<golden_v1::GoldenRestOnlyRetryPolicyOption>()) {
4344
options.set<golden_v1::GoldenRestOnlyRetryPolicyOption>(

generator/integration_tests/golden/v1/internal/golden_rest_only_option_defaults.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121

2222
#include "google/cloud/options.h"
2323
#include "google/cloud/version.h"
24+
#include <string>
2425

2526
namespace google {
2627
namespace cloud {
2728
namespace golden_v1_internal {
2829
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2930

30-
Options GoldenRestOnlyDefaultOptions(Options options);
31+
Options GoldenRestOnlyDefaultOptions(std::string const& location, Options options);
3132

3233
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
3334
} // namespace golden_v1_internal

generator/integration_tests/golden/v1/samples/deprecated_client_samples.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void SetClientEndpoint(std::vector<std::string> const& argv) {
4242
// https://cloud.google.com/vpc/docs/private-google-access
4343
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
4444
"private.googleapis.com");
45-
auto client = google::cloud::golden_v1::DeprecatedServiceClient(
45+
auto vpc_client = google::cloud::golden_v1::DeprecatedServiceClient(
4646
google::cloud::golden_v1::MakeDeprecatedServiceConnection(options));
4747
//! [set-client-endpoint]
4848
}

generator/integration_tests/golden/v1/samples/golden_kitchen_sink_client_samples.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void SetClientEndpoint(std::vector<std::string> const& argv) {
4242
// https://cloud.google.com/vpc/docs/private-google-access
4343
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
4444
"private.googleapis.com");
45-
auto client = google::cloud::golden_v1::GoldenKitchenSinkClient(
45+
auto vpc_client = google::cloud::golden_v1::GoldenKitchenSinkClient(
4646
google::cloud::golden_v1::MakeGoldenKitchenSinkConnection(options));
4747
//! [set-client-endpoint]
4848
}

generator/integration_tests/golden/v1/samples/golden_rest_only_client_samples.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ void SetClientEndpoint(std::vector<std::string> const& argv) {
3838
throw google::cloud::testing_util::Usage{"set-client-endpoint"};
3939
}
4040
//! [set-client-endpoint]
41+
// This service supports specifying a regional or locational endpoint prefix
42+
// when creating the GoldenRestOnlyConnectionRest.
43+
// For example, to connect to "europe-central2-goldenrestonly.googleapis.com":
44+
auto client = google::cloud::golden_v1::GoldenRestOnlyClient(
45+
google::cloud::golden_v1::MakeGoldenRestOnlyConnectionRest("europe-central2"));
46+
4147
// This configuration is common with Private Google Access:
4248
// https://cloud.google.com/vpc/docs/private-google-access
4349
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
4450
"private.googleapis.com");
45-
auto client = google::cloud::golden_v1::GoldenRestOnlyClient(
51+
auto vpc_client = google::cloud::golden_v1::GoldenRestOnlyClient(
4652
google::cloud::golden_v1::MakeGoldenRestOnlyConnectionRest(options));
4753
//! [set-client-endpoint]
4854
}

generator/integration_tests/golden/v1/samples/golden_thing_admin_client_samples.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void SetClientEndpoint(std::vector<std::string> const& argv) {
4444
// https://cloud.google.com/vpc/docs/private-google-access
4545
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
4646
"private.googleapis.com");
47-
auto client = google::cloud::golden_v1::GoldenThingAdminClient(
47+
auto vpc_client = google::cloud::golden_v1::GoldenThingAdminClient(
4848
google::cloud::golden_v1::MakeGoldenThingAdminConnection(options));
4949
//! [set-client-endpoint]
5050
}

generator/integration_tests/golden/v1/samples/request_id_client_samples.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void SetClientEndpoint(std::vector<std::string> const& argv) {
4444
// https://cloud.google.com/vpc/docs/private-google-access
4545
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
4646
"private.googleapis.com");
47-
auto client = google::cloud::golden_v1::RequestIdServiceClient(
47+
auto vpc_client = google::cloud::golden_v1::RequestIdServiceClient(
4848
google::cloud::golden_v1::MakeRequestIdServiceConnection(options));
4949
//! [set-client-endpoint]
5050
}

0 commit comments

Comments
 (0)