Skip to content

Commit 97361ad

Browse files
authored
feat(resourcemanager): add Connection factory function for regional endpoints (#15189)
1 parent 28a33ff commit 97361ad

39 files changed

+257
-43
lines changed

ci/generate-markdown/update-library-landing-dox.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ while IFS= read -r -d $'\0' option_defaults_cc; do
6464
variable=$(grep -om1 "${variable_re}" "${option_defaults_cc}")
6565
endpoint_re='"[^"]*?\.googleapis\.com"'
6666
endpoint=$(grep -Pom1 "${endpoint_re}" "${option_defaults_cc}")
67-
if grep -q 'location,' "${option_defaults_cc}"; then
68-
endpoint="\"<location>-${endpoint:1:-1}\""
67+
if ! grep -q 'optional location tag' "${option_defaults_cc}"; then
68+
if grep -q 'location,' "${option_defaults_cc}"; then
69+
endpoint="\"<location>-${endpoint:1:-1}\""
70+
fi
6971
fi
7072
make_connection_re='Make.*?Connection()'
7173
make_connection=$(grep -Pom1 "${make_connection_re}" "${connection_h}")

generator/generator_config.textproto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,6 +3302,7 @@ service {
33023302
forwarding_product_path: "google/cloud/resourcemanager"
33033303
initial_copyright_year: "2022"
33043304
retryable_status_codes: ["kUnavailable"]
3305+
endpoint_location_style: LOCATION_OPTIONALLY_DEPENDENT
33053306
}
33063307
33073308
service {
@@ -3310,6 +3311,7 @@ service {
33103311
forwarding_product_path: "google/cloud/resourcemanager"
33113312
initial_copyright_year: "2022"
33123313
retryable_status_codes: ["kUnavailable"]
3314+
endpoint_location_style: LOCATION_OPTIONALLY_DEPENDENT
33133315
}
33143316
33153317
service {
@@ -3318,34 +3320,39 @@ service {
33183320
forwarding_product_path: "google/cloud/resourcemanager"
33193321
initial_copyright_year: "2022"
33203322
retryable_status_codes: ["kUnavailable"]
3323+
endpoint_location_style: LOCATION_OPTIONALLY_DEPENDENT
33213324
}
33223325
33233326
service {
33243327
service_proto_path: "google/cloud/resourcemanager/v3/tag_bindings.proto"
33253328
product_path: "google/cloud/resourcemanager/v3"
33263329
initial_copyright_year: "2023"
33273330
retryable_status_codes: ["kUnavailable"]
3331+
endpoint_location_style: LOCATION_OPTIONALLY_DEPENDENT
33283332
}
33293333
33303334
service {
33313335
service_proto_path: "google/cloud/resourcemanager/v3/tag_holds.proto"
33323336
product_path: "google/cloud/resourcemanager/v3"
33333337
initial_copyright_year: "2023"
33343338
retryable_status_codes: ["kUnavailable"]
3339+
endpoint_location_style: LOCATION_OPTIONALLY_DEPENDENT
33353340
}
33363341
33373342
service {
33383343
service_proto_path: "google/cloud/resourcemanager/v3/tag_keys.proto"
33393344
product_path: "google/cloud/resourcemanager/v3"
33403345
initial_copyright_year: "2023"
33413346
retryable_status_codes: ["kUnavailable"]
3347+
endpoint_location_style: LOCATION_OPTIONALLY_DEPENDENT
33423348
}
33433349
33443350
service {
33453351
service_proto_path: "google/cloud/resourcemanager/v3/tag_values.proto"
33463352
product_path: "google/cloud/resourcemanager/v3"
33473353
initial_copyright_year: "2023"
33483354
retryable_status_codes: ["kUnavailable"]
3355+
endpoint_location_style: LOCATION_OPTIONALLY_DEPENDENT
33493356
}
33503357
33513358
# Retail

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Options GoldenRestOnlyDefaultOptions(std::string const& location, Options option
3838
options = internal::PopulateCommonOptions(
3939
std::move(options), "GOOGLE_CLOUD_CPP_GOLDEN_REST_ONLY_ENDPOINT",
4040
"", "GOOGLE_CLOUD_CPP_GOLDEN_REST_ONLY_AUTHORITY",
41+
// optional location tag for generating docs
4142
absl::StrCat(location, location.empty() ? "" : "-", "goldenrestonly.googleapis.com"));
4243
options = internal::PopulateGrpcOptions(std::move(options));
4344
if (!options.has<golden_v1::GoldenRestOnlyRetryPolicyOption>()) {

generator/internal/option_defaults_generator.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,15 @@ auto constexpr kBackoffScaling = 2.0;
141141
R"""( absl::StrCat(location, "-", "$service_endpoint$"));)""");
142142
break;
143143
case ServiceConfiguration::LOCATION_DEPENDENT_COMPAT:
144-
case ServiceConfiguration::LOCATION_OPTIONALLY_DEPENDENT:
145144
CcPrint(R"""( absl::StrCat(location, )"""
146145
R"""(location.empty() ? "" : "-", "$service_endpoint$"));)""");
147146
break;
147+
case ServiceConfiguration::LOCATION_OPTIONALLY_DEPENDENT:
148+
CcPrint(R"""( // optional location tag for generating docs
149+
)"""
150+
R"""( absl::StrCat(location, )"""
151+
R"""(location.empty() ? "" : "-", "$service_endpoint$"));)""");
152+
break;
148153
default:
149154
CcPrint(R"""( "$service_endpoint$");)""");
150155
break;

google/cloud/resourcemanager/v3/folders_connection.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ StatusOr<google::longrunning::Operation> FoldersConnection::GetOperation(
190190
return Status(StatusCode::kUnimplemented, "not implemented");
191191
}
192192

193-
std::shared_ptr<FoldersConnection> MakeFoldersConnection(Options options) {
193+
std::shared_ptr<FoldersConnection> MakeFoldersConnection(
194+
std::string const& location, Options options) {
194195
internal::CheckExpectedOptions<CommonOptionList, GrpcOptionList,
195196
UnifiedCredentialsOptionList,
196197
FoldersPolicyOptionList>(options, __func__);
197-
options =
198-
resourcemanager_v3_internal::FoldersDefaultOptions(std::move(options));
198+
options = resourcemanager_v3_internal::FoldersDefaultOptions(
199+
location, std::move(options));
199200
auto background = internal::MakeBackgroundThreadsFactory(options)();
200201
auto auth = internal::CreateAuthenticationStrategy(background->cq(), options);
201202
auto stub = resourcemanager_v3_internal::CreateDefaultFoldersStub(
@@ -205,6 +206,10 @@ std::shared_ptr<FoldersConnection> MakeFoldersConnection(Options options) {
205206
std::move(background), std::move(stub), std::move(options)));
206207
}
207208

209+
std::shared_ptr<FoldersConnection> MakeFoldersConnection(Options options) {
210+
return MakeFoldersConnection(std::string{}, std::move(options));
211+
}
212+
208213
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
209214
} // namespace resourcemanager_v3
210215
} // namespace cloud

google/cloud/resourcemanager/v3/folders_connection.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <google/cloud/resourcemanager/v3/folders.pb.h>
3434
#include <google/longrunning/operations.grpc.pb.h>
3535
#include <memory>
36+
#include <string>
3637

3738
namespace google {
3839
namespace cloud {
@@ -278,9 +279,19 @@ class FoldersConnection {
278279
* @note Unexpected options will be ignored. To log unexpected options instead,
279280
* set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment.
280281
*
282+
* @param location Sets the prefix for the default `EndpointOption` value.
281283
* @param options (optional) Configure the `FoldersConnection` created by
282284
* this function.
283285
*/
286+
std::shared_ptr<FoldersConnection> MakeFoldersConnection(
287+
std::string const& location, Options options = {});
288+
289+
/**
290+
* A factory function to construct an object of type `FoldersConnection`.
291+
*
292+
* This overload of `MakeFoldersConnection` does not require a location
293+
* argument, creating a connection to the global service endpoint.
294+
*/
284295
std::shared_ptr<FoldersConnection> MakeFoldersConnection(Options options = {});
285296

286297
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/resourcemanager/v3/internal/folders_option_defaults.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "google/cloud/resourcemanager/v3/internal/folders_option_defaults.h"
2020
#include "google/cloud/resourcemanager/v3/folders_connection.h"
2121
#include "google/cloud/resourcemanager/v3/folders_options.h"
22+
#include "google/cloud/internal/absl_str_cat_quiet.h"
2223
#include "google/cloud/internal/populate_common_options.h"
2324
#include "google/cloud/internal/populate_grpc_options.h"
2425
#include <memory>
@@ -33,11 +34,13 @@ namespace {
3334
auto constexpr kBackoffScaling = 2.0;
3435
} // namespace
3536

36-
Options FoldersDefaultOptions(Options options) {
37+
Options FoldersDefaultOptions(std::string const& location, Options options) {
3738
options = internal::PopulateCommonOptions(
3839
std::move(options), "GOOGLE_CLOUD_CPP_FOLDERS_ENDPOINT", "",
3940
"GOOGLE_CLOUD_CPP_FOLDERS_AUTHORITY",
40-
"cloudresourcemanager.googleapis.com");
41+
// optional location tag for generating docs
42+
absl::StrCat(location, location.empty() ? "" : "-",
43+
"cloudresourcemanager.googleapis.com"));
4144
options = internal::PopulateGrpcOptions(std::move(options));
4245
if (!options.has<resourcemanager_v3::FoldersRetryPolicyOption>()) {
4346
options.set<resourcemanager_v3::FoldersRetryPolicyOption>(

google/cloud/resourcemanager/v3/internal/folders_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 resourcemanager_v3_internal {
2829
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2930

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

3233
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
3334
} // namespace resourcemanager_v3_internal

google/cloud/resourcemanager/v3/internal/organizations_option_defaults.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "google/cloud/resourcemanager/v3/internal/organizations_option_defaults.h"
2020
#include "google/cloud/resourcemanager/v3/organizations_connection.h"
2121
#include "google/cloud/resourcemanager/v3/organizations_options.h"
22+
#include "google/cloud/internal/absl_str_cat_quiet.h"
2223
#include "google/cloud/internal/populate_common_options.h"
2324
#include "google/cloud/internal/populate_grpc_options.h"
2425
#include <memory>
@@ -33,11 +34,14 @@ namespace {
3334
auto constexpr kBackoffScaling = 2.0;
3435
} // namespace
3536

36-
Options OrganizationsDefaultOptions(Options options) {
37+
Options OrganizationsDefaultOptions(std::string const& location,
38+
Options options) {
3739
options = internal::PopulateCommonOptions(
3840
std::move(options), "GOOGLE_CLOUD_CPP_ORGANIZATIONS_ENDPOINT", "",
3941
"GOOGLE_CLOUD_CPP_ORGANIZATIONS_AUTHORITY",
40-
"cloudresourcemanager.googleapis.com");
42+
// optional location tag for generating docs
43+
absl::StrCat(location, location.empty() ? "" : "-",
44+
"cloudresourcemanager.googleapis.com"));
4145
options = internal::PopulateGrpcOptions(std::move(options));
4246
if (!options.has<resourcemanager_v3::OrganizationsRetryPolicyOption>()) {
4347
options.set<resourcemanager_v3::OrganizationsRetryPolicyOption>(

google/cloud/resourcemanager/v3/internal/organizations_option_defaults.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
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 resourcemanager_v3_internal {
2829
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2930

30-
Options OrganizationsDefaultOptions(Options options);
31+
Options OrganizationsDefaultOptions(std::string const& location,
32+
Options options);
3133

3234
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
3335
} // namespace resourcemanager_v3_internal

0 commit comments

Comments
 (0)