google-cloud-bigtable 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +19 -0
- data/AUTHENTICATION.md +177 -0
- data/CHANGELOG.md +223 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +188 -0
- data/EMULATOR.md +30 -0
- data/LICENSE +201 -0
- data/LOGGING.md +32 -0
- data/OVERVIEW.md +400 -0
- data/TROUBLESHOOTING.md +31 -0
- data/lib/google-cloud-bigtable.rb +171 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +145 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +90 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +208 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +154 -0
- data/lib/google/bigtable/admin/v2/common_pb.rb +30 -0
- data/lib/google/bigtable/admin/v2/instance_pb.rb +74 -0
- data/lib/google/bigtable/admin/v2/table_pb.rb +127 -0
- data/lib/google/bigtable/v2/bigtable_pb.rb +113 -0
- data/lib/google/bigtable/v2/bigtable_services_pb.rb +68 -0
- data/lib/google/bigtable/v2/data_pb.rb +156 -0
- data/lib/google/cloud/bigtable.rb +184 -0
- data/lib/google/cloud/bigtable/admin.rb +202 -0
- data/lib/google/cloud/bigtable/admin/credentials.rb +27 -0
- data/lib/google/cloud/bigtable/admin/v2.rb +223 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1451 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +139 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1734 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +163 -0
- data/lib/google/cloud/bigtable/admin/v2/credentials.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +297 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +587 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +193 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +303 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +64 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +33 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +151 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +91 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +29 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +222 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +113 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +45 -0
- data/lib/google/cloud/bigtable/app_profile.rb +439 -0
- data/lib/google/cloud/bigtable/app_profile/job.rb +99 -0
- data/lib/google/cloud/bigtable/app_profile/list.rb +165 -0
- data/lib/google/cloud/bigtable/backup.rb +324 -0
- data/lib/google/cloud/bigtable/backup/job.rb +87 -0
- data/lib/google/cloud/bigtable/backup/list.rb +167 -0
- data/lib/google/cloud/bigtable/chunk_processor.rb +241 -0
- data/lib/google/cloud/bigtable/cluster.rb +390 -0
- data/lib/google/cloud/bigtable/cluster/job.rb +88 -0
- data/lib/google/cloud/bigtable/cluster/list.rb +171 -0
- data/lib/google/cloud/bigtable/column_family.rb +73 -0
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +194 -0
- data/lib/google/cloud/bigtable/convert.rb +83 -0
- data/lib/google/cloud/bigtable/credentials.rb +25 -0
- data/lib/google/cloud/bigtable/errors.rb +38 -0
- data/lib/google/cloud/bigtable/gc_rule.rb +334 -0
- data/lib/google/cloud/bigtable/instance.rb +935 -0
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +74 -0
- data/lib/google/cloud/bigtable/instance/job.rb +98 -0
- data/lib/google/cloud/bigtable/instance/list.rb +164 -0
- data/lib/google/cloud/bigtable/longrunning_job.rb +122 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +256 -0
- data/lib/google/cloud/bigtable/mutation_operations.rb +357 -0
- data/lib/google/cloud/bigtable/policy.rb +167 -0
- data/lib/google/cloud/bigtable/project.rb +471 -0
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +134 -0
- data/lib/google/cloud/bigtable/read_operations.rb +328 -0
- data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
- data/lib/google/cloud/bigtable/row.rb +136 -0
- data/lib/google/cloud/bigtable/row_filter.rb +639 -0
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +590 -0
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +114 -0
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +621 -0
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +287 -0
- data/lib/google/cloud/bigtable/row_range.rb +179 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +113 -0
- data/lib/google/cloud/bigtable/rows_reader.rb +200 -0
- data/lib/google/cloud/bigtable/sample_row_key.rb +85 -0
- data/lib/google/cloud/bigtable/service.rb +913 -0
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +686 -0
- data/lib/google/cloud/bigtable/table/cluster_state.rb +125 -0
- data/lib/google/cloud/bigtable/table/list.rb +154 -0
- data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
- data/lib/google/cloud/bigtable/v2.rb +146 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +591 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +83 -0
- data/lib/google/cloud/bigtable/v2/credentials.rb +46 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +290 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +493 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +34 -0
- data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/value_range.rb +181 -0
- data/lib/google/cloud/bigtable/version.rb +22 -0
- metadata +337 -0
@@ -0,0 +1,935 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
|
18
|
+
require "google/cloud/bigtable/instance/job"
|
19
|
+
require "google/cloud/bigtable/instance/list"
|
20
|
+
require "google/cloud/bigtable/instance/cluster_map"
|
21
|
+
require "google/cloud/bigtable/app_profile"
|
22
|
+
require "google/cloud/bigtable/policy"
|
23
|
+
require "google/cloud/bigtable/routing_policy"
|
24
|
+
|
25
|
+
module Google
|
26
|
+
module Cloud
|
27
|
+
module Bigtable
|
28
|
+
##
|
29
|
+
# # Instance
|
30
|
+
#
|
31
|
+
# Represents a Bigtable instance. Instances are dedicated Bigtable
|
32
|
+
# storage resources that contain Bigtable tables.
|
33
|
+
#
|
34
|
+
# See {Google::Cloud::Bigtable::Project#instances},
|
35
|
+
# {Google::Cloud::Bigtable::Project#instance}, and
|
36
|
+
# {Google::Cloud::Bigtable::Project#create_instance}.
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# require "google/cloud/bigtable"
|
40
|
+
#
|
41
|
+
# bigtable = Google::Cloud::Bigtable.new
|
42
|
+
#
|
43
|
+
# job = bigtable.create_instance(
|
44
|
+
# "my-instance",
|
45
|
+
# display_name: "Instance for user data",
|
46
|
+
# type: :DEVELOPMENT,
|
47
|
+
# labels: { "env" => "dev"}
|
48
|
+
# ) do |clusters|
|
49
|
+
# clusters.add("test-cluster", "us-east1-b") # nodes not allowed
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# job.done? #=> false
|
53
|
+
#
|
54
|
+
# # To block until the operation completes.
|
55
|
+
# job.wait_until_done!
|
56
|
+
# job.done? #=> true
|
57
|
+
#
|
58
|
+
# if job.error?
|
59
|
+
# status = job.error
|
60
|
+
# else
|
61
|
+
# instance = job.instance
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
class Instance
|
65
|
+
# @private
|
66
|
+
# The gRPC Service object.
|
67
|
+
attr_accessor :service
|
68
|
+
|
69
|
+
# @private
|
70
|
+
#
|
71
|
+
# Creates a new Instance instance.
|
72
|
+
def initialize grpc, service
|
73
|
+
@grpc = grpc
|
74
|
+
@service = service
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# The unique identifier for the project to which the instance belongs.
|
79
|
+
#
|
80
|
+
# @return [String]
|
81
|
+
#
|
82
|
+
def project_id
|
83
|
+
@grpc.name.split("/")[1]
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# The unique identifier for the instance.
|
88
|
+
#
|
89
|
+
# @return [String]
|
90
|
+
#
|
91
|
+
def instance_id
|
92
|
+
@grpc.name.split("/")[3]
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# The descriptive name for the instance as it appears in UIs. Must be
|
97
|
+
# unique per project and between 4 and 30 characters long.
|
98
|
+
#
|
99
|
+
# @return [String]
|
100
|
+
#
|
101
|
+
def display_name
|
102
|
+
@grpc.display_name
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# Updates the descriptive name for the instance as it appears in UIs.
|
107
|
+
# Can be changed at any time, but should be kept globally unique
|
108
|
+
# to avoid confusion.
|
109
|
+
#
|
110
|
+
# @param value [String] The descriptive name for the instance.
|
111
|
+
#
|
112
|
+
def display_name= value
|
113
|
+
@grpc.display_name = value
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# The full path for the instance resource. Values are of the form
|
118
|
+
# `projects/<project_id>/instances/<instance_id>`.
|
119
|
+
#
|
120
|
+
# @return [String]
|
121
|
+
#
|
122
|
+
def path
|
123
|
+
@grpc.name
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# The current instance state. Possible values are `:CREATING`,
|
128
|
+
# `:READY`, `:STATE_NOT_KNOWN`.
|
129
|
+
#
|
130
|
+
# @return [Symbol]
|
131
|
+
#
|
132
|
+
def state
|
133
|
+
@grpc.state
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# The instance has been successfully created and can serve requests
|
138
|
+
# to its tables.
|
139
|
+
#
|
140
|
+
# @return [Boolean]
|
141
|
+
#
|
142
|
+
def ready?
|
143
|
+
state == :READY
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# The instance is currently being created and may be destroyed if the
|
148
|
+
# creation process encounters an error.
|
149
|
+
#
|
150
|
+
# @return [Boolean]
|
151
|
+
#
|
152
|
+
def creating?
|
153
|
+
state == :CREATING
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Instance type. Possible values include `:DEVELOPMENT` and `:PRODUCTION`.
|
158
|
+
#
|
159
|
+
# @return [Symbol]
|
160
|
+
#
|
161
|
+
def type
|
162
|
+
@grpc.type
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# The instance is meant for development and testing purposes only; it has
|
167
|
+
# no performance or uptime guarantees and is not covered by SLA.
|
168
|
+
# After a development instance is created, it can be upgraded by
|
169
|
+
# updating the instance to type `:PRODUCTION`. An instance created
|
170
|
+
# as a production instance cannot be changed to a development instance.
|
171
|
+
# When creating a development instance, `nodes` on the cluster must
|
172
|
+
# not be set. (See {#create_cluster}.)
|
173
|
+
#
|
174
|
+
# @return [Boolean]
|
175
|
+
#
|
176
|
+
def development?
|
177
|
+
type == :DEVELOPMENT
|
178
|
+
end
|
179
|
+
|
180
|
+
##
|
181
|
+
# An instance meant for production use. Requires that `nodes` must be set
|
182
|
+
# on the cluster. (See {#create_cluster}.)
|
183
|
+
#
|
184
|
+
# @return [Boolean]
|
185
|
+
#
|
186
|
+
def production?
|
187
|
+
type == :PRODUCTION
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
# Sets the instance type.
|
192
|
+
#
|
193
|
+
# Valid values are `:DEVELOPMENT` and `:PRODUCTION`.
|
194
|
+
# After a development instance is created, it can be upgraded
|
195
|
+
# by updating the instance to type `:PRODUCTION`.
|
196
|
+
# An instance created as a production instance cannot be changed to a
|
197
|
+
# development instance.
|
198
|
+
#
|
199
|
+
# @param instance_type [Symbol]
|
200
|
+
#
|
201
|
+
# @example
|
202
|
+
# require "google/cloud/bigtable"
|
203
|
+
#
|
204
|
+
# bigtable = Google::Cloud::Bigtable.new
|
205
|
+
#
|
206
|
+
# instance = bigtable.instance("my-instance")
|
207
|
+
#
|
208
|
+
# instance.development? # true
|
209
|
+
# instance.type = :PRODUCTION
|
210
|
+
# instance.development? # false
|
211
|
+
# instance.production? # true
|
212
|
+
#
|
213
|
+
def type= instance_type
|
214
|
+
@grpc.type = instance_type
|
215
|
+
end
|
216
|
+
|
217
|
+
##
|
218
|
+
# Gets the Cloud Labels for the instance.
|
219
|
+
#
|
220
|
+
# Cloud Labels are a flexible and lightweight mechanism for organizing
|
221
|
+
# cloud resources into groups that reflect a customer's organizational
|
222
|
+
# needs and deployment strategies. Cloud Labels can be used to filter
|
223
|
+
# collections of resources, to control how resource
|
224
|
+
# metrics are aggregated, and as arguments to policy
|
225
|
+
# management rules (e.g., route, firewall, load balancing, etc.).
|
226
|
+
#
|
227
|
+
# * Label keys must be between 1 and 63 characters long and must conform
|
228
|
+
# to the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.
|
229
|
+
# * Label values must be between 0 and 63 characters long and must
|
230
|
+
# conform to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
|
231
|
+
# * No more than 64 labels can be associated with a given resource.
|
232
|
+
#
|
233
|
+
# @return [Hash{String=>String}] The label keys and values in a hash.
|
234
|
+
#
|
235
|
+
def labels
|
236
|
+
@grpc.labels
|
237
|
+
end
|
238
|
+
|
239
|
+
##
|
240
|
+
# Sets the Cloud Labels for the instance.
|
241
|
+
#
|
242
|
+
# @param labels [Hash{String=>String}] The Cloud Labels.
|
243
|
+
#
|
244
|
+
def labels= labels
|
245
|
+
labels ||= {}
|
246
|
+
@grpc.labels = Google::Protobuf::Map.new(
|
247
|
+
:string, :string,
|
248
|
+
Hash[labels.map { |k, v| [String(k), String(v)] }]
|
249
|
+
)
|
250
|
+
end
|
251
|
+
|
252
|
+
##
|
253
|
+
# Updates the instance.
|
254
|
+
#
|
255
|
+
# Updatable attributes are:
|
256
|
+
# * `display_name` - The descriptive name for the instance.
|
257
|
+
# * `type` - `:DEVELOPMENT` type instance can be upgraded to `:PRODUCTION` instance.
|
258
|
+
# An instance created as a production instance cannot be changed to a development instance.
|
259
|
+
# * `labels` - Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources.
|
260
|
+
#
|
261
|
+
# @return [Google::Cloud::Bigtable::Instance::Job]
|
262
|
+
# The job representing the long-running, asynchronous processing of
|
263
|
+
# an instance update operation.
|
264
|
+
#
|
265
|
+
# @example
|
266
|
+
# require "google/cloud/bigtable"
|
267
|
+
#
|
268
|
+
# bigtable = Google::Cloud::Bigtable.new
|
269
|
+
#
|
270
|
+
# instance = bigtable.instance("my-instance")
|
271
|
+
# instance.display_name = "My app dev instance" # Set display name
|
272
|
+
# instance.labels = { env: "dev", data: "users" }
|
273
|
+
# job = instance.save
|
274
|
+
#
|
275
|
+
# job.done? #=> false
|
276
|
+
#
|
277
|
+
# # Reload job until completion.
|
278
|
+
# job.wait_until_done!
|
279
|
+
# job.done? #=> true
|
280
|
+
#
|
281
|
+
# if job.error?
|
282
|
+
# puts job.error
|
283
|
+
# else
|
284
|
+
# instance = job.instance
|
285
|
+
# puts instance.name
|
286
|
+
# puts instance.labels
|
287
|
+
# end
|
288
|
+
#
|
289
|
+
def save
|
290
|
+
ensure_service!
|
291
|
+
update_mask = Google::Protobuf::FieldMask.new paths: ["labels", "display_name", "type"]
|
292
|
+
grpc = service.partial_update_instance @grpc, update_mask
|
293
|
+
Instance::Job.from_grpc grpc, service
|
294
|
+
end
|
295
|
+
alias update save
|
296
|
+
|
297
|
+
##
|
298
|
+
# Reloads instance data.
|
299
|
+
#
|
300
|
+
# @return [Google::Cloud::Bigtable::Instance]
|
301
|
+
#
|
302
|
+
def reload!
|
303
|
+
@grpc = service.get_instance instance_id
|
304
|
+
self
|
305
|
+
end
|
306
|
+
|
307
|
+
##
|
308
|
+
# Permanently deletes the instance from the project.
|
309
|
+
#
|
310
|
+
# @return [Boolean] Returns `true` if the instance was deleted.
|
311
|
+
#
|
312
|
+
# @example
|
313
|
+
# require "google/cloud/bigtable"
|
314
|
+
#
|
315
|
+
# bigtable = Google::Cloud::Bigtable.new
|
316
|
+
#
|
317
|
+
# instance = bigtable.instance("my-instance")
|
318
|
+
# instance.delete
|
319
|
+
#
|
320
|
+
def delete
|
321
|
+
ensure_service!
|
322
|
+
service.delete_instance instance_id
|
323
|
+
true
|
324
|
+
end
|
325
|
+
|
326
|
+
##
|
327
|
+
# Lists the clusters in the instance.
|
328
|
+
#
|
329
|
+
# See {Google::Cloud::Bigtable::Cluster#delete} and
|
330
|
+
# {Google::Cloud::Bigtable::Cluster#save}.
|
331
|
+
#
|
332
|
+
# @param token [String] The `token` value returned by the last call to
|
333
|
+
# `clusters`; indicates that this is a continuation of a call
|
334
|
+
# and that the system should return the next page of data.
|
335
|
+
# @return [Array<Google::Cloud::Bigtable::Cluster>]
|
336
|
+
# See({Google::Cloud::Bigtable::Cluster::List})
|
337
|
+
#
|
338
|
+
# @example
|
339
|
+
# require "google/cloud/bigtable"
|
340
|
+
#
|
341
|
+
# bigtable = Google::Cloud::Bigtable.new
|
342
|
+
#
|
343
|
+
# instance = bigtable.instance("my-instance")
|
344
|
+
#
|
345
|
+
# instance.clusters.all do |cluster|
|
346
|
+
# puts cluster.cluster_id
|
347
|
+
# end
|
348
|
+
#
|
349
|
+
def clusters token: nil
|
350
|
+
ensure_service!
|
351
|
+
grpc = service.list_clusters instance_id, token: token
|
352
|
+
Cluster::List.from_grpc grpc, service, instance_id: instance_id
|
353
|
+
end
|
354
|
+
|
355
|
+
##
|
356
|
+
# Gets a cluster in the instance.
|
357
|
+
#
|
358
|
+
# See {Google::Cloud::Bigtable::Cluster#delete} and
|
359
|
+
# {Google::Cloud::Bigtable::Cluster#save}.
|
360
|
+
#
|
361
|
+
# @param cluster_id [String] The unique ID of the requested cluster.
|
362
|
+
# @return [Google::Cloud::Bigtable::Cluster, nil]
|
363
|
+
#
|
364
|
+
# @example
|
365
|
+
# require "google/cloud/bigtable"
|
366
|
+
#
|
367
|
+
# bigtable = Google::Cloud::Bigtable.new
|
368
|
+
#
|
369
|
+
# instance = bigtable.instance("my-instance")
|
370
|
+
#
|
371
|
+
# cluster = instance.cluster("my-instance-cluster")
|
372
|
+
# puts cluster.cluster_id
|
373
|
+
#
|
374
|
+
def cluster cluster_id
|
375
|
+
ensure_service!
|
376
|
+
grpc = service.get_cluster instance_id, cluster_id
|
377
|
+
Cluster.from_grpc grpc, service
|
378
|
+
rescue Google::Cloud::NotFoundError
|
379
|
+
nil
|
380
|
+
end
|
381
|
+
|
382
|
+
##
|
383
|
+
# Creates a cluster in the instance.
|
384
|
+
#
|
385
|
+
# @param cluster_id [String]
|
386
|
+
# The ID to be used when referring to the new cluster within its instance.
|
387
|
+
# @param location [String]
|
388
|
+
# The location where this cluster's nodes and storage reside. For best
|
389
|
+
# performance, clients should be located as close as possible to this
|
390
|
+
# cluster. Example: "us-east-1b"
|
391
|
+
# @param nodes [Integer] The number of nodes allocated to this cluster.
|
392
|
+
# More nodes enable higher throughput and more consistent performance.
|
393
|
+
# @param storage_type [Symbol] Storage type.
|
394
|
+
# The type of storage used by this cluster to serve its
|
395
|
+
# parent instance's tables.
|
396
|
+
# Valid types are:
|
397
|
+
# * `:SSD` - Flash (SSD) storage.
|
398
|
+
# * `:HDD` - Magnetic drive (HDD).
|
399
|
+
# @return [Google::Cloud::Bigtable::Cluster::Job]
|
400
|
+
#
|
401
|
+
# @example
|
402
|
+
# require "google/cloud/bigtable"
|
403
|
+
#
|
404
|
+
# bigtable = Google::Cloud::Bigtable.new
|
405
|
+
#
|
406
|
+
# instance = bigtable.instance("my-instance")
|
407
|
+
# job = instance.create_cluster(
|
408
|
+
# "my-new-cluster",
|
409
|
+
# "us-east-1b",
|
410
|
+
# nodes: 3,
|
411
|
+
# storage_type: :SSD
|
412
|
+
# )
|
413
|
+
#
|
414
|
+
# job.done? #=> false
|
415
|
+
#
|
416
|
+
# # To block until the operation completes.
|
417
|
+
# job.wait_until_done!
|
418
|
+
# job.done? #=> true
|
419
|
+
#
|
420
|
+
# if job.error?
|
421
|
+
# status = job.error
|
422
|
+
# else
|
423
|
+
# cluster = job.cluster
|
424
|
+
# end
|
425
|
+
#
|
426
|
+
def create_cluster cluster_id, location, nodes: nil, storage_type: nil
|
427
|
+
ensure_service!
|
428
|
+
attrs = {
|
429
|
+
serve_nodes: nodes,
|
430
|
+
default_storage_type: storage_type,
|
431
|
+
location: location
|
432
|
+
}.delete_if { |_, v| v.nil? }
|
433
|
+
|
434
|
+
cluster = Google::Bigtable::Admin::V2::Cluster.new attrs
|
435
|
+
grpc = service.create_cluster instance_id, cluster_id, cluster
|
436
|
+
Cluster::Job.from_grpc grpc, service
|
437
|
+
end
|
438
|
+
|
439
|
+
##
|
440
|
+
# Lists all tables in the instance.
|
441
|
+
#
|
442
|
+
# See {Google::Cloud::Bigtable::Table#delete} and
|
443
|
+
# {Google::Cloud::Bigtable::Table#save}.
|
444
|
+
#
|
445
|
+
# @return [Array<Google::Cloud::Bigtable::Table>]
|
446
|
+
# (See {Google::Cloud::Bigtable::Table::List})
|
447
|
+
#
|
448
|
+
# @example
|
449
|
+
# require "google/cloud/bigtable"
|
450
|
+
#
|
451
|
+
# bigtable = Google::Cloud::Bigtable.new
|
452
|
+
#
|
453
|
+
# instance = bigtable.instance("my-instance")
|
454
|
+
#
|
455
|
+
# # Default name-only view
|
456
|
+
# instance.tables.all do |table|
|
457
|
+
# puts table.name
|
458
|
+
# end
|
459
|
+
#
|
460
|
+
def tables
|
461
|
+
ensure_service!
|
462
|
+
grpc = service.list_tables instance_id
|
463
|
+
Table::List.from_grpc grpc, service
|
464
|
+
end
|
465
|
+
|
466
|
+
##
|
467
|
+
# Gets metadata information of a table in the instance.
|
468
|
+
#
|
469
|
+
# @param view [Symbol]
|
470
|
+
# The view to be applied to the returned tables' fields.
|
471
|
+
# Defaults to `SCHEMA_VIEW` if unspecified.
|
472
|
+
# Valid view types are.
|
473
|
+
# * `:NAME_ONLY` - Only populates `name`
|
474
|
+
# * `:SCHEMA_VIEW` - Only populates `name` and fields related to the table's schema
|
475
|
+
# * `:REPLICATION_VIEW` - Only populates `name` and fields related to the table's replication state.
|
476
|
+
# * `:FULL` - Populates all fields
|
477
|
+
# @param perform_lookup [Boolean] Creates table object without verifying
|
478
|
+
# that the table resource exists.
|
479
|
+
# Calls made on this object will raise errors if the table
|
480
|
+
# does not exist. Default value is `false`. Optional.
|
481
|
+
# Helps to reduce admin API calls.
|
482
|
+
# @param app_profile_id [String] The unique identifier for the app profile. Optional.
|
483
|
+
# Used only in data operations.
|
484
|
+
# This value specifies routing for replication. If not specified, the
|
485
|
+
# "default" application profile will be used.
|
486
|
+
# @return [Google::Cloud::Bigtable::Table]
|
487
|
+
#
|
488
|
+
# @example
|
489
|
+
# require "google/cloud/bigtable"
|
490
|
+
#
|
491
|
+
# bigtable = Google::Cloud::Bigtable.new
|
492
|
+
#
|
493
|
+
# instance = bigtable.instance("my-instance")
|
494
|
+
#
|
495
|
+
# table = instance.table("my-table", perform_lookup: true)
|
496
|
+
# puts table.name
|
497
|
+
# puts table.column_families
|
498
|
+
#
|
499
|
+
# # Name-only view
|
500
|
+
# table = instance.table("my-table", view: :NAME_ONLY, perform_lookup: true)
|
501
|
+
# puts table.name
|
502
|
+
#
|
503
|
+
# @example Mutate rows.
|
504
|
+
# require "google/cloud/bigtable"
|
505
|
+
#
|
506
|
+
# bigtable = Google::Cloud::Bigtable.new
|
507
|
+
#
|
508
|
+
# table = bigtable.table("my-instance", "my-table")
|
509
|
+
#
|
510
|
+
# entry = table.new_mutation_entry("user-1")
|
511
|
+
# entry.set_cell(
|
512
|
+
# "cf-1",
|
513
|
+
# "field-1",
|
514
|
+
# "XYZ",
|
515
|
+
# timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
|
516
|
+
# ).delete_cells("cf2", "field02")
|
517
|
+
#
|
518
|
+
# table.mutate_row(entry)
|
519
|
+
#
|
520
|
+
def table table_id, view: nil, perform_lookup: nil, app_profile_id: nil
|
521
|
+
ensure_service!
|
522
|
+
|
523
|
+
table = if perform_lookup
|
524
|
+
grpc = service.get_table instance_id, table_id, view: view
|
525
|
+
Table.from_grpc grpc, service, view: view
|
526
|
+
else
|
527
|
+
Table.from_path service.table_path(instance_id, table_id), service
|
528
|
+
end
|
529
|
+
|
530
|
+
table.app_profile_id = app_profile_id
|
531
|
+
table
|
532
|
+
rescue Google::Cloud::NotFoundError
|
533
|
+
nil
|
534
|
+
end
|
535
|
+
|
536
|
+
##
|
537
|
+
# Creates a new table in the instance.
|
538
|
+
#
|
539
|
+
# The table can be created with a full set of initial column families,
|
540
|
+
# specified in the request.
|
541
|
+
#
|
542
|
+
# @param name [String]
|
543
|
+
# The name by which the new table should be referred to within the parent
|
544
|
+
# instance.
|
545
|
+
# @param column_families [Google::Cloud::Bigtable::ColumnFamilyMap]
|
546
|
+
# An object containing the column families for the table, mapped by
|
547
|
+
# column family name.
|
548
|
+
# @param granularity [Symbol]
|
549
|
+
# The granularity at which timestamps are stored in this table.
|
550
|
+
# Timestamps not matching the granularity will be rejected.
|
551
|
+
# Valid value is `:MILLIS`.
|
552
|
+
# If unspecified, the value will be set to `:MILLIS`.
|
553
|
+
# @param initial_splits [Array<String>]
|
554
|
+
# The optional list of row keys that will be used to initially split the
|
555
|
+
# table into several tablets (tablets are similar to HBase regions).
|
556
|
+
# Given two split keys, `s1` and `s2`, three tablets will be created,
|
557
|
+
# spanning the key ranges: `[, s1), [s1, s2), [s2, )`.
|
558
|
+
#
|
559
|
+
# Example:
|
560
|
+
#
|
561
|
+
# * Row keys := `["a", "apple", "custom", "customer_1", "customer_2", "other", "zz"]`
|
562
|
+
# * initial_split_keys := `["apple", "customer_1", "customer_2", "other"]`
|
563
|
+
# * Key assignment:
|
564
|
+
# * Tablet 1 : `[, apple) => {"a"}`
|
565
|
+
# * Tablet 2 : `[apple, customer_1) => {"apple", "custom"}`
|
566
|
+
# * Tablet 3 : `[customer_1, customer_2) => {"customer_1"}`
|
567
|
+
# * Tablet 4 : `[customer_2, other) => {"customer_2"}`
|
568
|
+
# * Tablet 5 : `[other, ) => {"other", "zz"}`
|
569
|
+
# A hash in the form of `Google::Bigtable::Admin::V2::CreateTableRequest::Split`
|
570
|
+
# can also be provided.
|
571
|
+
# @yield [column_families] A block for adding column families.
|
572
|
+
# @yieldparam [Google::Cloud::Bigtable::ColumnFamilyMap] column_families
|
573
|
+
# A mutable object containing the column families for the table,
|
574
|
+
# mapped by column family name.
|
575
|
+
#
|
576
|
+
# @return [Google::Cloud::Bigtable::Table]
|
577
|
+
#
|
578
|
+
# @example Create a table without column families.
|
579
|
+
# require "google/cloud/bigtable"
|
580
|
+
#
|
581
|
+
# bigtable = Google::Cloud::Bigtable.new
|
582
|
+
#
|
583
|
+
# instance = bigtable.instance("my-instance")
|
584
|
+
#
|
585
|
+
# table = instance.create_table("my-table")
|
586
|
+
# puts table.name
|
587
|
+
#
|
588
|
+
# @example Create a table with initial splits and column families.
|
589
|
+
# require "google/cloud/bigtable"
|
590
|
+
#
|
591
|
+
# bigtable = Google::Cloud::Bigtable.new
|
592
|
+
#
|
593
|
+
# instance = bigtable.instance("my-instance")
|
594
|
+
#
|
595
|
+
# initial_splits = ["user-00001", "user-100000", "others"]
|
596
|
+
# table = instance.create_table("my-table", initial_splits: initial_splits) do |cfm|
|
597
|
+
# cfm.add('cf1', gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
|
598
|
+
# cfm.add('cf2', gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
|
599
|
+
#
|
600
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.union(
|
601
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
602
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
603
|
+
# )
|
604
|
+
# cfm.add('cf3', gc_rule: gc_rule)
|
605
|
+
# end
|
606
|
+
#
|
607
|
+
# puts table
|
608
|
+
#
|
609
|
+
def create_table name, column_families: nil, granularity: nil, initial_splits: nil, &block
|
610
|
+
ensure_service!
|
611
|
+
Table.create(
|
612
|
+
service,
|
613
|
+
instance_id,
|
614
|
+
name,
|
615
|
+
column_families: column_families,
|
616
|
+
granularity: granularity,
|
617
|
+
initial_splits: initial_splits,
|
618
|
+
&block
|
619
|
+
)
|
620
|
+
end
|
621
|
+
|
622
|
+
##
|
623
|
+
# Creates an app profile for the instance with a routing policy.
|
624
|
+
# Only one routing policy can applied to the app profile. The policy can be
|
625
|
+
# multi-cluster routing or single cluster routing.
|
626
|
+
#
|
627
|
+
# @param name [String] Unique ID of the app profile.
|
628
|
+
# @param routing_policy [Google::Cloud::Bigtable::RoutingPolicy]
|
629
|
+
# The routing policy for all read/write requests that use this app
|
630
|
+
# profile. A value must be explicitly set.
|
631
|
+
#
|
632
|
+
# Routing Policies:
|
633
|
+
# * {Google::Cloud::Bigtable::MultiClusterRoutingUseAny} - Read/write
|
634
|
+
# requests may be routed to any cluster in the instance and will
|
635
|
+
# fail over to another cluster in the event of transient errors or
|
636
|
+
# delays. Choosing this option sacrifices read-your-writes
|
637
|
+
# consistency to improve availability.
|
638
|
+
# * {Google::Cloud::Bigtable::SingleClusterRouting} - Unconditionally
|
639
|
+
# routes all read/write requests to a specific cluster. This option
|
640
|
+
# preserves read-your-writes consistency but does not improve
|
641
|
+
# availability. Value contains `cluster_id` and optional field
|
642
|
+
# `allow_transactional_writes`.
|
643
|
+
# @param description [String] Description of the use case for this app profile.
|
644
|
+
# @param etag [String]
|
645
|
+
# Strongly validated etag for optimistic concurrency control. Preserve the
|
646
|
+
# value returned from `GetAppProfile` when calling `UpdateAppProfile` to
|
647
|
+
# fail the request if there has been a modification in the meantime. The
|
648
|
+
# `update_mask` of the request need not include `etag` for this protection
|
649
|
+
# to apply.
|
650
|
+
# See [Wikipedia](https://en.wikipedia.org/wiki/HTTP_ETag) and
|
651
|
+
# [RFC 7232](https://tools.ietf.org/html/rfc7232#section-2.3) for more details.
|
652
|
+
# @param ignore_warnings [Boolean]
|
653
|
+
# If true, ignore safety checks when creating the app profile.
|
654
|
+
# Default value is `false`.
|
655
|
+
# @return [Google::Cloud::Bigtable::AppProfile]
|
656
|
+
#
|
657
|
+
# @example Create an app profile with a single cluster routing policy.
|
658
|
+
# require "google/cloud/bigtable"
|
659
|
+
#
|
660
|
+
# bigtable = Google::Cloud::Bigtable.new
|
661
|
+
#
|
662
|
+
# instance = bigtable.instance("my-instance")
|
663
|
+
#
|
664
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
|
665
|
+
# "my-instance-cluster-1",
|
666
|
+
# allow_transactional_writes: true
|
667
|
+
# )
|
668
|
+
#
|
669
|
+
# app_profile = instance.create_app_profile(
|
670
|
+
# "my-app-profile",
|
671
|
+
# routing_policy,
|
672
|
+
# description: "App profile for user data instance"
|
673
|
+
# )
|
674
|
+
# puts app_profile.name
|
675
|
+
#
|
676
|
+
# @example Create an app profile with multi-cluster routing policy.
|
677
|
+
# require "google/cloud/bigtable"
|
678
|
+
#
|
679
|
+
# bigtable = Google::Cloud::Bigtable.new
|
680
|
+
#
|
681
|
+
# instance = bigtable.instance("my-instance")
|
682
|
+
#
|
683
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
|
684
|
+
#
|
685
|
+
# app_profile = instance.create_app_profile(
|
686
|
+
# "my-app-profile",
|
687
|
+
# routing_policy,
|
688
|
+
# description: "App profile for user data instance"
|
689
|
+
# )
|
690
|
+
# puts app_profile.name
|
691
|
+
#
|
692
|
+
# @example Create app profile and ignore warnings.
|
693
|
+
# require "google/cloud/bigtable"
|
694
|
+
#
|
695
|
+
# bigtable = Google::Cloud::Bigtable.new
|
696
|
+
#
|
697
|
+
# instance = bigtable.instance("my-instance")
|
698
|
+
#
|
699
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
|
700
|
+
#
|
701
|
+
# app_profile = instance.create_app_profile(
|
702
|
+
# "my-app-profile",
|
703
|
+
# routing_policy,
|
704
|
+
# description: "App profile for user data instance",
|
705
|
+
# ignore_warnings: true
|
706
|
+
# )
|
707
|
+
# puts app_profile.name
|
708
|
+
#
|
709
|
+
def create_app_profile name, routing_policy, description: nil, etag: nil, ignore_warnings: false
|
710
|
+
ensure_service!
|
711
|
+
routing_policy_grpc = routing_policy.to_grpc
|
712
|
+
if routing_policy_grpc.is_a? Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny
|
713
|
+
multi_cluster_routing = routing_policy_grpc
|
714
|
+
else
|
715
|
+
single_cluster_routing = routing_policy_grpc
|
716
|
+
end
|
717
|
+
|
718
|
+
app_profile_attrs = {
|
719
|
+
multi_cluster_routing_use_any: multi_cluster_routing,
|
720
|
+
single_cluster_routing: single_cluster_routing,
|
721
|
+
description: description,
|
722
|
+
etag: etag
|
723
|
+
}.delete_if { |_, v| v.nil? }
|
724
|
+
|
725
|
+
grpc = service.create_app_profile(
|
726
|
+
instance_id,
|
727
|
+
name,
|
728
|
+
Google::Bigtable::Admin::V2::AppProfile.new(app_profile_attrs),
|
729
|
+
ignore_warnings: ignore_warnings
|
730
|
+
)
|
731
|
+
AppProfile.from_grpc grpc, service
|
732
|
+
end
|
733
|
+
|
734
|
+
##
|
735
|
+
# Gets an app profile in the instance.
|
736
|
+
#
|
737
|
+
# See {Google::Cloud::Bigtable::AppProfile#delete} and
|
738
|
+
# {Google::Cloud::Bigtable::AppProfile#save}.
|
739
|
+
#
|
740
|
+
# @param app_profile_id [String] The unique name of the requested app profile.
|
741
|
+
# @return [Google::Cloud::Bigtable::AppProfile, nil]
|
742
|
+
#
|
743
|
+
# @example
|
744
|
+
# require "google/cloud/bigtable"
|
745
|
+
#
|
746
|
+
# bigtable = Google::Cloud::Bigtable.new
|
747
|
+
#
|
748
|
+
# instance = bigtable.instance("my-instance")
|
749
|
+
#
|
750
|
+
# app_profile = instance.app_profile("my-app-profile")
|
751
|
+
#
|
752
|
+
# if app_profile
|
753
|
+
# puts app_profile.name
|
754
|
+
# end
|
755
|
+
#
|
756
|
+
def app_profile app_profile_id
|
757
|
+
ensure_service!
|
758
|
+
grpc = service.get_app_profile instance_id, app_profile_id
|
759
|
+
AppProfile.from_grpc grpc, service
|
760
|
+
rescue Google::Cloud::NotFoundError
|
761
|
+
nil
|
762
|
+
end
|
763
|
+
|
764
|
+
##
|
765
|
+
# Lists all app profiles in the instance.
|
766
|
+
#
|
767
|
+
# See {Google::Cloud::Bigtable::AppProfile#delete} and
|
768
|
+
# {Google::Cloud::Bigtable::AppProfile#save}.
|
769
|
+
#
|
770
|
+
# @return [Array<Google::Cloud::Bigtable::AppProfile>]
|
771
|
+
# (See {Google::Cloud::Bigtable::AppProfile::List})
|
772
|
+
#
|
773
|
+
# @example
|
774
|
+
# require "google/cloud/bigtable"
|
775
|
+
#
|
776
|
+
# bigtable = Google::Cloud::Bigtable.new
|
777
|
+
#
|
778
|
+
# instance = bigtable.instance("my-instance")
|
779
|
+
#
|
780
|
+
# instance.app_profiles.all do |app_profile|
|
781
|
+
# puts app_profile.name
|
782
|
+
# end
|
783
|
+
#
|
784
|
+
def app_profiles
|
785
|
+
ensure_service!
|
786
|
+
grpc = service.list_app_profiles instance_id
|
787
|
+
AppProfile::List.from_grpc grpc, service
|
788
|
+
end
|
789
|
+
|
790
|
+
##
|
791
|
+
# Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
|
792
|
+
# policy for the instance.
|
793
|
+
#
|
794
|
+
# @see https://cloud.google.com/bigtable/docs/access-control
|
795
|
+
#
|
796
|
+
# @yield [policy] A block for updating the policy. The latest policy
|
797
|
+
# will be read from the Bigtable service and passed to the block. After
|
798
|
+
# the block completes, the modified policy will be written to the
|
799
|
+
# service.
|
800
|
+
# @yieldparam [Policy] policy the current Cloud IAM Policy for this
|
801
|
+
# instance.
|
802
|
+
#
|
803
|
+
# @return [Policy] The current Cloud IAM Policy for the instance.
|
804
|
+
#
|
805
|
+
# @example
|
806
|
+
# require "google/cloud/bigtable"
|
807
|
+
#
|
808
|
+
# bigtable = Google::Cloud::Bigtable.new
|
809
|
+
#
|
810
|
+
# instance = bigtable.instance("my-instance")
|
811
|
+
# policy = instance.policy
|
812
|
+
#
|
813
|
+
# @example Update the policy by passing a block.
|
814
|
+
# require "google/cloud/bigtable"
|
815
|
+
#
|
816
|
+
# bigtable = Google::Cloud::Bigtable.new
|
817
|
+
# instance = bigtable.instance("my-instance")
|
818
|
+
#
|
819
|
+
# instance.policy do |p|
|
820
|
+
# p.add("roles/owner", "user:owner@example.com")
|
821
|
+
# end # 2 API calls
|
822
|
+
#
|
823
|
+
def policy
|
824
|
+
ensure_service!
|
825
|
+
grpc = service.get_instance_policy instance_id
|
826
|
+
policy = Policy.from_grpc grpc
|
827
|
+
return policy unless block_given?
|
828
|
+
yield policy
|
829
|
+
update_policy policy
|
830
|
+
end
|
831
|
+
|
832
|
+
##
|
833
|
+
# Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
|
834
|
+
# policy for the instance. The policy should be read from {#policy}.
|
835
|
+
# See {Google::Cloud::Bigtable::Policy} for an explanation of the policy
|
836
|
+
# `etag` property and how to modify policies.
|
837
|
+
#
|
838
|
+
# You can also update the policy by passing a block to {#policy}, which
|
839
|
+
# will call this method internally after the block completes.
|
840
|
+
#
|
841
|
+
# @param new_policy [Policy] a new or modified Cloud IAM Policy for this
|
842
|
+
# instance
|
843
|
+
#
|
844
|
+
# @return [Policy] The policy returned by the API update operation.
|
845
|
+
#
|
846
|
+
# @example
|
847
|
+
# require "google/cloud/bigtable"
|
848
|
+
#
|
849
|
+
# bigtable = Google::Cloud::Bigtable.new
|
850
|
+
#
|
851
|
+
# instance = bigtable.instance("my-instance")
|
852
|
+
#
|
853
|
+
# policy = instance.policy
|
854
|
+
# policy.add("roles/owner", "user:owner@example.com")
|
855
|
+
# updated_policy = instance.update_policy(policy)
|
856
|
+
#
|
857
|
+
# puts updated_policy.roles
|
858
|
+
#
|
859
|
+
def update_policy new_policy
|
860
|
+
ensure_service!
|
861
|
+
grpc = service.set_instance_policy instance_id, new_policy.to_grpc
|
862
|
+
Policy.from_grpc grpc
|
863
|
+
end
|
864
|
+
alias policy= update_policy
|
865
|
+
|
866
|
+
##
|
867
|
+
# Tests the specified permissions against the [Cloud
|
868
|
+
# IAM](https://cloud.google.com/iam/) access control policy.
|
869
|
+
#
|
870
|
+
# @see https://cloud.google.com/iam/docs/managing-policies Managing Policies
|
871
|
+
# @see https://cloud.google.com/bigtable/docs/access-control Access Control
|
872
|
+
#
|
873
|
+
# @param permissions [String, Array<String>] permissions The set of permissions to
|
874
|
+
# check access for. Permissions with wildcards (such as `*` or
|
875
|
+
# `bigtable.*`) are not allowed.
|
876
|
+
# See [Access Control](https://cloud.google.com/bigtable/docs/access-control).
|
877
|
+
#
|
878
|
+
# Some of the permissions that can be checked on a instance are:
|
879
|
+
# * bigtable.instances.create
|
880
|
+
# * bigtable.instances.list
|
881
|
+
# * bigtable.instances.get
|
882
|
+
# * bigtable.tables.create
|
883
|
+
# * bigtable.tables.delete
|
884
|
+
# * bigtable.tables.get
|
885
|
+
# * bigtable.tables.list
|
886
|
+
#
|
887
|
+
# @return [Array<String>] The permissions that are configured for the policy.
|
888
|
+
#
|
889
|
+
# @example
|
890
|
+
# require "google/cloud/bigtable"
|
891
|
+
#
|
892
|
+
# bigtable = Google::Cloud::Bigtable.new
|
893
|
+
#
|
894
|
+
# instance = bigtable.instance("my-instance")
|
895
|
+
#
|
896
|
+
# permissions = instance.test_iam_permissions(
|
897
|
+
# "bigtable.instances.get",
|
898
|
+
# "bigtable.instances.update"
|
899
|
+
# )
|
900
|
+
# permissions.include? "bigtable.instances.get" #=> true
|
901
|
+
# permissions.include? "bigtable.instances.update" #=> false
|
902
|
+
#
|
903
|
+
def test_iam_permissions *permissions
|
904
|
+
ensure_service!
|
905
|
+
grpc = service.test_instance_permissions instance_id, permissions.flatten
|
906
|
+
grpc.permissions.to_a
|
907
|
+
end
|
908
|
+
|
909
|
+
# @private
|
910
|
+
#
|
911
|
+
# Creates a new Instance instance from a
|
912
|
+
# Google::Bigtable::Admin::V2::Instance.
|
913
|
+
#
|
914
|
+
# @param grpc [Google::Bigtable::Admin::V2::Instance]
|
915
|
+
# @param service [Google::Cloud::Bigtable::Service]
|
916
|
+
# @return [Google::Cloud::Bigtable::Instance]
|
917
|
+
#
|
918
|
+
def self.from_grpc grpc, service
|
919
|
+
new grpc, service
|
920
|
+
end
|
921
|
+
|
922
|
+
protected
|
923
|
+
|
924
|
+
# @private
|
925
|
+
#
|
926
|
+
# Raise an error unless an active connection to the service is
|
927
|
+
# available.
|
928
|
+
#
|
929
|
+
def ensure_service!
|
930
|
+
raise "Must have active connection to service" unless service
|
931
|
+
end
|
932
|
+
end
|
933
|
+
end
|
934
|
+
end
|
935
|
+
end
|