Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
instance_admin_client.cc
Go to the documentation of this file.
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Generated by the Codegen C++ plugin.
16 // If you make any local changes, they will be lost.
17 // source: google/spanner/admin/instance/v1/spanner_instance_admin.proto
18 
19 #include "google/cloud/spanner/admin/instance_admin_client.h"
20 #include "google/cloud/spanner/admin/instance_admin_options.h"
21 #include "google/cloud/spanner/admin/internal/instance_admin_option_defaults.h"
22 #include <memory>
23 #include <thread>
24 
25 namespace google {
26 namespace cloud {
27 namespace spanner_admin {
28 inline namespace GOOGLE_CLOUD_CPP_GENERATED_NS {
29 
31  std::shared_ptr<InstanceAdminConnection> connection)
32  : connection_(std::move(connection)) {}
34 
35 StreamRange<google::spanner::admin::instance::v1::InstanceConfig>
36 InstanceAdminClient::ListInstanceConfigs(std::string const& parent) {
37  google::spanner::admin::instance::v1::ListInstanceConfigsRequest request;
38  request.set_parent(parent);
39  return connection_->ListInstanceConfigs(request);
40 }
41 
42 StatusOr<google::spanner::admin::instance::v1::InstanceConfig>
43 InstanceAdminClient::GetInstanceConfig(std::string const& name) {
44  google::spanner::admin::instance::v1::GetInstanceConfigRequest request;
45  request.set_name(name);
46  return connection_->GetInstanceConfig(request);
47 }
48 
49 StreamRange<google::spanner::admin::instance::v1::Instance>
50 InstanceAdminClient::ListInstances(std::string const& parent) {
51  google::spanner::admin::instance::v1::ListInstancesRequest request;
52  request.set_parent(parent);
53  return connection_->ListInstances(request);
54 }
55 
56 StatusOr<google::spanner::admin::instance::v1::Instance>
57 InstanceAdminClient::GetInstance(std::string const& name) {
58  google::spanner::admin::instance::v1::GetInstanceRequest request;
59  request.set_name(name);
60  return connection_->GetInstance(request);
61 }
62 
63 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
65  std::string const& parent, std::string const& instance_id,
66  google::spanner::admin::instance::v1::Instance const& instance) {
67  google::spanner::admin::instance::v1::CreateInstanceRequest request;
68  request.set_parent(parent);
69  request.set_instance_id(instance_id);
70  *request.mutable_instance() = instance;
71  return connection_->CreateInstance(request);
72 }
73 
74 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
76  google::spanner::admin::instance::v1::Instance const& instance,
77  google::protobuf::FieldMask const& field_mask) {
78  google::spanner::admin::instance::v1::UpdateInstanceRequest request;
79  *request.mutable_instance() = instance;
80  *request.mutable_field_mask() = field_mask;
81  return connection_->UpdateInstance(request);
82 }
83 
84 Status InstanceAdminClient::DeleteInstance(std::string const& name) {
85  google::spanner::admin::instance::v1::DeleteInstanceRequest request;
86  request.set_name(name);
87  return connection_->DeleteInstance(request);
88 }
89 
90 StatusOr<google::iam::v1::Policy> InstanceAdminClient::SetIamPolicy(
91  std::string const& resource, google::iam::v1::Policy const& policy) {
92  google::iam::v1::SetIamPolicyRequest request;
93  request.set_resource(resource);
94  *request.mutable_policy() = policy;
95  return connection_->SetIamPolicy(request);
96 }
97 
98 StatusOr<google::iam::v1::Policy> InstanceAdminClient::SetIamPolicy(
99  std::string const& resource, IamUpdater const& updater, Options options) {
100  internal::CheckExpectedOptions<InstanceAdminBackoffPolicyOption>(options,
101  __func__);
102  options =
104  auto backoff_policy =
106  for (;;) {
107  auto recent = GetIamPolicy(resource);
108  if (!recent) {
109  return recent.status();
110  }
111  auto policy = updater(*std::move(recent));
112  if (!policy) {
113  return Status(StatusCode::kCancelled, "updater did not yield a policy");
114  }
115  auto result = SetIamPolicy(resource, *std::move(policy));
116  if (result || result.status().code() != StatusCode::kAborted) {
117  return result;
118  }
119  std::this_thread::sleep_for(backoff_policy->OnCompletion());
120  }
121 }
122 
123 StatusOr<google::iam::v1::Policy> InstanceAdminClient::GetIamPolicy(
124  std::string const& resource) {
125  google::iam::v1::GetIamPolicyRequest request;
126  request.set_resource(resource);
127  return connection_->GetIamPolicy(request);
128 }
129 
130 StatusOr<google::iam::v1::TestIamPermissionsResponse>
132  std::string const& resource, std::vector<std::string> const& permissions) {
133  google::iam::v1::TestIamPermissionsRequest request;
134  request.set_resource(resource);
135  *request.mutable_permissions() = {permissions.begin(), permissions.end()};
136  return connection_->TestIamPermissions(request);
137 }
138 
139 StreamRange<google::spanner::admin::instance::v1::InstanceConfig>
141  google::spanner::admin::instance::v1::ListInstanceConfigsRequest request) {
142  return connection_->ListInstanceConfigs(std::move(request));
143 }
144 
145 StatusOr<google::spanner::admin::instance::v1::InstanceConfig>
147  google::spanner::admin::instance::v1::GetInstanceConfigRequest const&
148  request) {
149  return connection_->GetInstanceConfig(request);
150 }
151 
152 StreamRange<google::spanner::admin::instance::v1::Instance>
154  google::spanner::admin::instance::v1::ListInstancesRequest request) {
155  return connection_->ListInstances(std::move(request));
156 }
157 
158 StatusOr<google::spanner::admin::instance::v1::Instance>
160  google::spanner::admin::instance::v1::GetInstanceRequest const& request) {
161  return connection_->GetInstance(request);
162 }
163 
164 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
166  google::spanner::admin::instance::v1::CreateInstanceRequest const&
167  request) {
168  return connection_->CreateInstance(request);
169 }
170 
171 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
173  google::spanner::admin::instance::v1::UpdateInstanceRequest const&
174  request) {
175  return connection_->UpdateInstance(request);
176 }
177 
179  google::spanner::admin::instance::v1::DeleteInstanceRequest const&
180  request) {
181  return connection_->DeleteInstance(request);
182 }
183 
184 StatusOr<google::iam::v1::Policy> InstanceAdminClient::SetIamPolicy(
185  google::iam::v1::SetIamPolicyRequest const& request) {
186  return connection_->SetIamPolicy(request);
187 }
188 
189 StatusOr<google::iam::v1::Policy> InstanceAdminClient::GetIamPolicy(
190  google::iam::v1::GetIamPolicyRequest const& request) {
191  return connection_->GetIamPolicy(request);
192 }
193 
194 StatusOr<google::iam::v1::TestIamPermissionsResponse>
196  google::iam::v1::TestIamPermissionsRequest const& request) {
197  return connection_->TestIamPermissions(request);
198 }
199 
200 } // namespace GOOGLE_CLOUD_CPP_GENERATED_NS
201 } // namespace spanner_admin
202 } // namespace cloud
203 } // namespace google