19 #include "google/cloud/iam/iam_connection.h"
20 #include "google/cloud/iam/iam_options.h"
21 #include "google/cloud/iam/internal/iam_option_defaults.h"
22 #include "google/cloud/iam/internal/iam_stub_factory.h"
23 #include "google/cloud/background_threads.h"
24 #include "google/cloud/grpc_options.h"
25 #include "google/cloud/internal/pagination_range.h"
26 #include "google/cloud/internal/retry_loop.h"
36 StreamRange<
google::iam::admin::v1::ServiceAccount>
38 google::iam::admin::v1::ListServiceAccountsRequest request) {
39 return google::
cloud::internal::MakePaginationRange<
40 StreamRange<
google::iam::admin::v1::ServiceAccount>>(
42 [](
google::iam::admin::v1::ListServiceAccountsRequest
const&) {
45 [](
google::iam::admin::v1::ListServiceAccountsResponse
const&) {
46 return std::vector<
google::iam::admin::v1::ServiceAccount>();
50 StatusOr<
google::iam::admin::v1::ServiceAccount>
52 google::iam::admin::v1::GetServiceAccountRequest
const&) {
56 StatusOr<
google::iam::admin::v1::ServiceAccount>
58 google::iam::admin::v1::CreateServiceAccountRequest
const&) {
62 StatusOr<
google::iam::admin::v1::ServiceAccount>
64 google::iam::admin::v1::PatchServiceAccountRequest
const&) {
69 google::iam::admin::v1::DeleteServiceAccountRequest
const&) {
73 StatusOr<
google::iam::admin::v1::UndeleteServiceAccountResponse>
75 google::iam::admin::v1::UndeleteServiceAccountRequest
const&) {
80 google::iam::admin::v1::EnableServiceAccountRequest
const&) {
85 google::iam::admin::v1::DisableServiceAccountRequest
const&) {
89 StatusOr<
google::iam::admin::v1::ListServiceAccountKeysResponse>
91 google::iam::admin::v1::ListServiceAccountKeysRequest
const&) {
95 StatusOr<
google::iam::admin::v1::ServiceAccountKey>
97 google::iam::admin::v1::GetServiceAccountKeyRequest
const&) {
101 StatusOr<
google::iam::admin::v1::ServiceAccountKey>
103 google::iam::admin::v1::CreateServiceAccountKeyRequest
const&) {
107 StatusOr<
google::iam::admin::v1::ServiceAccountKey>
109 google::iam::admin::v1::UploadServiceAccountKeyRequest
const&) {
114 google::iam::admin::v1::DeleteServiceAccountKeyRequest
const&) {
119 google::iam::v1::GetIamPolicyRequest
const&) {
124 google::iam::v1::SetIamPolicyRequest
const&) {
128 StatusOr<
google::iam::v1::TestIamPermissionsResponse>
130 google::iam::v1::TestIamPermissionsRequest
const&) {
135 google::iam::admin::v1::QueryGrantableRolesRequest request) {
136 return google::
cloud::internal::MakePaginationRange<
137 StreamRange<
google::iam::admin::v1::Role>>(
139 [](
google::iam::admin::v1::QueryGrantableRolesRequest
const&) {
142 [](
google::iam::admin::v1::QueryGrantableRolesResponse
const&) {
143 return std::vector<
google::iam::admin::v1::Role>();
148 google::iam::admin::v1::ListRolesRequest request) {
149 return google::
cloud::internal::MakePaginationRange<
150 StreamRange<
google::iam::admin::v1::Role>>(
152 [](
google::iam::admin::v1::ListRolesRequest
const&) {
155 [](
google::iam::admin::v1::ListRolesResponse
const&) {
156 return std::vector<
google::iam::admin::v1::Role>();
161 google::iam::admin::v1::GetRoleRequest
const&) {
166 google::iam::admin::v1::CreateRoleRequest
const&) {
171 google::iam::admin::v1::UpdateRoleRequest
const&) {
176 google::iam::admin::v1::DeleteRoleRequest
const&) {
181 google::iam::admin::v1::UndeleteRoleRequest
const&) {
185 StreamRange<
google::iam::admin::v1::Permission>
187 google::iam::admin::v1::QueryTestablePermissionsRequest request) {
188 return google::
cloud::internal::MakePaginationRange<
189 StreamRange<
google::iam::admin::v1::Permission>>(
191 [](
google::iam::admin::v1::QueryTestablePermissionsRequest
const&) {
195 [](
google::iam::admin::v1::QueryTestablePermissionsResponse
const&) {
196 return std::vector<
google::iam::admin::v1::Permission>();
200 StatusOr<
google::iam::admin::v1::QueryAuditableServicesResponse>
202 google::iam::admin::v1::QueryAuditableServicesRequest
const&) {
207 google::iam::admin::v1::LintPolicyRequest
const&) {
216 std::shared_ptr<iam_internal::IAMStub> stub,
Options const& options)
217 : background_(std::move(background)),
218 stub_(std::move(stub)),
220 backoff_policy_prototype_(
225 ~IAMConnectionImpl()
override =
default;
227 StreamRange<
google::iam::admin::v1::ServiceAccount> ListServiceAccounts(
228 google::iam::admin::v1::ListServiceAccountsRequest request)
override {
229 request.clear_page_token();
232 std::shared_ptr<IAMRetryPolicy
const>(retry_policy_prototype_->clone());
233 auto backoff = std::shared_ptr<BackoffPolicy
const>(
234 backoff_policy_prototype_->clone());
236 char const* function_name =
__func__;
237 return google::
cloud::internal::MakePaginationRange<
238 StreamRange<
google::iam::admin::v1::ServiceAccount>>(
240 [stub, retry, backoff, idempotency, function_name](
241 google::iam::admin::v1::ListServiceAccountsRequest
const& r) {
243 retry->clone(), backoff->clone(), idempotency,
244 [stub](grpc::ClientContext& context,
245 google::iam::admin::v1::ListServiceAccountsRequest
const&
247 return stub->ListServiceAccounts(context, request);
251 [](
google::iam::admin::v1::ListServiceAccountsResponse r) {
252 std::vector<
google::iam::admin::v1::ServiceAccount> result(
253 r.accounts().size());
254 auto& messages = *r.mutable_accounts();
255 std::move(messages.begin(), messages.end(), result.begin());
260 StatusOr<
google::iam::admin::v1::ServiceAccount> GetServiceAccount(
261 google::iam::admin::v1::GetServiceAccountRequest
const& request)
264 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
267 grpc::ClientContext& context,
268 google::iam::admin::v1::GetServiceAccountRequest
const& request) {
269 return stub_->GetServiceAccount(context, request);
274 StatusOr<
google::iam::admin::v1::ServiceAccount> CreateServiceAccount(
275 google::iam::admin::v1::CreateServiceAccountRequest
const& request)
278 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
280 [
this](grpc::ClientContext& context,
281 google::iam::admin::v1::CreateServiceAccountRequest
const&
283 return stub_->CreateServiceAccount(context, request);
288 StatusOr<
google::iam::admin::v1::ServiceAccount> PatchServiceAccount(
289 google::iam::admin::v1::PatchServiceAccountRequest
const& request)
292 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
295 grpc::ClientContext& context,
296 google::iam::admin::v1::PatchServiceAccountRequest
const& request) {
297 return stub_->PatchServiceAccount(context, request);
302 Status DeleteServiceAccount(
303 google::iam::admin::v1::DeleteServiceAccountRequest
const& request)
306 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
308 [
this](grpc::ClientContext& context,
309 google::iam::admin::v1::DeleteServiceAccountRequest
const&
311 return stub_->DeleteServiceAccount(context, request);
316 StatusOr<
google::iam::admin::v1::UndeleteServiceAccountResponse>
317 UndeleteServiceAccount(
318 google::iam::admin::v1::UndeleteServiceAccountRequest
const& request)
321 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
323 [
this](grpc::ClientContext& context,
324 google::iam::admin::v1::UndeleteServiceAccountRequest
const&
326 return stub_->UndeleteServiceAccount(context, request);
331 Status EnableServiceAccount(
332 google::iam::admin::v1::EnableServiceAccountRequest
const& request)
335 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
337 [
this](grpc::ClientContext& context,
338 google::iam::admin::v1::EnableServiceAccountRequest
const&
340 return stub_->EnableServiceAccount(context, request);
345 Status DisableServiceAccount(
346 google::iam::admin::v1::DisableServiceAccountRequest
const& request)
349 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
351 [
this](grpc::ClientContext& context,
352 google::iam::admin::v1::DisableServiceAccountRequest
const&
354 return stub_->DisableServiceAccount(context, request);
359 StatusOr<
google::iam::admin::v1::ListServiceAccountKeysResponse>
360 ListServiceAccountKeys(
361 google::iam::admin::v1::ListServiceAccountKeysRequest
const& request)
364 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
366 [
this](grpc::ClientContext& context,
367 google::iam::admin::v1::ListServiceAccountKeysRequest
const&
369 return stub_->ListServiceAccountKeys(context, request);
374 StatusOr<
google::iam::admin::v1::ServiceAccountKey> GetServiceAccountKey(
375 google::iam::admin::v1::GetServiceAccountKeyRequest
const& request)
378 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
380 [
this](grpc::ClientContext& context,
381 google::iam::admin::v1::GetServiceAccountKeyRequest
const&
383 return stub_->GetServiceAccountKey(context, request);
388 StatusOr<
google::iam::admin::v1::ServiceAccountKey> CreateServiceAccountKey(
389 google::iam::admin::v1::CreateServiceAccountKeyRequest
const& request)
392 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
394 [
this](grpc::ClientContext& context,
395 google::iam::admin::v1::CreateServiceAccountKeyRequest
const&
397 return stub_->CreateServiceAccountKey(context, request);
402 StatusOr<
google::iam::admin::v1::ServiceAccountKey> UploadServiceAccountKey(
403 google::iam::admin::v1::UploadServiceAccountKeyRequest
const& request)
406 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
408 [
this](grpc::ClientContext& context,
409 google::iam::admin::v1::UploadServiceAccountKeyRequest
const&
411 return stub_->UploadServiceAccountKey(context, request);
416 Status DeleteServiceAccountKey(
417 google::iam::admin::v1::DeleteServiceAccountKeyRequest
const& request)
420 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
422 [
this](grpc::ClientContext& context,
423 google::iam::admin::v1::DeleteServiceAccountKeyRequest
const&
425 return stub_->DeleteServiceAccountKey(context, request);
430 StatusOr<
google::iam::v1::Policy> GetIamPolicy(
431 google::iam::v1::GetIamPolicyRequest
const& request)
override {
433 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
435 [
this](grpc::ClientContext& context,
436 google::iam::v1::GetIamPolicyRequest
const& request) {
437 return stub_->GetIamPolicy(context, request);
442 StatusOr<
google::iam::v1::Policy> SetIamPolicy(
443 google::iam::v1::SetIamPolicyRequest
const& request)
override {
445 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
447 [
this](grpc::ClientContext& context,
448 google::iam::v1::SetIamPolicyRequest
const& request) {
449 return stub_->SetIamPolicy(context, request);
454 StatusOr<
google::iam::v1::TestIamPermissionsResponse> TestIamPermissions(
455 google::iam::v1::TestIamPermissionsRequest
const& request)
override {
457 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
459 [
this](grpc::ClientContext& context,
460 google::iam::v1::TestIamPermissionsRequest
const& request) {
461 return stub_->TestIamPermissions(context, request);
466 StreamRange<
google::iam::admin::v1::Role> QueryGrantableRoles(
467 google::iam::admin::v1::QueryGrantableRolesRequest request)
override {
468 request.clear_page_token();
471 std::shared_ptr<IAMRetryPolicy
const>(retry_policy_prototype_->clone());
472 auto backoff = std::shared_ptr<BackoffPolicy
const>(
473 backoff_policy_prototype_->clone());
475 char const* function_name =
__func__;
476 return google::
cloud::internal::MakePaginationRange<
477 StreamRange<
google::iam::admin::v1::Role>>(
479 [stub, retry, backoff, idempotency, function_name](
480 google::iam::admin::v1::QueryGrantableRolesRequest
const& r) {
482 retry->clone(), backoff->clone(), idempotency,
483 [stub](grpc::ClientContext& context,
484 google::iam::admin::v1::QueryGrantableRolesRequest
const&
486 return stub->QueryGrantableRoles(context, request);
490 [](
google::iam::admin::v1::QueryGrantableRolesResponse r) {
491 std::vector<
google::iam::admin::v1::Role> result(r.roles().size());
492 auto& messages = *r.mutable_roles();
493 std::move(messages.begin(), messages.end(), result.begin());
498 StreamRange<
google::iam::admin::v1::Role> ListRoles(
499 google::iam::admin::v1::ListRolesRequest request)
override {
500 request.clear_page_token();
503 std::shared_ptr<IAMRetryPolicy
const>(retry_policy_prototype_->clone());
504 auto backoff = std::shared_ptr<BackoffPolicy
const>(
505 backoff_policy_prototype_->clone());
506 auto idempotency = idempotency_policy_->
ListRoles(request
);
507 char const* function_name =
__func__;
508 return google::
cloud::internal::MakePaginationRange<
509 StreamRange<
google::iam::admin::v1::Role>>(
511 [stub, retry, backoff, idempotency,
512 function_name](
google::iam::admin::v1::ListRolesRequest
const& r) {
514 retry->clone(), backoff->clone(), idempotency,
515 [stub](grpc::ClientContext& context,
516 google::iam::admin::v1::ListRolesRequest
const& request) {
517 return stub->ListRoles(context, request);
521 [](
google::iam::admin::v1::ListRolesResponse r) {
522 std::vector<
google::iam::admin::v1::Role> result(r.roles().size());
523 auto& messages = *r.mutable_roles();
524 std::move(messages.begin(), messages.end(), result.begin());
529 StatusOr<
google::iam::admin::v1::Role> GetRole(
530 google::iam::admin::v1::GetRoleRequest
const& request)
override {
532 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
534 [
this](grpc::ClientContext& context,
535 google::iam::admin::v1::GetRoleRequest
const& request) {
536 return stub_->GetRole(context, request);
541 StatusOr<
google::iam::admin::v1::Role> CreateRole(
542 google::iam::admin::v1::CreateRoleRequest
const& request)
override {
544 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
546 [
this](grpc::ClientContext& context,
547 google::iam::admin::v1::CreateRoleRequest
const& request) {
548 return stub_->CreateRole(context, request);
553 StatusOr<
google::iam::admin::v1::Role> UpdateRole(
554 google::iam::admin::v1::UpdateRoleRequest
const& request)
override {
556 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
558 [
this](grpc::ClientContext& context,
559 google::iam::admin::v1::UpdateRoleRequest
const& request) {
560 return stub_->UpdateRole(context, request);
565 StatusOr<
google::iam::admin::v1::Role> DeleteRole(
566 google::iam::admin::v1::DeleteRoleRequest
const& request)
override {
568 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
570 [
this](grpc::ClientContext& context,
571 google::iam::admin::v1::DeleteRoleRequest
const& request) {
572 return stub_->DeleteRole(context, request);
577 StatusOr<
google::iam::admin::v1::Role> UndeleteRole(
578 google::iam::admin::v1::UndeleteRoleRequest
const& request)
override {
580 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
582 [
this](grpc::ClientContext& context,
583 google::iam::admin::v1::UndeleteRoleRequest
const& request) {
584 return stub_->UndeleteRole(context, request);
589 StreamRange<
google::iam::admin::v1::Permission> QueryTestablePermissions(
590 google::iam::admin::v1::QueryTestablePermissionsRequest request)
592 request.clear_page_token();
595 std::shared_ptr<IAMRetryPolicy
const>(retry_policy_prototype_->clone());
596 auto backoff = std::shared_ptr<BackoffPolicy
const>(
597 backoff_policy_prototype_->clone());
599 char const* function_name =
__func__;
600 return google::
cloud::internal::MakePaginationRange<
601 StreamRange<
google::iam::admin::v1::Permission>>(
603 [stub, retry, backoff, idempotency, function_name](
604 google::iam::admin::v1::QueryTestablePermissionsRequest
const& r) {
606 retry->clone(), backoff->clone(), idempotency,
608 grpc::ClientContext& context,
609 google::iam::admin::v1::QueryTestablePermissionsRequest
const&
611 return stub->QueryTestablePermissions(context, request);
615 [](
google::iam::admin::v1::QueryTestablePermissionsResponse r) {
616 std::vector<
google::iam::admin::v1::Permission> result(
617 r.permissions().size());
618 auto& messages = *r.mutable_permissions();
619 std::move(messages.begin(), messages.end(), result.begin());
624 StatusOr<
google::iam::admin::v1::QueryAuditableServicesResponse>
625 QueryAuditableServices(
626 google::iam::admin::v1::QueryAuditableServicesRequest
const& request)
629 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
631 [
this](grpc::ClientContext& context,
632 google::iam::admin::v1::QueryAuditableServicesRequest
const&
634 return stub_->QueryAuditableServices(context, request);
639 StatusOr<
google::iam::admin::v1::LintPolicyResponse> LintPolicy(
640 google::iam::admin::v1::LintPolicyRequest
const& request)
override {
642 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
644 [
this](grpc::ClientContext& context,
645 google::iam::admin::v1::LintPolicyRequest
const& request) {
646 return stub_->LintPolicy(context, request);
653 std::shared_ptr<iam_internal::IAMStub> stub_;
654 std::unique_ptr<IAMRetryPolicy
const> retry_policy_prototype_;
655 std::unique_ptr<BackoffPolicy
const> backoff_policy_prototype_;
661 options
= iam_internal::IAMDefaultOptions(std::move(options));
662 auto background = internal::MakeBackgroundThreadsFactory(options)();
663 auto stub = iam_internal::CreateDefaultIAMStub(background->
cq(), options);
664 return std::make_shared<IAMConnectionImpl>(std::move(background),
665 std::move(stub), options);
675 namespace iam_internal {
679 std::shared_ptr<IAMStub> stub,
Options options) {
680 options
= IAMDefaultOptions(std::move(options));
681 return std::make_shared<
iam::IAMConnectionImpl>(
682 internal::MakeBackgroundThreadsFactory(options)(), std::move(stub),