google-cloud-bigquery 1.21.1 → 1.25.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: 66fb05be59bdce437c28d89670548abba36c23a00df0bbe175983156f7ef4677
4
- data.tar.gz: 73fdc5465df51fe3e3a2f554fa6540d5ffeb0890146eee2b97e60669abb2a020
3
+ metadata.gz: ae4b6e4d7c37a945f027fe56425698b19b430f5e75451ce82f2156f2dae96719
4
+ data.tar.gz: d50284a47bf96d5221b574590a60b3af0f77b3a8943d201fd473d78f41a46670
5
5
  SHA512:
6
- metadata.gz: 3c0857826bc2c7394e9d9fa8ffe4eee947bbd5ed57f9ad636e34718e0b266c7091e4ddd2734619874b7624d1b939e62f7f43a74f6fe944d33b057966dafea188
7
- data.tar.gz: 685a245183d53e26bfc133f6475b949b00ffc33e25eb00dfa1a52e557525bc9e6e61522d435c2398058c188005f535e5b49f79d28e29b8d8d47cb995c5561bea
6
+ metadata.gz: 56c0b2d3214b385efb3866e502faa0b0c28c2fffc0c3d2ca3c5e1ad05f4d69e0638e68d59d8310c68d01c26c3db55b42225944379bfb8f6ad7a57eec558ced3a
7
+ data.tar.gz: 0562b98e65e880a40d634f541285241823354a966f4d05a559463a23eacca54addf8843f89b32731d313a56d91dfe2984f6098630c4126d7dbc97033d3dc6a81
@@ -1,5 +1,56 @@
1
1
  # Release History
2
2
 
3
+ ### 1.25.0 / 2020-11-16
4
+
5
+ #### Features
6
+
7
+ * Add routine (UDF) to Dataset::Access
8
+ * Add support for Table ACLS (IAM Policy)
9
+ * feat(bigquery): Add support for Table ACLS
10
+ * Add Bigquery::Policy
11
+ * Add Table#policy
12
+ * Add Table#test_iam_permissions
13
+ * Add Table#update_policy
14
+
15
+ ### 1.24.0 / 2020-10-29
16
+
17
+ #### Features
18
+
19
+ * Add iamMember to Dataset::Access
20
+
21
+ #### Bug Fixes
22
+
23
+ * Ensure dense encoding of JSON responses
24
+ * Set query param prettyPrint=false for all requests.
25
+ * Upgrade google-api-client to ~> 0.47
26
+
27
+ #### Documentation
28
+
29
+ * Update supported types for time partition type
30
+
31
+ ### 1.23.0 / 2020-09-17
32
+
33
+ #### Features
34
+
35
+ * quota_project can be set via library configuration ([#7627](https://www.github.com/googleapis/google-cloud-ruby/issues/7627))
36
+
37
+ ### 1.22.0 / 2020-09-10
38
+
39
+ #### Features
40
+
41
+ * Add support for ML model export
42
+ * Add model support to Project#extract and #extract_job
43
+ * Add ExtractJob#model?
44
+ * Add ExtractJob#ml_tf_saved_model?
45
+ * Add ExtractJob#ml_xgboost_booster?
46
+ * Add Model#extract and #extract_job
47
+
48
+ ### 1.21.2 / 2020-07-21
49
+
50
+ #### Documentation
51
+
52
+ * Update Data#each samples
53
+
3
54
  ### 1.21.1 / 2020-05-28
4
55
 
5
56
  #### Documentation
@@ -53,9 +53,15 @@ module Google
53
53
  # bigquery = gcloud.bigquery
54
54
  # dataset = bigquery.dataset "my_dataset"
55
55
  # table = dataset.table "my_table"
56
- # table.data.each do |row|
57
- # puts row
56
+ #
57
+ # data = table.data
58
+ #
59
+ # # Iterate over the first page of results
60
+ # data.each do |row|
61
+ # puts row[:name]
58
62
  # end
63
+ # # Retrieve the next page of results
64
+ # data = data.next if data.next?
59
65
  #
60
66
  # @example The default scope can be overridden with the `scope` option:
61
67
  # require "google/cloud"
@@ -127,6 +133,7 @@ Google::Cloud.configure.add_config! :bigquery do |config|
127
133
  config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
128
134
  config.add_alias! :keyfile, :credentials
129
135
  config.add_field! :scope, nil, match: [String, Array]
136
+ config.add_field! :quota_project, nil, match: String
130
137
  config.add_field! :retries, nil, match: Integer
131
138
  config.add_field! :timeout, nil, match: Integer
132
139
  config.add_field! :endpoint, nil, match: String
@@ -84,7 +84,7 @@ module Google
84
84
  Bigquery::Project.new(
85
85
  Bigquery::Service.new(
86
86
  project_id, credentials,
87
- retries: retries, timeout: timeout, host: endpoint
87
+ retries: retries, timeout: timeout, host: endpoint, quota_project: configure.quota_project
88
88
  )
89
89
  )
90
90
  end
@@ -318,7 +318,9 @@ module Google
318
318
  "parquet" => "PARQUET",
319
319
  "datastore" => "DATASTORE_BACKUP",
320
320
  "backup" => "DATASTORE_BACKUP",
321
- "datastore_backup" => "DATASTORE_BACKUP"
321
+ "datastore_backup" => "DATASTORE_BACKUP",
322
+ "ml_tf_saved_model" => "ML_TF_SAVED_MODEL",
323
+ "ml_xgboost_booster" => "ML_XGBOOST_BOOSTER"
322
324
  }[format.to_s.downcase]
323
325
  return val unless val.nil?
324
326
  format
@@ -272,12 +272,21 @@ module Google
272
272
  # Sets the labels to use for the job.
273
273
  #
274
274
  # @param [Hash] value A hash of user-provided labels associated with
275
- # the job. You can use these to organize and group your jobs. Label
276
- # keys and values can be no longer than 63 characters, can only
277
- # contain lowercase letters, numeric characters, underscores and
278
- # dashes. International characters are allowed. Label values are
279
- # optional. Label keys must start with a letter and each label in
280
- # the list must have a different key.
275
+ # the job. You can use these to organize and group your jobs.
276
+ #
277
+ # The labels applied to a resource must meet the following requirements:
278
+ #
279
+ # * Each resource can have multiple labels, up to a maximum of 64.
280
+ # * Each label must be a key-value pair.
281
+ # * Keys have a minimum length of 1 character and a maximum length of
282
+ # 63 characters, and cannot be empty. Values can be empty, and have
283
+ # a maximum length of 63 characters.
284
+ # * Keys and values can contain only lowercase letters, numeric characters,
285
+ # underscores, and dashes. All characters must use UTF-8 encoding, and
286
+ # international characters are allowed.
287
+ # * The key portion of a label must be unique. However, you can use the
288
+ # same key with multiple resources.
289
+ # * Keys must start with a lowercase letter or international character.
281
290
  #
282
291
  # @!group Attributes
283
292
  def labels= value
@@ -41,9 +41,12 @@ module Google
41
41
  #
42
42
  # data.count # 100000
43
43
  # data.total # 164656
44
+ #
45
+ # # Iterate over the first page of results
44
46
  # data.each do |row|
45
47
  # puts row[:word]
46
48
  # end
49
+ # # Retrieve the next page of results
47
50
  # data = data.next if data.next?
48
51
  #
49
52
  class Data < DelegateClass(::Array)
@@ -117,9 +120,12 @@ module Google
117
120
  #
118
121
  # data.count # 100000
119
122
  # data.total # 164656
123
+ #
124
+ # # Iterate over the first page of results
120
125
  # data.each do |row|
121
126
  # puts row[:word]
122
127
  # end
128
+ # # Retrieve the next page of results
123
129
  # data = data.next if data.next?
124
130
  #
125
131
  def total
@@ -375,9 +381,12 @@ module Google
375
381
  #
376
382
  # data.count # 100000
377
383
  # data.total # 164656
384
+ #
385
+ # # Iterate over the first page of results
378
386
  # data.each do |row|
379
387
  # puts row[:word]
380
388
  # end
389
+ # # Retrieve the next page of results
381
390
  # data = data.next if data.next?
382
391
  #
383
392
  def next?
@@ -402,9 +411,12 @@ module Google
402
411
  #
403
412
  # data.count # 100000
404
413
  # data.total # 164656
414
+ #
415
+ # # Iterate over the first page of results
405
416
  # data.each do |row|
406
417
  # puts row[:word]
407
418
  # end
419
+ # # Retrieve the next page of results
408
420
  # data = data.next if data.next?
409
421
  #
410
422
  def next
@@ -313,12 +313,19 @@ module Google
313
313
  # @param [Hash<String, String>] labels A hash containing key/value
314
314
  # pairs.
315
315
  #
316
- # * Label keys and values can be no longer than 63 characters.
317
- # * Label keys and values can contain only lowercase letters, numbers,
318
- # underscores, hyphens, and international characters.
319
- # * Label keys and values cannot exceed 128 bytes in size.
320
- # * Label keys must begin with a letter.
321
- # * Label keys must be unique within a dataset.
316
+ # The labels applied to a resource must meet the following requirements:
317
+ #
318
+ # * Each resource can have multiple labels, up to a maximum of 64.
319
+ # * Each label must be a key-value pair.
320
+ # * Keys have a minimum length of 1 character and a maximum length of
321
+ # 63 characters, and cannot be empty. Values can be empty, and have
322
+ # a maximum length of 63 characters.
323
+ # * Keys and values can contain only lowercase letters, numeric characters,
324
+ # underscores, and dashes. All characters must use UTF-8 encoding, and
325
+ # international characters are allowed.
326
+ # * The key portion of a label must be unique. However, you can use the
327
+ # same key with multiple resources.
328
+ # * Keys must start with a lowercase letter or international character.
322
329
  #
323
330
  # @example
324
331
  # require "google/cloud/bigquery"
@@ -1171,13 +1178,21 @@ module Google
1171
1178
  # is 1,024 characters. If `job_id` is provided, then `prefix` will not
1172
1179
  # be used.
1173
1180
  # @param [Hash] labels A hash of user-provided labels associated with
1174
- # the job. You can use these to organize and group your jobs. Label
1175
- # keys and values can be no longer than 63 characters, can only
1176
- # contain lowercase letters, numeric characters, underscores and
1177
- # dashes. International characters are allowed. Label values are
1178
- # optional. Label keys must start with a letter and each label in the
1179
- # list must have a different key. See [Requirements for
1180
- # labels](https://cloud.google.com/bigquery/docs/creating-managing-labels#requirements).
1181
+ # the job. You can use these to organize and group your jobs.
1182
+ #
1183
+ # The labels applied to a resource must meet the following requirements:
1184
+ #
1185
+ # * Each resource can have multiple labels, up to a maximum of 64.
1186
+ # * Each label must be a key-value pair.
1187
+ # * Keys have a minimum length of 1 character and a maximum length of
1188
+ # 63 characters, and cannot be empty. Values can be empty, and have
1189
+ # a maximum length of 63 characters.
1190
+ # * Keys and values can contain only lowercase letters, numeric characters,
1191
+ # underscores, and dashes. All characters must use UTF-8 encoding, and
1192
+ # international characters are allowed.
1193
+ # * The key portion of a label must be unique. However, you can use the
1194
+ # same key with multiple resources.
1195
+ # * Keys must start with a lowercase letter or international character.
1181
1196
  # @param [Array<String>, String] udfs User-defined function resources
1182
1197
  # used in a legacy SQL query. May be either a code resource to load from
1183
1198
  # a Google Cloud Storage URI (`gs://bucket/path`), or an inline resource
@@ -1474,9 +1489,12 @@ module Google
1474
1489
  #
1475
1490
  # data = dataset.query "SELECT name FROM my_table"
1476
1491
  #
1492
+ # # Iterate over the first page of results
1477
1493
  # data.each do |row|
1478
1494
  # puts row[:name]
1479
1495
  # end
1496
+ # # Retrieve the next page of results
1497
+ # data = data.next if data.next?
1480
1498
  #
1481
1499
  # @example Query using legacy SQL:
1482
1500
  # require "google/cloud/bigquery"
@@ -1487,9 +1505,12 @@ module Google
1487
1505
  # data = dataset.query "SELECT name FROM my_table",
1488
1506
  # legacy_sql: true
1489
1507
  #
1508
+ # # Iterate over the first page of results
1490
1509
  # data.each do |row|
1491
1510
  # puts row[:name]
1492
1511
  # end
1512
+ # # Retrieve the next page of results
1513
+ # data = data.next if data.next?
1493
1514
  #
1494
1515
  # @example Query using positional query parameters:
1495
1516
  # require "google/cloud/bigquery"
@@ -1500,9 +1521,12 @@ module Google
1500
1521
  # data = dataset.query "SELECT name FROM my_table WHERE id = ?",
1501
1522
  # params: [1]
1502
1523
  #
1524
+ # # Iterate over the first page of results
1503
1525
  # data.each do |row|
1504
1526
  # puts row[:name]
1505
1527
  # end
1528
+ # # Retrieve the next page of results
1529
+ # data = data.next if data.next?
1506
1530
  #
1507
1531
  # @example Query using named query parameters:
1508
1532
  # require "google/cloud/bigquery"
@@ -1513,9 +1537,12 @@ module Google
1513
1537
  # data = dataset.query "SELECT name FROM my_table WHERE id = @id",
1514
1538
  # params: { id: 1 }
1515
1539
  #
1540
+ # # Iterate over the first page of results
1516
1541
  # data.each do |row|
1517
1542
  # puts row[:name]
1518
1543
  # end
1544
+ # # Retrieve the next page of results
1545
+ # data = data.next if data.next?
1519
1546
  #
1520
1547
  # @example Query using named query parameters with types:
1521
1548
  # require "google/cloud/bigquery"
@@ -1528,9 +1555,12 @@ module Google
1528
1555
  # params: { ids: [] },
1529
1556
  # types: { ids: [:INT64] }
1530
1557
  #
1558
+ # # Iterate over the first page of results
1531
1559
  # data.each do |row|
1532
1560
  # puts row[:name]
1533
1561
  # end
1562
+ # # Retrieve the next page of results
1563
+ # data = data.next if data.next?
1534
1564
  #
1535
1565
  # @example Execute a DDL statement:
1536
1566
  # require "google/cloud/bigquery"
@@ -1569,9 +1599,12 @@ module Google
1569
1599
  # query.table = dataset.table "my_table", skip_lookup: true
1570
1600
  # end
1571
1601
  #
1602
+ # # Iterate over the first page of results
1572
1603
  # data.each do |row|
1573
1604
  # puts row[:name]
1574
1605
  # end
1606
+ # # Retrieve the next page of results
1607
+ # data = data.next if data.next?
1575
1608
  #
1576
1609
  # @!group Data
1577
1610
  #
@@ -1774,13 +1807,21 @@ module Google
1774
1807
  # is 1,024 characters. If `job_id` is provided, then `prefix` will not
1775
1808
  # be used.
1776
1809
  # @param [Hash] labels A hash of user-provided labels associated with
1777
- # the job. You can use these to organize and group your jobs. Label
1778
- # keys and values can be no longer than 63 characters, can only
1779
- # contain lowercase letters, numeric characters, underscores and
1780
- # dashes. International characters are allowed. Label values are
1781
- # optional. Label keys must start with a letter and each label in the
1782
- # list must have a different key. See [Requirements for
1783
- # labels](https://cloud.google.com/bigquery/docs/creating-managing-labels#requirements).
1810
+ # the job. You can use these to organize and group your jobs.
1811
+ #
1812
+ # The labels applied to a resource must meet the following requirements:
1813
+ #
1814
+ # * Each resource can have multiple labels, up to a maximum of 64.
1815
+ # * Each label must be a key-value pair.
1816
+ # * Keys have a minimum length of 1 character and a maximum length of
1817
+ # 63 characters, and cannot be empty. Values can be empty, and have
1818
+ # a maximum length of 63 characters.
1819
+ # * Keys and values can contain only lowercase letters, numeric characters,
1820
+ # underscores, and dashes. All characters must use UTF-8 encoding, and
1821
+ # international characters are allowed.
1822
+ # * The key portion of a label must be unique. However, you can use the
1823
+ # same key with multiple resources.
1824
+ # * Keys must start with a lowercase letter or international character.
1784
1825
  # @yield [updater] A block for setting the schema and other
1785
1826
  # options for the destination table. The schema can be omitted if the
1786
1827
  # destination table already exists, or if you're loading data from a
@@ -48,16 +48,19 @@ module Google
48
48
 
49
49
  # @private
50
50
  SCOPES = {
51
- "user" => :user_by_email,
52
- "user_by_email" => :user_by_email,
53
- "userByEmail" => :user_by_email,
51
+ "domain" => :domain,
54
52
  "group" => :group_by_email,
55
53
  "group_by_email" => :group_by_email,
56
54
  "groupByEmail" => :group_by_email,
57
- "domain" => :domain,
55
+ "iam_member" => :iam_member,
56
+ "iamMember" => :iam_member,
57
+ "routine" => :routine,
58
58
  "special" => :special_group,
59
59
  "special_group" => :special_group,
60
60
  "specialGroup" => :special_group,
61
+ "user" => :user_by_email,
62
+ "user_by_email" => :user_by_email,
63
+ "userByEmail" => :user_by_email,
61
64
  "view" => :view
62
65
  }.freeze
63
66
 
@@ -150,6 +153,26 @@ module Google
150
153
  add_access_role_scope_value :reader, :group, email
151
154
  end
152
155
 
156
+ ##
157
+ # Add reader access to some other type of member that appears in the IAM
158
+ # Policy but isn't a user, group, domain, or special group.
159
+ #
160
+ # @param [String] identity The identity reference.
161
+ #
162
+ # @example
163
+ # require "google/cloud/bigquery"
164
+ #
165
+ # bigquery = Google::Cloud::Bigquery.new
166
+ # dataset = bigquery.dataset "my_dataset"
167
+ #
168
+ # dataset.access do |access|
169
+ # access.add_reader_iam_member "entity@example.com"
170
+ # end
171
+ #
172
+ def add_reader_iam_member identity
173
+ add_access_role_scope_value :reader, :iam_member, identity
174
+ end
175
+
153
176
  ##
154
177
  # Add reader access to a domain.
155
178
  #
@@ -190,6 +213,33 @@ module Google
190
213
  add_access_role_scope_value :reader, :special, group
191
214
  end
192
215
 
216
+ ##
217
+ # Add access to a routine from a different dataset. Queries executed
218
+ # against that routine will have read access to views/tables/routines
219
+ # in this dataset. Only UDF is supported for now. The role field is
220
+ # not required when this field is set. If that routine is updated by
221
+ # any user, access to the routine needs to be granted again via an
222
+ # update operation.
223
+ #
224
+ # @param [Google::Cloud::Bigquery::Routine] routine A routine object.
225
+ #
226
+ # @example
227
+ # require "google/cloud/bigquery"
228
+ #
229
+ # bigquery = Google::Cloud::Bigquery.new
230
+ # dataset = bigquery.dataset "my_dataset"
231
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
232
+ #
233
+ # routine = other_dataset.routine "my_routine"
234
+ #
235
+ # dataset.access do |access|
236
+ # access.add_reader_routine routine
237
+ # end
238
+ #
239
+ def add_reader_routine routine
240
+ add_access_routine routine
241
+ end
242
+
193
243
  ##
194
244
  # Add reader access to a view.
195
245
  #
@@ -205,9 +255,9 @@ module Google
205
255
  #
206
256
  # bigquery = Google::Cloud::Bigquery.new
207
257
  # dataset = bigquery.dataset "my_dataset"
208
- # other_dataset = bigquery.dataset "my_other_dataset"
258
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
209
259
  #
210
- # view = other_dataset.table "my_view"
260
+ # view = other_dataset.table "my_view", skip_lookup: true
211
261
  #
212
262
  # dataset.access do |access|
213
263
  # access.add_reader_view view
@@ -255,6 +305,26 @@ module Google
255
305
  add_access_role_scope_value :writer, :group, email
256
306
  end
257
307
 
308
+ ##
309
+ # Add writer access to some other type of member that appears in the IAM
310
+ # Policy but isn't a user, group, domain, or special group.
311
+ #
312
+ # @param [String] identity The identity reference.
313
+ #
314
+ # @example
315
+ # require "google/cloud/bigquery"
316
+ #
317
+ # bigquery = Google::Cloud::Bigquery.new
318
+ # dataset = bigquery.dataset "my_dataset"
319
+ #
320
+ # dataset.access do |access|
321
+ # access.add_writer_iam_member "entity@example.com"
322
+ # end
323
+ #
324
+ def add_writer_iam_member identity
325
+ add_access_role_scope_value :writer, :iam_member, identity
326
+ end
327
+
258
328
  ##
259
329
  # Add writer access to a domain.
260
330
  #
@@ -333,6 +403,26 @@ module Google
333
403
  add_access_role_scope_value :owner, :group, email
334
404
  end
335
405
 
406
+ ##
407
+ # Add owner access to some other type of member that appears in the IAM
408
+ # Policy but isn't a user, group, domain, or special group.
409
+ #
410
+ # @param [String] identity The identity reference.
411
+ #
412
+ # @example
413
+ # require "google/cloud/bigquery"
414
+ #
415
+ # bigquery = Google::Cloud::Bigquery.new
416
+ # dataset = bigquery.dataset "my_dataset"
417
+ #
418
+ # dataset.access do |access|
419
+ # access.add_owner_iam_member "entity@example.com"
420
+ # end
421
+ #
422
+ def add_owner_iam_member identity
423
+ add_access_role_scope_value :owner, :iam_member, identity
424
+ end
425
+
336
426
  ##
337
427
  # Add owner access to a domain.
338
428
  #
@@ -411,6 +501,26 @@ module Google
411
501
  remove_access_role_scope_value :reader, :group, email
412
502
  end
413
503
 
504
+ ##
505
+ # Remove reader access from some other type of member that appears in the IAM
506
+ # Policy but isn't a user, group, domain, or special group.
507
+ #
508
+ # @param [String] identity The identity reference.
509
+ #
510
+ # @example
511
+ # require "google/cloud/bigquery"
512
+ #
513
+ # bigquery = Google::Cloud::Bigquery.new
514
+ # dataset = bigquery.dataset "my_dataset"
515
+ #
516
+ # dataset.access do |access|
517
+ # access.remove_reader_iam_member "entity@example.com"
518
+ # end
519
+ #
520
+ def remove_reader_iam_member identity
521
+ remove_access_role_scope_value :reader, :iam_member, identity
522
+ end
523
+
414
524
  ##
415
525
  # Remove reader access from a domain.
416
526
  #
@@ -451,6 +561,28 @@ module Google
451
561
  remove_access_role_scope_value :reader, :special, group
452
562
  end
453
563
 
564
+ ##
565
+ # Remove reader access from a routine from a different dataset.
566
+ #
567
+ # @param [Google::Cloud::Bigquery::Routine] routine A routine object.
568
+ #
569
+ # @example
570
+ # require "google/cloud/bigquery"
571
+ #
572
+ # bigquery = Google::Cloud::Bigquery.new
573
+ # dataset = bigquery.dataset "my_dataset"
574
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
575
+ #
576
+ # routine = other_dataset.routine "my_routine", skip_lookup: true
577
+ #
578
+ # dataset.access do |access|
579
+ # access.remove_reader_routine routine
580
+ # end
581
+ #
582
+ def remove_reader_routine routine
583
+ remove_access_routine routine
584
+ end
585
+
454
586
  ##
455
587
  # Remove reader access from a view.
456
588
  #
@@ -466,9 +598,9 @@ module Google
466
598
  #
467
599
  # bigquery = Google::Cloud::Bigquery.new
468
600
  # dataset = bigquery.dataset "my_dataset"
469
- # other_dataset = bigquery.dataset "my_other_dataset"
601
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
470
602
  #
471
- # view = other_dataset.table "my_view"
603
+ # view = other_dataset.table "my_view", skip_lookup: true
472
604
  #
473
605
  # dataset.access do |access|
474
606
  # access.remove_reader_view view
@@ -516,6 +648,26 @@ module Google
516
648
  remove_access_role_scope_value :writer, :group, email
517
649
  end
518
650
 
651
+ ##
652
+ # Remove writer access from some other type of member that appears in the IAM
653
+ # Policy but isn't a user, group, domain, or special group.
654
+ #
655
+ # @param [String] identity The identity reference.
656
+ #
657
+ # @example
658
+ # require "google/cloud/bigquery"
659
+ #
660
+ # bigquery = Google::Cloud::Bigquery.new
661
+ # dataset = bigquery.dataset "my_dataset"
662
+ #
663
+ # dataset.access do |access|
664
+ # access.remove_writer_iam_member "entity@example.com"
665
+ # end
666
+ #
667
+ def remove_writer_iam_member identity
668
+ remove_access_role_scope_value :writer, :iam_member, identity
669
+ end
670
+
519
671
  ##
520
672
  # Remove writer access from a domain.
521
673
  #
@@ -594,6 +746,26 @@ module Google
594
746
  remove_access_role_scope_value :owner, :group, email
595
747
  end
596
748
 
749
+ ##
750
+ # Remove owner access from some other type of member that appears in the IAM
751
+ # Policy but isn't a user, group, domain, or special group.
752
+ #
753
+ # @param [String] identity The identity reference.
754
+ #
755
+ # @example
756
+ # require "google/cloud/bigquery"
757
+ #
758
+ # bigquery = Google::Cloud::Bigquery.new
759
+ # dataset = bigquery.dataset "my_dataset"
760
+ #
761
+ # dataset.access do |access|
762
+ # access.remove_owner_iam_member "entity@example.com"
763
+ # end
764
+ #
765
+ def remove_owner_iam_member identity
766
+ remove_access_role_scope_value :owner, :iam_member, identity
767
+ end
768
+
597
769
  ##
598
770
  # Remove owner access from a domain.
599
771
  #
@@ -670,6 +842,25 @@ module Google
670
842
  lookup_access_role_scope_value :reader, :group, email
671
843
  end
672
844
 
845
+ ##
846
+ # Checks reader access for some other type of member that appears in the IAM
847
+ # Policy but isn't a user, group, domain, or special group.
848
+ #
849
+ # @param [String] identity The identity reference.
850
+ #
851
+ # @example
852
+ # require "google/cloud/bigquery"
853
+ #
854
+ # bigquery = Google::Cloud::Bigquery.new
855
+ # dataset = bigquery.dataset "my_dataset"
856
+ #
857
+ # access = dataset.access
858
+ # access.reader_iam_member? "entity@example.com" #=> false
859
+ #
860
+ def reader_iam_member? identity
861
+ lookup_access_role_scope_value :reader, :iam_member, identity
862
+ end
863
+
673
864
  ##
674
865
  # Checks reader access for a domain.
675
866
  #
@@ -708,6 +899,32 @@ module Google
708
899
  lookup_access_role_scope_value :reader, :special, group
709
900
  end
710
901
 
902
+ ##
903
+ # Checks access for a routine from a different dataset. Queries executed
904
+ # against that routine will have read access to views/tables/routines
905
+ # in this dataset. Only UDF is supported for now. The role field is
906
+ # not required when this field is set. If that routine is updated by
907
+ # any user, access to the routine needs to be granted again via an
908
+ # update operation.
909
+ #
910
+ # @param [Google::Cloud::Bigquery::Routine] routine A routine object.
911
+ #
912
+ # @example
913
+ # require "google/cloud/bigquery"
914
+ #
915
+ # bigquery = Google::Cloud::Bigquery.new
916
+ # dataset = bigquery.dataset "my_dataset"
917
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
918
+ #
919
+ # routine = other_dataset.routine "my_routine", skip_lookup: true
920
+ #
921
+ # access = dataset.access
922
+ # access.reader_routine? routine #=> false
923
+ #
924
+ def reader_routine? routine
925
+ lookup_access_routine routine
926
+ end
927
+
711
928
  ##
712
929
  # Checks reader access for a view.
713
930
  #
@@ -723,9 +940,9 @@ module Google
723
940
  #
724
941
  # bigquery = Google::Cloud::Bigquery.new
725
942
  # dataset = bigquery.dataset "my_dataset"
726
- # other_dataset = bigquery.dataset "my_other_dataset"
943
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
727
944
  #
728
- # view = other_dataset.table "my_view"
945
+ # view = other_dataset.table "my_view", skip_lookup: true
729
946
  #
730
947
  # access = dataset.access
731
948
  # access.reader_view? view #=> false
@@ -770,6 +987,25 @@ module Google
770
987
  lookup_access_role_scope_value :writer, :group, email
771
988
  end
772
989
 
990
+ ##
991
+ # Checks writer access for some other type of member that appears in the IAM
992
+ # Policy but isn't a user, group, domain, or special group.
993
+ #
994
+ # @param [String] identity The identity reference.
995
+ #
996
+ # @example
997
+ # require "google/cloud/bigquery"
998
+ #
999
+ # bigquery = Google::Cloud::Bigquery.new
1000
+ # dataset = bigquery.dataset "my_dataset"
1001
+ #
1002
+ # access = dataset.access
1003
+ # access.writer_iam_member? "entity@example.com" #=> false
1004
+ #
1005
+ def writer_iam_member? identity
1006
+ lookup_access_role_scope_value :writer, :iam_member, identity
1007
+ end
1008
+
773
1009
  ##
774
1010
  # Checks writer access for a domain.
775
1011
  #
@@ -844,6 +1080,25 @@ module Google
844
1080
  lookup_access_role_scope_value :owner, :group, email
845
1081
  end
846
1082
 
1083
+ ##
1084
+ # Checks owner access for some other type of member that appears in the IAM
1085
+ # Policy but isn't a user, group, domain, or special group.
1086
+ #
1087
+ # @param [String] identity The identity reference.
1088
+ #
1089
+ # @example
1090
+ # require "google/cloud/bigquery"
1091
+ #
1092
+ # bigquery = Google::Cloud::Bigquery.new
1093
+ # dataset = bigquery.dataset "my_dataset"
1094
+ #
1095
+ # access = dataset.access
1096
+ # access.owner_iam_member? "entity@example.com" #=> false
1097
+ #
1098
+ def owner_iam_member? identity
1099
+ lookup_access_role_scope_value :owner, :iam_member, identity
1100
+ end
1101
+
847
1102
  ##
848
1103
  # Checks owner access for a domain.
849
1104
  #
@@ -942,12 +1197,22 @@ module Google
942
1197
  @rules << Google::Apis::BigqueryV2::Dataset::Access.new(opts)
943
1198
  end
944
1199
 
1200
+ # @private
1201
+ def add_access_routine routine
1202
+ value = routine.routine_ref
1203
+ # Remove existing routine rule, if any
1204
+ @rules.reject!(&find_by_scope_and_resource_ref(:routine, value))
1205
+ # Add new rule for this role, scope, and value
1206
+ opts = { routine: value }
1207
+ @rules << Google::Apis::BigqueryV2::Dataset::Access.new(opts)
1208
+ end
1209
+
945
1210
  # @private
946
1211
  def add_access_view value
947
1212
  # scope is view, make sure value is in the right format
948
1213
  value = validate_view value
949
1214
  # Remove existing view rule, if any
950
- @rules.reject!(&find_view(value))
1215
+ @rules.reject!(&find_by_scope_and_resource_ref(:view, value))
951
1216
  # Add new rule for this role, scope, and value
952
1217
  opts = { view: value }
953
1218
  @rules << Google::Apis::BigqueryV2::Dataset::Access.new(opts)
@@ -965,12 +1230,18 @@ module Google
965
1230
  )
966
1231
  end
967
1232
 
1233
+ # @private
1234
+ def remove_access_routine routine
1235
+ # Remove existing routine rule, if any
1236
+ @rules.reject!(&find_by_scope_and_resource_ref(:routine, routine.routine_ref))
1237
+ end
1238
+
968
1239
  # @private
969
1240
  def remove_access_view value
970
1241
  # scope is view, make sure value is in the right format
971
1242
  value = validate_view value
972
1243
  # Remove existing view rule, if any
973
- @rules.reject!(&find_view(value))
1244
+ @rules.reject!(&find_by_scope_and_resource_ref(:view, value))
974
1245
  end
975
1246
 
976
1247
  # @private
@@ -983,12 +1254,18 @@ module Google
983
1254
  !(!@rules.detect(&find_by_role_and_scope_and_value(role, scope, value)))
984
1255
  end
985
1256
 
1257
+ # @private
1258
+ def lookup_access_routine routine
1259
+ # Detect routine rule, if any
1260
+ !(!@rules.detect(&find_by_scope_and_resource_ref(:routine, routine.routine_ref)))
1261
+ end
1262
+
986
1263
  # @private
987
1264
  def lookup_access_view value
988
1265
  # scope is view, make sure value is in the right format
989
1266
  value = validate_view value
990
1267
  # Detect view rule, if any
991
- !(!@rules.detect(&find_view(value)))
1268
+ !(!@rules.detect(&find_by_scope_and_resource_ref(:view, value)))
992
1269
  end
993
1270
 
994
1271
  # @private
@@ -1007,11 +1284,11 @@ module Google
1007
1284
  end
1008
1285
  end
1009
1286
 
1010
- # @private
1011
- def find_view value
1287
+ # @private Compare hash representations to find table_ref, routine_ref.
1288
+ def find_by_scope_and_resource_ref scope, value
1012
1289
  lambda do |a|
1013
1290
  h = a.to_h
1014
- h[:view].to_h == value.to_h
1291
+ h[scope].to_h == value.to_h
1015
1292
  end
1016
1293
  end
1017
1294
  end