google-cloud-bigquery 1.41.0 → 1.42.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f13891ae7f46f3a0561140fabe4eed4cc426923258e17ed4cc10cc8155f9129
4
- data.tar.gz: 65eb5cfc6fb0feadae0d4503bcf2bd1942a0a9740a6f4f1b6f6aaddf7ee244c0
3
+ metadata.gz: 779c0f4690b370db6eb7811fa6fb8dbca101dff34ff478dcdc51ed1e9c83c083
4
+ data.tar.gz: d1456024ae30a18c93c05d6d8be7eef88dd3f0610cdbf816cf0c46322c9574be
5
5
  SHA512:
6
- metadata.gz: cecf4d1450deb04f33772ebc0bf18892816dda84e9e2b43668615dc37c49b3319465c3d0f3cb9c07ca9cc5a5e7a7118daab1f1aa51c25bf83ebadc925bd52eef
7
- data.tar.gz: c678e3b5420f82894c1d4935f4f89959fda4ea6e66faffa7fb649c0ff3c0e2fec91daf3e77208e02eb4747cf1a3d41ef5764a4b4da8b76b2a03328861121c7c2
6
+ metadata.gz: 6a5da0e2565b0c224f46a6330d138c8fb35831e874ebc2364fd3b91578d400354011d1e9df7d2986dbe2398f610776b130b7eb9305af8282bf3a6265dd84aa05
7
+ data.tar.gz: 0d14faa0d89ba6a114e247c362f8a5d4775ae4dc19de1aad0a64083da7e41fc93ac810e876b434056340b27412bb08063af05edf33355800ca1c528ff02f437b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Release History
2
2
 
3
+ ### 1.42.0 (2023-01-15)
4
+
5
+ #### Features
6
+
7
+ * Added support for authorized dataset ([#19442](https://github.com/googleapis/google-cloud-ruby/issues/19442))
8
+ * Added support for tags in dataset ([#19350](https://github.com/googleapis/google-cloud-ruby/issues/19350))
9
+
3
10
  ### 1.41.0 (2023-01-05)
4
11
 
5
12
  #### Features
@@ -61,8 +61,10 @@ module Google
61
61
  "user" => :user_by_email,
62
62
  "user_by_email" => :user_by_email,
63
63
  "userByEmail" => :user_by_email,
64
- "view" => :view
64
+ "view" => :view,
65
+ "dataset" => :dataset
65
66
  }.freeze
67
+ attr_reader :rules
66
68
 
67
69
  # @private
68
70
  GROUPS = {
@@ -267,6 +269,44 @@ module Google
267
269
  add_access_view view
268
270
  end
269
271
 
272
+ ##
273
+ # Add reader access to a dataset.
274
+ #
275
+ # @param [Google::Cloud::Bigquery::DatasetAccessEntry, Hash<String,String> ] dataset A DatasetAccessEntry
276
+ # or a Hash object. Required
277
+ #
278
+ # @example
279
+ # require "google/cloud/bigquery"
280
+ #
281
+ # bigquery = Google::Cloud::Bigquery.new
282
+ # dataset = bigquery.dataset "my_dataset"
283
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
284
+ #
285
+ # params = {
286
+ # dataset_id: other_dataset.dataset_id,
287
+ # project_id: other_dataset.project_id,
288
+ # target_types: ["VIEWS"]
289
+ # }
290
+ #
291
+ # dataset.access do |access|
292
+ # access.add_reader_dataset params
293
+ # end
294
+ #
295
+ # @example
296
+ # require "google/cloud/bigquery"
297
+ #
298
+ # bigquery = Google::Cloud::Bigquery.new
299
+ # dataset = bigquery.dataset "my_dataset"
300
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
301
+ #
302
+ # dataset.access do |access|
303
+ # access.add_reader_dataset other_dataset.access_entry(target_types: ["VIEWS"])
304
+ # end
305
+ #
306
+ def add_reader_dataset dataset
307
+ add_access_dataset dataset
308
+ end
309
+
270
310
  ##
271
311
  # Add writer access to a user.
272
312
  #
@@ -610,6 +650,44 @@ module Google
610
650
  remove_access_view view
611
651
  end
612
652
 
653
+ ##
654
+ # Removes reader access of a dataset.
655
+ #
656
+ # @param [Google::Cloud::Bigquery::DatasetAccessEntry, Hash<String,String> ] dataset A DatasetAccessEntry
657
+ # or a Hash object. Required
658
+ #
659
+ # @example
660
+ # require "google/cloud/bigquery"
661
+ #
662
+ # bigquery = Google::Cloud::Bigquery.new
663
+ # dataset = bigquery.dataset "my_dataset"
664
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
665
+ #
666
+ # params = {
667
+ # dataset_id: other_dataset.dataset_id,
668
+ # project_id: other_dataset.project_id,
669
+ # target_types: ["VIEWS"]
670
+ # }
671
+ #
672
+ # dataset.access do |access|
673
+ # access.remove_reader_dataset params
674
+ # end
675
+ #
676
+ # @example
677
+ # require "google/cloud/bigquery"
678
+ #
679
+ # bigquery = Google::Cloud::Bigquery.new
680
+ # dataset = bigquery.dataset "my_dataset"
681
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
682
+ #
683
+ # dataset.access do |access|
684
+ # access.remove_reader_dataset other_dataset.access_entry(target_types: ["VIEWS"])
685
+ # end
686
+ #
687
+ def remove_reader_dataset dataset
688
+ remove_access_dataset dataset
689
+ end
690
+
613
691
  ##
614
692
  # Remove writer access from a user.
615
693
  #
@@ -951,6 +1029,40 @@ module Google
951
1029
  lookup_access_view view
952
1030
  end
953
1031
 
1032
+ ##
1033
+ # Checks reader access for a dataset.
1034
+ #
1035
+ # @param [Google::Cloud::Bigquery::DatasetAccessEntry, Hash<String,String> ] dataset A DatasetAccessEntry
1036
+ # or a Hash object. Required
1037
+ #
1038
+ # @example
1039
+ # require "google/cloud/bigquery"
1040
+ #
1041
+ # bigquery = Google::Cloud::Bigquery.new
1042
+ # dataset = bigquery.dataset "my_dataset"
1043
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
1044
+ #
1045
+ # params = {
1046
+ # dataset_id: other_dataset.dataset_id,
1047
+ # project_id: other_dataset.project_id,
1048
+ # target_types: ["VIEWS"]
1049
+ # }
1050
+ #
1051
+ # dataset.access.reader_dataset? params
1052
+ #
1053
+ # @example
1054
+ # require "google/cloud/bigquery"
1055
+ #
1056
+ # bigquery = Google::Cloud::Bigquery.new
1057
+ # dataset = bigquery.dataset "my_dataset"
1058
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
1059
+ #
1060
+ # dataset.access.reader_dataset? other_dataset.access_entry(target_types: ["VIEWS"])
1061
+ #
1062
+ def reader_dataset? dataset
1063
+ lookup_access_dataset dataset
1064
+ end
1065
+
954
1066
  ##
955
1067
  # Checks writer access for a user.
956
1068
  #
@@ -1184,6 +1296,18 @@ module Google
1184
1296
  end
1185
1297
  end
1186
1298
 
1299
+ # @private
1300
+ #
1301
+ # Checks the type of user input and converts it to acceptable format.
1302
+ #
1303
+ def validate_dataset dataset
1304
+ if dataset.is_a? Google::Apis::BigqueryV2::DatasetAccessEntry
1305
+ dataset
1306
+ else
1307
+ Service.dataset_access_entry_from_hash dataset
1308
+ end
1309
+ end
1310
+
1187
1311
  # @private
1188
1312
  def add_access_role_scope_value role, scope, value
1189
1313
  role = validate_role role
@@ -1218,6 +1342,17 @@ module Google
1218
1342
  @rules << Google::Apis::BigqueryV2::Dataset::Access.new(**opts)
1219
1343
  end
1220
1344
 
1345
+ # @private
1346
+ def add_access_dataset dataset
1347
+ # scope is dataset, make sure value is in the right format
1348
+ value = validate_dataset dataset
1349
+ # Remove existing rule for input dataset, if any
1350
+ @rules.reject!(&find_by_scope_and_resource_ref(:dataset, value))
1351
+ # Add new rule for this role, scope, and value
1352
+ opts = { dataset: value }
1353
+ @rules << Google::Apis::BigqueryV2::Dataset::Access.new(**opts)
1354
+ end
1355
+
1221
1356
  # @private
1222
1357
  def remove_access_role_scope_value role, scope, value
1223
1358
  role = validate_role role
@@ -1244,6 +1379,14 @@ module Google
1244
1379
  @rules.reject!(&find_by_scope_and_resource_ref(:view, value))
1245
1380
  end
1246
1381
 
1382
+ # @private
1383
+ def remove_access_dataset dataset
1384
+ # scope is dataset, make sure value is in the right format
1385
+ value = validate_dataset dataset
1386
+ # Remove existing rule for input dataset, if any
1387
+ @rules.reject!(&find_by_scope_and_resource_ref(:dataset, value))
1388
+ end
1389
+
1247
1390
  # @private
1248
1391
  def lookup_access_role_scope_value role, scope, value
1249
1392
  role = validate_role role
@@ -1268,6 +1411,14 @@ module Google
1268
1411
  !(!@rules.detect(&find_by_scope_and_resource_ref(:view, value)))
1269
1412
  end
1270
1413
 
1414
+ # @private
1415
+ def lookup_access_dataset dataset
1416
+ # scope is dataset, make sure value is in the right format
1417
+ value = validate_dataset dataset
1418
+ # Detect existing rule for input dataset, if any
1419
+ !(!@rules.detect(&find_by_scope_and_resource_ref(:dataset, value)))
1420
+ end
1421
+
1271
1422
  # @private
1272
1423
  def find_by_role_and_scope_and_value role, scope, value
1273
1424
  lambda do |a|
@@ -0,0 +1,67 @@
1
+ # Copyright 2022 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
+ require "google/apis/bigquery_v2"
16
+
17
+ module Google
18
+ module Cloud
19
+ module Bigquery
20
+ class Dataset
21
+ ##
22
+ # A global tag managed by Resource Manager.
23
+ #
24
+ # @see https://cloud.google.com/iam/docs/tags-access-control#definitions
25
+ #
26
+ class Tag
27
+ ##
28
+ # @private The Google API Client object.
29
+ attr_accessor :gapi
30
+
31
+ ##
32
+ # @private Create an empty Tag object.
33
+ def initialize
34
+ @gapi = Google::Apis::BigqueryV2::Dataset::Tag.new
35
+ end
36
+
37
+ ##
38
+ # The namespaced friendly name of the tag key, e.g. "12345/environment" where
39
+ # 12345 is org id.
40
+ #
41
+ # @return [String]
42
+ #
43
+ def tag_key
44
+ @gapi.tag_key
45
+ end
46
+
47
+ ##
48
+ # The friendly short name of the tag value, e.g. "production".
49
+ #
50
+ # @return [String]
51
+ #
52
+ def tag_value
53
+ @gapi.tag_value
54
+ end
55
+
56
+ ##
57
+ # @private Google API Client object.
58
+ def self.from_gapi gapi
59
+ new_tag = new
60
+ new_tag.instance_variable_set :@gapi, gapi
61
+ new_tag
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -22,6 +22,7 @@ require "google/cloud/bigquery/routine"
22
22
  require "google/cloud/bigquery/external"
23
23
  require "google/cloud/bigquery/dataset/list"
24
24
  require "google/cloud/bigquery/dataset/access"
25
+ require "google/cloud/bigquery/dataset/tag"
25
26
  require "google/cloud/bigquery/convert"
26
27
  require "google/apis/bigquery_v2"
27
28
 
@@ -466,6 +467,21 @@ module Google
466
467
  access_builder.freeze
467
468
  end
468
469
 
470
+ ##
471
+ # Retrieves the tags associated with this dataset. Tag keys are
472
+ # globally unique, and managed via the resource manager API.
473
+ #
474
+ # @see https://cloud.google.com/resource-manager/docs/tags/tags-overview
475
+ # for more information.
476
+ #
477
+ # @return [Google::Cloud::Bigquery::Dataset::Tag] The list of tags.
478
+ #
479
+ def tags
480
+ ensure_full_data!
481
+ return nil if @gapi.tags.nil?
482
+ @gapi.tags.map { |gapi| Tag.from_gapi(gapi) }
483
+ end
484
+
469
485
  ##
470
486
  # Permanently deletes the dataset. The dataset must be empty before it
471
487
  # can be deleted unless the `force` option is set to `true`.
@@ -2741,6 +2757,29 @@ module Google
2741
2757
  interval: interval, threads: threads, &block
2742
2758
  end
2743
2759
 
2760
+ ##
2761
+ # Build an object of type Google::Apis::BigqueryV2::DatasetAccessEntry from
2762
+ # the self.
2763
+ #
2764
+ # @param [Array<String>] target_types The list of target types within the dataset.
2765
+ #
2766
+ # @return [Google::Apis::BigqueryV2::DatasetAccessEntry] Returns a DatasetAccessEntry object.
2767
+ #
2768
+ # @example
2769
+ # require "google/cloud/bigquery"
2770
+ #
2771
+ # bigquery = Google::Cloud::Bigquery.new
2772
+ # dataset = bigquery.dataset "my_dataset"
2773
+ # dataset_access_entry = dataset.access_entry target_types: ["VIEWS"]
2774
+ #
2775
+ def build_access_entry target_types: nil
2776
+ params = {
2777
+ dataset: dataset_ref,
2778
+ target_types: target_types
2779
+ }.delete_if { |_, v| v.nil? }
2780
+ Google::Apis::BigqueryV2::DatasetAccessEntry.new(**params)
2781
+ end
2782
+
2744
2783
  protected
2745
2784
 
2746
2785
  def insert_data_with_autocreate table_id, rows, skip_invalid: nil, ignore_unknown: nil, insert_ids: nil
@@ -497,6 +497,19 @@ module Google
497
497
  ref
498
498
  end
499
499
 
500
+ ##
501
+ # Converts a hash to a Google::Apis::BigqueryV2::DatasetAccessEntry oject.
502
+ #
503
+ # @param [Hash<String,String>] dataset_hash Hash for a DatasetAccessEntry.
504
+ #
505
+ def self.dataset_access_entry_from_hash dataset_hash
506
+ params = {
507
+ dataset: Google::Apis::BigqueryV2::DatasetReference.new(**dataset_hash),
508
+ target_types: dataset_hash[:target_types]
509
+ }.delete_if { |_, v| v.nil? }
510
+ Google::Apis::BigqueryV2::DatasetAccessEntry.new(**params)
511
+ end
512
+
500
513
  def self.validate_table_ref table_ref
501
514
  [:project_id, :dataset_id, :table_id].each do |f|
502
515
  raise ArgumentError, "TableReference is missing #{f}" if table_ref.send(f).nil?
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigquery
19
- VERSION = "1.41.0".freeze
19
+ VERSION = "1.42.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-bigquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.41.0
4
+ version: 1.42.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-06 00:00:00.000000000 Z
12
+ date: 2023-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -268,6 +268,7 @@ files:
268
268
  - lib/google/cloud/bigquery/dataset.rb
269
269
  - lib/google/cloud/bigquery/dataset/access.rb
270
270
  - lib/google/cloud/bigquery/dataset/list.rb
271
+ - lib/google/cloud/bigquery/dataset/tag.rb
271
272
  - lib/google/cloud/bigquery/encryption_configuration.rb
272
273
  - lib/google/cloud/bigquery/external.rb
273
274
  - lib/google/cloud/bigquery/external/avro_source.rb
@@ -320,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
321
  - !ruby/object:Gem::Version
321
322
  version: '0'
322
323
  requirements: []
323
- rubygems_version: 3.3.14
324
+ rubygems_version: 3.4.2
324
325
  signing_key:
325
326
  specification_version: 4
326
327
  summary: API Client library for Google BigQuery