google-cloud-bigtable 2.2.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/CONTRIBUTING.md +3 -4
  4. data/LOGGING.md +1 -1
  5. data/OVERVIEW.md +1 -1
  6. data/lib/google/cloud/bigtable/app_profile/list.rb +2 -2
  7. data/lib/google/cloud/bigtable/backup.rb +55 -4
  8. data/lib/google/cloud/bigtable/backup/list.rb +2 -2
  9. data/lib/google/cloud/bigtable/chunk_processor.rb +4 -3
  10. data/lib/google/cloud/bigtable/cluster.rb +22 -2
  11. data/lib/google/cloud/bigtable/cluster/list.rb +2 -2
  12. data/lib/google/cloud/bigtable/column_family.rb +4 -0
  13. data/lib/google/cloud/bigtable/column_family_map.rb +2 -0
  14. data/lib/google/cloud/bigtable/convert.rb +12 -0
  15. data/lib/google/cloud/bigtable/encryption_info.rb +118 -0
  16. data/lib/google/cloud/bigtable/gc_rule.rb +2 -0
  17. data/lib/google/cloud/bigtable/instance.rb +1 -0
  18. data/lib/google/cloud/bigtable/instance/cluster_map.rb +61 -21
  19. data/lib/google/cloud/bigtable/instance/list.rb +2 -2
  20. data/lib/google/cloud/bigtable/mutation_entry.rb +6 -3
  21. data/lib/google/cloud/bigtable/mutation_operations.rb +2 -1
  22. data/lib/google/cloud/bigtable/policy.rb +2 -1
  23. data/lib/google/cloud/bigtable/project.rb +4 -3
  24. data/lib/google/cloud/bigtable/routing_policy.rb +3 -1
  25. data/lib/google/cloud/bigtable/row.rb +5 -1
  26. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +6 -1
  27. data/lib/google/cloud/bigtable/rows_reader.rb +6 -6
  28. data/lib/google/cloud/bigtable/service.rb +6 -3
  29. data/lib/google/cloud/bigtable/status.rb +4 -1
  30. data/lib/google/cloud/bigtable/table.rb +62 -19
  31. data/lib/google/cloud/bigtable/table/cluster_state.rb +43 -9
  32. data/lib/google/cloud/bigtable/table/list.rb +2 -2
  33. data/lib/google/cloud/bigtable/table/restore_job.rb +1 -1
  34. data/lib/google/cloud/bigtable/value_range.rb +24 -6
  35. data/lib/google/cloud/bigtable/version.rb +1 -1
  36. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c055b86b9d279e27fdb78ec71ddb8babd48661349c0404db696496c84fb3d8e1
4
- data.tar.gz: 4c3557a421b16d56680b9c9a39f1d5073a6886efe5198262df0ca02494a000be
3
+ metadata.gz: 4349eaa8149e90524a1966a96fcdb6e1c1faee050c25487e594ee6aa87318681
4
+ data.tar.gz: 0f34a5bee198253cf893e5209dd3230276663a494f94d16734de89e366e2c322
5
5
  SHA512:
6
- metadata.gz: da4f265ebb057cc6e291104edf56cfdf121efc9a75def53dbc9831aba3708049eb68a53c378c147c9f49277afa8cf46822ce01c4e11aa8fcefd907522408862c
7
- data.tar.gz: 79be648c3e85fe49e9a285fcdec140e16e015e510b8d5327a802c0e1d36b825d4c4ab2cb52f63c9d5e8b96ef3177c0f91648ea56e5aac5c045ffba90e0a1c101
6
+ metadata.gz: bf6355506c1a29fe2a2a149a36cce4b1e80c9713f317c76ea707353a7828f1a299cb6fc2daeb7beea537cc7ae792e7ffed9ccacc0dd22fc49eedb03a63ee26a0
7
+ data.tar.gz: bbded4a5e2d126580c68df77aa1171d6d8c9f222237dc5fc9a8fe8dafbb13e9c110b65800ea67018e902e3250ea23b9a2cf3ba29bf64653052be16b4c782b7b7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # Release History
2
2
 
3
+ ### 2.6.0 / 2021-05-03
4
+
5
+ #### Features
6
+
7
+ * Add support for Backup restore to different Instance
8
+ * Add instance to Backup#restore
9
+
10
+ ### 2.5.0 / 2021-04-20
11
+
12
+ #### Features
13
+
14
+ * Add CMEK support
15
+ * Add kms_key to ClusterMap#add
16
+ * Add Cluster#kms_key
17
+ * Add EncryptionInfo
18
+ * Add ClusterState#encryption_infos
19
+ * Add ENCRYPTION_VIEW support to Table
20
+ * Update docs in Table::ClusterState
21
+ * Add Backup#encryption_info
22
+
23
+ ### 2.4.1 / 2021-04-01
24
+
25
+ #### Bug Fixes
26
+
27
+ * Update internal management of view states in Table
28
+
29
+ ### 2.4.0 / 2021-03-10
30
+
31
+ #### Features
32
+
33
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
34
+
35
+ #### Documentation
36
+
37
+ * Add link to Garbage collection docs
38
+
39
+ ### 2.3.0 / 2021-02-04
40
+
41
+ #### Features
42
+
43
+ * Add integer support to RowFilter#value and ValueRange
44
+ * Encode Integer arguments as 64-bit signed big-endian integer data
45
+
3
46
  ### 2.2.1 / 2021-01-13
4
47
 
5
48
  #### Documentation
data/CONTRIBUTING.md CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
24
24
  In order to use the google-cloud-bigtable console and run the project's tests,
25
25
  there is a small amount of setup:
26
26
 
27
- 1. Install Ruby. google-cloud-bigtable requires Ruby 2.4+. You may choose to
27
+ 1. Install Ruby. google-cloud-bigtable requires Ruby 2.5+. You may choose to
28
28
  manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
29
  [rbenv](https://github.com/rbenv/rbenv), or
30
30
  [chruby](https://github.com/postmodern/chruby).
@@ -119,15 +119,14 @@ If you alter an example's title, you may encounter breaking tests.
119
119
  ### Bigtable Acceptance Tests
120
120
 
121
121
  The Bigtable acceptance tests interact with the live service API. Follow the
122
- instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
122
+ instructions in the {file:AUTHENTICATION.md Authentication Guide} for enabling
123
123
  the Bigtable API. Occasionally, some API features may not yet be generally
124
124
  available, making it difficult for some contributors to successfully run the
125
125
  entire acceptance test suite. However, please ensure that you do successfully
126
126
  run acceptance tests for any code areas covered by your pull request.
127
127
 
128
128
  To run the acceptance tests, first create and configure a project in the Google
129
- Developers Console, as described in the {file:AUTHENTICATION.md Authentication
130
- guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
129
+ Developers Console, as described in the {file:AUTHENTICATION.md Authentication Guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
131
130
  the KEYFILE location on your system.
132
131
 
133
132
  Before you can run the Bigtable acceptance tests, you must first create indexes
data/LOGGING.md CHANGED
@@ -3,7 +3,7 @@
3
3
  To enable logging for this library, set the logger for the underlying
4
4
  [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
5
5
  that you set may be a Ruby stdlib
6
- [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
6
+ [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as
7
7
  shown below, or a
8
8
  [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
9
9
  that will write logs to [Stackdriver
data/OVERVIEW.md CHANGED
@@ -396,5 +396,5 @@ instance.delete
396
396
  ## Additional information
397
397
 
398
398
  Google Bigtable can be configured to use an emulator or to enable gRPC's
399
- logging. To learn more, see the {file:EMULATOR.md Emulator guide} and
399
+ logging. To learn more, see the {file:EMULATOR.md Emulator guide}} and
400
400
  {file:LOGGING.md Logging guide}.
@@ -122,12 +122,12 @@ module Google
122
122
  # app_profile.name
123
123
  # end
124
124
  #
125
- def all
125
+ def all &block
126
126
  return enum_for :all unless block_given?
127
127
 
128
128
  results = self
129
129
  loop do
130
- results.each { |r| yield r }
130
+ results.each(&block)
131
131
  break unless next?
132
132
  grpc.next_page
133
133
  results = self.class.from_grpc grpc, service
@@ -18,10 +18,10 @@
18
18
  require "google/cloud/bigtable/backup/job"
19
19
  require "google/cloud/bigtable/backup/list"
20
20
  require "google/cloud/bigtable/convert"
21
+ require "google/cloud/bigtable/encryption_info"
21
22
  require "google/cloud/bigtable/policy"
22
23
  require "google/cloud/bigtable/table/restore_job"
23
24
 
24
-
25
25
  module Google
26
26
  module Cloud
27
27
  module Bigtable
@@ -207,6 +207,27 @@ module Google
207
207
  state == :READY
208
208
  end
209
209
 
210
+ ##
211
+ # The encryption information for the backup. See also {Instance::ClusterMap#add}.
212
+ #
213
+ # @return [Google::Cloud::Bigtable::EncryptionInfo] The encryption information for the backup.
214
+ #
215
+ # @example
216
+ # require "google/cloud/bigtable"
217
+ #
218
+ # bigtable = Google::Cloud::Bigtable.new
219
+ # instance = bigtable.instance("my-instance")
220
+ # cluster = instance.cluster("my-cluster")
221
+ #
222
+ # backup = cluster.backup("my-backup")
223
+ #
224
+ # encryption_info = backup.encryption_info
225
+ # encryption_info.encryption_type #=> :GOOGLE_DEFAULT_ENCRYPTION
226
+ #
227
+ def encryption_info
228
+ EncryptionInfo.from_grpc @grpc.encryption_info
229
+ end
230
+
210
231
  ##
211
232
  # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
212
233
  # policy for the backup.
@@ -328,9 +349,12 @@ module Google
328
349
  end
329
350
 
330
351
  ##
331
- # Creates a new table by restoring from a completed backup.
352
+ # Creates a new table by restoring data from a completed backup. The new table may be created in an instance
353
+ # different than that of the backup.
332
354
  #
333
355
  # @param table_id [String] The table ID for the new table. This table must not yet exist. Required.
356
+ # @param instance [Instance, String] The instance or the ID of the instance for the new table, if different from
357
+ # the instance of the backup. Optional.
334
358
  #
335
359
  # @return [Google::Cloud::Bigtable::Table::RestoreJob] The job representing the long-running, asynchronous
336
360
  # processing of a backup restore table operation.
@@ -356,8 +380,35 @@ module Google
356
380
  # optimized = job.optimize_table_operation_name
357
381
  # end
358
382
  #
359
- def restore table_id
360
- grpc = service.restore_table table_id, instance_id, cluster_id, backup_id
383
+ # @example Create the table in a different instance.
384
+ # require "google/cloud/bigtable"
385
+ #
386
+ # bigtable = Google::Cloud::Bigtable.new
387
+ # instance = bigtable.instance("my-instance")
388
+ # cluster = instance.cluster("my-cluster")
389
+ #
390
+ # backup = cluster.backup("my-backup")
391
+ #
392
+ # table_instance = bigtable.instance("my-other-instance")
393
+ # job = backup.restore("my-new-table", instance: table_instance)
394
+ #
395
+ # job.wait_until_done!
396
+ # job.done? #=> true
397
+ #
398
+ # if job.error?
399
+ # status = job.error
400
+ # else
401
+ # table = job.table
402
+ # optimized = job.optimize_table_operation_name
403
+ # end
404
+ #
405
+ def restore table_id, instance: nil
406
+ table_instance_id = instance.respond_to?(:instance_id) ? instance.instance_id : instance
407
+ grpc = service.restore_table table_id,
408
+ instance_id,
409
+ cluster_id,
410
+ backup_id,
411
+ table_instance_id: table_instance_id
361
412
  Table::RestoreJob.from_grpc grpc, service
362
413
  end
363
414
 
@@ -124,12 +124,12 @@ module Google
124
124
  # backup.backup_id
125
125
  # end
126
126
  #
127
- def all
127
+ def all &block
128
128
  return enum_for :all unless block_given?
129
129
 
130
130
  results = self
131
131
  loop do
132
- results.each { |r| yield r }
132
+ results.each(&block)
133
133
  break unless next?
134
134
  grpc.next_page
135
135
  results = self.class.from_grpc grpc, service
@@ -57,11 +57,12 @@ module Google
57
57
 
58
58
  raise_if chunk.value_size.positive?, "Commit rows cannot have a non-zero value_size." if chunk.commit_row
59
59
 
60
- if state == NEW_ROW
60
+ case state
61
+ when NEW_ROW
61
62
  process_new_row
62
- elsif state == CELL_IN_PROGRESS
63
+ when CELL_IN_PROGRESS
63
64
  process_cell_in_progress
64
- elsif state == ROW_IN_PROGRESS
65
+ when ROW_IN_PROGRESS
65
66
  process_row_in_progress
66
67
  end
67
68
  end
@@ -168,8 +168,10 @@ module Google
168
168
  ##
169
169
  # The type of storage used by this cluster to serve its
170
170
  # parent instance's tables, unless explicitly overridden.
171
- # Valid values are `:SSD`(Flash (SSD) storage should be used),
172
- # `:HDD`(Magnetic drive (HDD) storage should be used)
171
+ # Valid values are:
172
+ #
173
+ # * `:SSD` - Flash (SSD) storage should be used.
174
+ # * `:HDD` - Magnetic drive (HDD) storage should be used.
173
175
  #
174
176
  # @return [Symbol]
175
177
  #
@@ -197,6 +199,24 @@ module Google
197
199
  @grpc.location
198
200
  end
199
201
 
202
+ ##
203
+ # The full name of the Cloud KMS encryption key for the cluster, if it is CMEK-protected, in the format
204
+ # `projects/{key_project_id}/locations/{location}/keyRings/{ring_name}/cryptoKeys/{key_name}`.
205
+ #
206
+ # The requirements for this key are:
207
+ #
208
+ # 1. The Cloud Bigtable service account associated with the project that contains this cluster must be granted
209
+ # the `cloudkms.cryptoKeyEncrypterDecrypter` role on the CMEK key.
210
+ # 2. Only regional keys can be used and the region of the CMEK key must match the region of the cluster.
211
+ # 3. All clusters within an instance must use the same CMEK key.
212
+ #
213
+ # @return [String, nil] The full name of the Cloud KMS encryption key, or `nil` if the cluster is not
214
+ # CMEK-protected.
215
+ #
216
+ def kms_key
217
+ @grpc.encryption_config&.kms_key_name
218
+ end
219
+
200
220
  ##
201
221
  # Creates a new Cloud Bigtable Backup.
202
222
  #
@@ -129,12 +129,12 @@ module Google
129
129
  # puts cluster.cluster_id
130
130
  # end
131
131
  #
132
- def all
132
+ def all &block
133
133
  return enum_for :all unless block_given?
134
134
 
135
135
  results = self
136
136
  loop do
137
- results.each { |r| yield r }
137
+ results.each(&block)
138
138
  break unless results.next?
139
139
  results = results.next
140
140
  end
@@ -45,7 +45,11 @@ module Google
45
45
  ##
46
46
  # The garbage collection rule to be used for the column family.
47
47
  # Optional. The service default value will be used when not specified.
48
+ #
49
+ # @see https://cloud.google.com/bigtable/docs/garbage-collection Garbage collection
50
+ #
48
51
  # @return [Google::Cloud::Bigtable::GcRule, nil]
52
+ #
49
53
  attr_accessor :gc_rule
50
54
 
51
55
  # @private
@@ -222,6 +222,8 @@ module Google
222
222
  ##
223
223
  # Updates an existing column family in the table.
224
224
  #
225
+ # @see https://cloud.google.com/bigtable/docs/garbage-collection Garbage collection
226
+ #
225
227
  # @param name [String] Column family name.
226
228
  # @param gc_rule [Google::Cloud::Bigtable::GcRule] The new garbage
227
229
  # collection rule to be used for the column family. Optional. The
@@ -77,6 +77,18 @@ module Google
77
77
 
78
78
  Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec
79
79
  end
80
+
81
+ ##
82
+ # Converts an Integer to 64-bit signed big-endian integer data.
83
+ # Returns a string argument unchanged.
84
+ #
85
+ # @param value [String, Integer]
86
+ # @return [String]
87
+ #
88
+ def integer_to_signed_be_64 value
89
+ return [value].pack "q>" if value.is_a? Integer
90
+ value
91
+ end
80
92
  end
81
93
  end
82
94
  end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 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/status"
19
+
20
+ module Google
21
+ module Cloud
22
+ module Bigtable
23
+ ##
24
+ # # EncryptionInfo
25
+ #
26
+ # Encryption information for a given resource.
27
+ #
28
+ # See {Backup#encryption_info} and {Table::ClusterState#encryption_infos}.
29
+ #
30
+ # @example
31
+ # require "google/cloud/bigtable"
32
+ #
33
+ # bigtable = Google::Cloud::Bigtable.new
34
+ # instance = bigtable.instance("my-instance")
35
+ # cluster = instance.cluster("my-cluster")
36
+ #
37
+ # backup = cluster.backup("my-backup")
38
+ #
39
+ # encryption_info = backup.encryption_info
40
+ # encryption_info.encryption_type #=> :GOOGLE_DEFAULT_ENCRYPTION
41
+ #
42
+ # @example Retrieve a table with cluster states containing encryption info.
43
+ # require "google/cloud/bigtable"
44
+ #
45
+ # bigtable = Google::Cloud::Bigtable.new
46
+ #
47
+ # table = bigtable.table("my-instance", "my-table", view: :ENCRYPTION_VIEW, perform_lookup: true)
48
+ #
49
+ # table.cluster_states.each do |cs|
50
+ # puts cs.cluster_name
51
+ # puts cs.encryption_infos.first.encryption_type
52
+ # end
53
+ #
54
+ class EncryptionInfo
55
+ # @private
56
+ #
57
+ # Creates a new EncryptionInfo instance.
58
+ def initialize grpc
59
+ @grpc = grpc
60
+ end
61
+
62
+ ##
63
+ # The type of encryption used to protect the resource. Possible values:
64
+ #
65
+ # * `ENCRYPTION_TYPE_UNSPECIFIED` - Encryption type was not specified, though data at rest remains encrypted.
66
+ # * `GOOGLE_DEFAULT_ENCRYPTION` - The data backing the resource is encrypted at rest with a key that is
67
+ # fully managed by Google. No key version or status will be populated. This is the default state.
68
+ # * `CUSTOMER_MANAGED_ENCRYPTION` - The data backing the resource is encrypted at rest with a key that is
69
+ # managed by the customer. The in-use version of the key and its status are populated for CMEK-protected
70
+ # tables. CMEK-protected backups are pinned to the key version that was in use at the time the backup was
71
+ # taken. This key version is populated but its status is not tracked and is reported as `UNKNOWN`.
72
+ #
73
+ # See also {#encryption_status}, {#kms_key_version} and {Instance::ClusterMap#add}.
74
+ #
75
+ # @return [Symbol] The encryption type code as an uppercase symbol.
76
+ #
77
+ def encryption_type
78
+ @grpc.encryption_type
79
+ end
80
+
81
+ ##
82
+ # The status of encrypt/decrypt calls on underlying data for the resource. Regardless of status, the existing
83
+ # data is always encrypted at rest.
84
+ #
85
+ # See also {#encryption_type}, {#kms_key_version} and {Instance::ClusterMap#add}.
86
+ #
87
+ # @return [Google::Cloud::Bigtable::Status, nil] The encryption status object, or `nil` if not present.
88
+ #
89
+ def encryption_status
90
+ status_grpc = @grpc.encryption_status
91
+ Status.from_grpc status_grpc if status_grpc
92
+ end
93
+
94
+ ##
95
+ # The version of the Cloud KMS key specified in the parent cluster that is in use for the data underlying the
96
+ # table.
97
+ #
98
+ # See also {#encryption_type}, {#encryption_status} and {Instance::ClusterMap#add}.
99
+ #
100
+ # @return [String, nil] The Cloud KMS key version, or `nil` if not present.
101
+ #
102
+ def kms_key_version
103
+ @grpc.kms_key_version unless @grpc.kms_key_version.empty?
104
+ end
105
+
106
+ # @private
107
+ #
108
+ # Creates a new EncryptionInfo instance from a Google::Cloud::Bigtable::Admin::V2::EncryptionInfo.
109
+ #
110
+ # @param grpc [Google::Cloud::Bigtable::Admin::V2::EncryptionInfo]
111
+ # @return [Google::Cloud::Bigtable::EncryptionInfo]
112
+ def self.from_grpc grpc
113
+ new grpc
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end