Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
instance_admin_client.h
1// Copyright 2019 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#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INSTANCE_ADMIN_CLIENT_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INSTANCE_ADMIN_CLIENT_H
17
18#include "google/cloud/spanner/iam_updater.h"
19#include "google/cloud/spanner/instance.h"
20#include "google/cloud/spanner/instance_admin_connection.h"
21#include "google/cloud/spanner/version.h"
22#include "google/cloud/status_or.h"
23#include <string>
24#include <vector>
25
26namespace google {
27namespace cloud {
28namespace spanner {
29GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
30
31/**
32 * Performs instance administration operations on Cloud Spanner.
33 *
34 * @deprecated Please use #google::cloud::spanner_admin::InstanceAdminClient
35 * instead.
36 *
37 * Applications use this class to perform operations on
38 * [Spanner Databases][spanner-doc-link].
39 *
40 * @par Performance
41 *
42 * `InstanceAdminClient` objects are cheap to create, copy, and move. However,
43 * each `InstanceAdminClient` object must be created with a
44 * `std::shared_ptr<InstanceAdminConnection>`, which itself is relatively
45 * expensive to create. Therefore, connection instances should be shared when
46 * possible. See the `MakeInstanceAdminConnection()` method and the
47 * `InstanceAdminConnection` interface for more details.
48 *
49 * @par Thread Safety
50 *
51 * Instances of this class created via copy-construction or copy-assignment
52 * share the underlying pool of connections. Access to these copies via multiple
53 * threads is guaranteed to work. Two threads operating on the same instance of
54 * this class is not guaranteed to work.
55 *
56 * @par Error Handling
57 *
58 * This class uses `StatusOr<T>` to report errors. When an operation fails to
59 * perform its work the returned `StatusOr<T>` contains the error details. If
60 * the `ok()` member function in the `StatusOr<T>` returns `true` then it
61 * contains the expected result. For more information, see the
62 * [Error Handling Guide](#spanner-error-handling).
63 *
64 * [spanner-doc-link]:
65 * https://cloud.google.com/spanner/docs/api-libraries-overview
66 */
67class GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("InstanceAdminClient")
69 public:
70 explicit InstanceAdminClient(std::shared_ptr<InstanceAdminConnection> conn)
71 : conn_(std::move(conn)) {}
72
73 /// No default construction.
74 /// Use `InstanceAdminClient(std::shared_ptr<InstanceAdminConnection>)`
75 InstanceAdminClient() = delete;
76
77 ///@{
78 /// @name Copy and move support
83 ///@}
84
85 ///@{
86 /// @name Equality
87 friend bool operator==(InstanceAdminClient const& a,
88 InstanceAdminClient const& b) {
89 return a.conn_ == b.conn_;
90 }
91 friend bool operator!=(InstanceAdminClient const& a,
92 InstanceAdminClient const& b) {
93 return !(a == b);
94 }
95 ///@}
96
97 /**
98 * Retrieve metadata information about a Cloud Spanner Instance.
99 *
100 * @par Idempotency
101 * This is a read-only operation and therefore it is always treated as
102 * idempotent.
103 *
104 * @par Example
105 * @snippet samples.cc get-instance
106 */
107 StatusOr<google::spanner::admin::instance::v1::Instance> GetInstance(
108 Instance const& in);
109
110 /**
111 * Creates a new Cloud Spanner instance in the given project.
112 *
113 * Use CreateInstanceRequestBuilder to build the
114 * `google::spanner::admin::instance::v1::CreateInstanceRequest` object.
115 *
116 * Note that the instance id must be between 2 and 64 characters long, it must
117 * start with a lowercase letter (`[a-z]`), it must end with a lowercase
118 * letter or a number (`[a-z0-9]`) and any characters between the beginning
119 * and ending characters must be lower case letters, numbers, or dashes (`-`),
120 * that is, they must belong to the `[-a-z0-9]` character set.
121 *
122 * @par Example
123 * @snippet samples.cc create-instance
124 *
125 */
126 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
128 google::spanner::admin::instance::v1::CreateInstanceRequest const&);
129
130 /**
131 * Updates a Cloud Spanner instance.
132 *
133 * Use `google::cloud::spanner::UpdateInstanceRequestBuilder` to build the
134 * `google::spanner::admin::instance::v1::UpdateInstanceRequest` object.
135 *
136 * @par Idempotency
137 * This operation is idempotent as its result does not depend on the previous
138 * state of the instance. Note that, as is the case with all operations, it is
139 * subject to race conditions if multiple tasks are attempting to change the
140 * same fields in the same instance.
141 *
142 * @par Example
143 * @snippet samples.cc update-instance
144 *
145 */
146 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
148 google::spanner::admin::instance::v1::UpdateInstanceRequest const&);
149
150 /**
151 * Deletes an existing Cloud Spanner instance.
152 *
153 * @warning Deleting an instance deletes all the databases in the
154 * instance. This is an unrecoverable operation.
155 *
156 * @par Example
157 * @snippet samples.cc delete-instance
158 */
159 Status DeleteInstance(Instance const& in);
160
161 /**
162 * Retrieve information about a Cloud Spanner Instance Config.
163 *
164 * @par Idempotency
165 * This is a read-only operation and therefore it is always treated as
166 * idempotent.
167 *
168 * @par Example
169 * @snippet samples.cc get-instance-config
170 */
171 StatusOr<google::spanner::admin::instance::v1::InstanceConfig>
172 GetInstanceConfig(std::string const& name);
173
174 /**
175 * Retrieve a list of instance configs for a given project.
176 *
177 * @par Idempotency
178 * This is a read-only operation and therefore it is always treated as
179 * idempotent.
180 *
181 * @par Example
182 * @snippet samples.cc list-instance-configs
183 */
184 ListInstanceConfigsRange ListInstanceConfigs(std::string project_id);
185
186 /**
187 * Retrieve a list of instances for a given project.
188 *
189 * @par Idempotency
190 * This is a read-only operation and therefore it is always treated as
191 * idempotent.
192 *
193 * @par Example
194 * @snippet samples.cc list-instances
195 */
196 ListInstancesRange ListInstances(std::string project_id, std::string filter);
197
198 /**
199 * Get the IAM policy in effect for the given instance.
200 *
201 * This function retrieves the IAM policy configured in the given instance,
202 * that is, which roles are enabled in the instance, and what entities are
203 * members of each role.
204 *
205 * @par Idempotency
206 * This is a read-only operation and therefore it is always treated as
207 * idempotent.
208 *
209 * @par Example
210 * @snippet samples.cc instance-get-iam-policy
211 *
212 * @see The [Cloud Spanner
213 * documentation](https://cloud.google.com/spanner/docs/iam) for a
214 * description of the roles and permissions supported by Cloud Spanner.
215 * @see [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions)
216 * for an introduction to Identity and Access Management in Google Cloud
217 * Platform.
218 */
219 StatusOr<google::iam::v1::Policy> GetIamPolicy(Instance const& in);
220
221 /**
222 * Set the IAM policy for the given instance.
223 *
224 * This function changes the IAM policy configured in the given instance to
225 * the value of @p policy.
226 *
227 * @par Idempotency
228 * This function is only idempotent if the `etag` field in @p policy is set.
229 * Therefore, the underlying RPCs are only retried if the field is set, and
230 * the function returns the first RPC error in any other case.
231 *
232 * @par Example
233 * @snippet samples.cc add-database-reader
234 *
235 * @see The [Cloud Spanner
236 * documentation](https://cloud.google.com/spanner/docs/iam) for a
237 * description of the roles and permissions supported by Cloud Spanner.
238 * @see [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions)
239 * for an introduction to Identity and Access Management in Google Cloud
240 * Platform.
241 */
242 StatusOr<google::iam::v1::Policy> SetIamPolicy(
243 Instance const& in, google::iam::v1::Policy policy);
244
245 /**
246 * Updates the IAM policy for an instance using an optimistic concurrency
247 * control loop.
248 *
249 * This function repeatedly reads the current IAM policy in @p in, and then
250 * calls the @p updater with the this policy. The @p updater returns an empty
251 * optional if no changes are required, or it returns the new desired value
252 * for the IAM policy. This function then updates the policy.
253 *
254 * Updating an IAM policy can fail with retryable errors or can be aborted
255 * because there were simultaneous changes the to IAM policy. In these cases
256 * this function reruns the loop until it succeeds.
257 *
258 * The function returns the final IAM policy, or an error if the rerun policy
259 * for the underlying connection has expired.
260 *
261 * @par Idempotency
262 * This function always sets the `etag` field on the policy, so the underlying
263 * RPCs are retried automatically.
264 *
265 * @param in the identifier for the instance where you want to change the IAM
266 * policy.
267 * @param updater a callback to modify the policy. Return an unset optional
268 * to indicate that no changes to the policy are needed.
269 */
270 StatusOr<google::iam::v1::Policy> SetIamPolicy(Instance const& in,
271 IamUpdater const& updater);
272
273 /**
274 * @copydoc SetIamPolicy(Instance const&,IamUpdater const&)
275 *
276 * @param rerun_policy controls for how long (or how many times) the updater
277 * will be rerun after the IAM policy update aborts.
278 * @param backoff_policy controls how long `SetIamPolicy` waits between
279 * reruns.
280 */
281 StatusOr<google::iam::v1::Policy> SetIamPolicy(
282 Instance const& in, IamUpdater const& updater,
283 std::unique_ptr<TransactionRerunPolicy> rerun_policy,
284 std::unique_ptr<BackoffPolicy> backoff_policy);
285
286 /**
287 * Get the subset of the permissions the caller has on the given instance.
288 *
289 * This function compares the given list of permissions against those
290 * permissions granted to the caller, and returns the subset of the list that
291 * the caller actually holds.
292 *
293 * @note Permission wildcards, such as `spanner.*` are not allowed.
294 *
295 * @par Example
296 * @snippet samples.cc instance-test-iam-permissions
297 *
298 * @see The [Cloud Spanner
299 * documentation](https://cloud.google.com/spanner/docs/iam) for a description
300 * of the roles and permissions supported by Cloud Spanner.
301 * @see [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions)
302 * for an introduction to Identity and Access Management in Google Cloud
303 * Platform.
304 */
305 StatusOr<google::iam::v1::TestIamPermissionsResponse> TestIamPermissions(
306 Instance const& in, std::vector<std::string> permissions);
307
308 private:
309 std::shared_ptr<InstanceAdminConnection> conn_;
310};
311
312GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
313} // namespace spanner
314} // namespace cloud
315} // namespace google
316
317#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INSTANCE_ADMIN_CLIENT_H
friend friend class future
Performs instance administration operations on Cloud Spanner.
Definition: instance_admin_client.h:68
StatusOr< google::spanner::admin::instance::v1::Instance > GetInstance(Instance const &in)
Retrieve metadata information about a Cloud Spanner Instance.
InstanceAdminClient & operator=(InstanceAdminClient &&)=default
StatusOr< google::iam::v1::Policy > SetIamPolicy(Instance const &in, IamUpdater const &updater)
Updates the IAM policy for an instance using an optimistic concurrency control loop.
ListInstanceConfigsRange ListInstanceConfigs(std::string project_id)
Retrieve a list of instance configs for a given project.
StatusOr< google::spanner::admin::instance::v1::InstanceConfig > GetInstanceConfig(std::string const &name)
Retrieve information about a Cloud Spanner Instance Config.
future< StatusOr< google::spanner::admin::instance::v1::Instance > > CreateInstance(google::spanner::admin::instance::v1::CreateInstanceRequest const &)
Creates a new Cloud Spanner instance in the given project.
StatusOr< google::iam::v1::Policy > GetIamPolicy(Instance const &in)
Get the IAM policy in effect for the given instance.
StatusOr< google::iam::v1::TestIamPermissionsResponse > TestIamPermissions(Instance const &in, std::vector< std::string > permissions)
Get the subset of the permissions the caller has on the given instance.
InstanceAdminClient(InstanceAdminClient const &)=default
Status DeleteInstance(Instance const &in)
Deletes an existing Cloud Spanner instance.
StatusOr< google::iam::v1::Policy > SetIamPolicy(Instance const &in, IamUpdater const &updater, std::unique_ptr< TransactionRerunPolicy > rerun_policy, std::unique_ptr< BackoffPolicy > backoff_policy)
Updates the IAM policy for an instance using an optimistic concurrency control loop.
InstanceAdminClient(InstanceAdminClient &&)=default
InstanceAdminClient & operator=(InstanceAdminClient const &)=default
InstanceAdminClient()=delete
No default construction.
future< StatusOr< google::spanner::admin::instance::v1::Instance > > UpdateInstance(google::spanner::admin::instance::v1::UpdateInstanceRequest const &)
Updates a Cloud Spanner instance.
InstanceAdminClient(std::shared_ptr< InstanceAdminConnection > conn)
Definition: instance_admin_client.h:70
ListInstancesRange ListInstances(std::string project_id, std::string filter)
Retrieve a list of instances for a given project.
friend bool operator!=(InstanceAdminClient const &a, InstanceAdminClient const &b)
Definition: instance_admin_client.h:91
StatusOr< google::iam::v1::Policy > SetIamPolicy(Instance const &in, google::iam::v1::Policy policy)
Set the IAM policy for the given instance.
friend bool operator==(InstanceAdminClient const &a, InstanceAdminClient const &b)
Definition: instance_admin_client.h:87
A connection to the Cloud Spanner instance administration service.
Definition: instance_admin_connection.h:75
This class identifies a Cloud Spanner Instance.
Definition: instance.h:42
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
#define GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED(name)
Definition: version.h:23