google-cloud-pubsub 2.15.3 → 3.0.2

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +8 -26
  3. data/CHANGELOG.md +108 -0
  4. data/OVERVIEW.md +188 -144
  5. data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
  6. data/lib/google/cloud/pubsub/async_publisher.rb +9 -9
  7. data/lib/google/cloud/pubsub/batch_publisher.rb +4 -4
  8. data/lib/google/cloud/pubsub/convert.rb +1 -1
  9. data/lib/google/cloud/pubsub/errors.rb +3 -3
  10. data/lib/google/cloud/pubsub/flow_controller.rb +0 -2
  11. data/lib/google/cloud/pubsub/message.rb +10 -11
  12. data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
  13. data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +2 -4
  14. data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
  15. data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +15 -14
  16. data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +1 -1
  17. data/lib/google/cloud/pubsub/message_listener.rb +413 -0
  18. data/lib/google/cloud/pubsub/project.rb +103 -523
  19. data/lib/google/cloud/pubsub/publisher.rb +373 -0
  20. data/lib/google/cloud/pubsub/received_message.rb +50 -45
  21. data/lib/google/cloud/pubsub/service.rb +40 -352
  22. data/lib/google/cloud/pubsub/subscriber.rb +442 -279
  23. data/lib/google/cloud/pubsub/version.rb +1 -1
  24. data/lib/google/cloud/pubsub.rb +24 -28
  25. data/lib/google-cloud-pubsub.rb +8 -6
  26. metadata +18 -183
  27. data/lib/google/cloud/pubsub/policy.rb +0 -188
  28. data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
  29. data/lib/google/cloud/pubsub/schema/list.rb +0 -180
  30. data/lib/google/cloud/pubsub/schema.rb +0 -310
  31. data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
  32. data/lib/google/cloud/pubsub/snapshot.rb +0 -205
  33. data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
  34. data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
  35. data/lib/google/cloud/pubsub/subscription.rb +0 -1467
  36. data/lib/google/cloud/pubsub/topic/list.rb +0 -171
  37. data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "2.15.3".freeze
19
+ VERSION = "3.0.2".freeze
20
20
  end
21
21
 
22
22
  Pubsub = PubSub unless const_defined? :Pubsub
@@ -59,9 +59,7 @@ module Google
59
59
  # If the param is nil, uses the default endpoint.
60
60
  # @param [String] emulator_host Pub/Sub emulator host. Optional.
61
61
  # If the param is nil, uses the value of the `emulator_host` config.
62
- # @param [String] project Alias for the `project_id` argument. Deprecated.
63
- # @param [String] keyfile Alias for the `credentials` argument.
64
- # Deprecated.
62
+ # @param universe_domain [String] A custom universe domain. Optional.
65
63
  #
66
64
  # @return [Google::Cloud::PubSub::Project]
67
65
  #
@@ -70,41 +68,41 @@ module Google
70
68
  #
71
69
  # pubsub = Google::Cloud::PubSub.new
72
70
  #
73
- # topic = pubsub.topic "my-topic"
74
- # topic.publish "task completed"
71
+ # publisher = pubsub.publisher "my-topic"
72
+ # publisher.publish "task completed"
75
73
  #
76
74
  def self.new project_id: nil,
77
75
  credentials: nil,
78
76
  scope: nil,
79
77
  timeout: nil,
78
+ universe_domain: nil,
80
79
  endpoint: nil,
81
- emulator_host: nil,
82
- project: nil,
83
- keyfile: nil
84
- project_id ||= (project || default_project_id)
85
- scope ||= configure.scope
86
- timeout ||= configure.timeout
87
- endpoint ||= configure.endpoint
80
+ emulator_host: nil
81
+ project_id ||= default_project_id
82
+ scope ||= configure.scope
83
+ timeout ||= configure.timeout
84
+ endpoint ||= configure.endpoint
85
+ universe_domain ||= configure.universe_domain
88
86
  emulator_host ||= configure.emulator_host
89
87
 
90
88
  if emulator_host
91
- project_id = project_id.to_s # Always cast to a string
92
- raise ArgumentError, "project_id is missing" if project_id.empty?
93
-
94
- service = PubSub::Service.new project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout
95
- return PubSub::Project.new service
96
- end
97
-
98
- credentials ||= (keyfile || default_credentials(scope: scope))
99
- unless credentials.is_a? Google::Auth::Credentials
100
- credentials = PubSub::Credentials.new credentials, scope: scope
89
+ credentials = :this_channel_is_insecure
90
+ endpoint = emulator_host
91
+ else
92
+ credentials ||= default_credentials scope: scope
93
+ unless credentials.is_a? Google::Auth::Credentials
94
+ credentials = PubSub::Credentials.new credentials, scope: scope
95
+ end
101
96
  end
102
97
 
103
98
  project_id ||= credentials.project_id if credentials.respond_to? :project_id
104
99
  project_id = project_id.to_s # Always cast to a string
105
100
  raise ArgumentError, "project_id is missing" if project_id.empty?
106
101
 
107
- service = PubSub::Service.new project_id, credentials, host: endpoint, timeout: timeout
102
+ service = PubSub::Service.new project_id, credentials,
103
+ host: endpoint,
104
+ timeout: timeout,
105
+ universe_domain: universe_domain
108
106
  PubSub::Project.new service
109
107
  end
110
108
 
@@ -113,12 +111,10 @@ module Google
113
111
  #
114
112
  # The following PubSub configuration parameters are supported:
115
113
  #
116
- # * `project_id` - (String) Identifier for a PubSub project. (The
117
- # parameter `project` is considered deprecated, but may also be used.)
114
+ # * `project_id` - (String) Identifier for a PubSub project.
118
115
  # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
119
116
  # the keyfile as a String, the contents of the keyfile as a Hash, or a
120
- # Google::Auth::Credentials object. (See {PubSub::Credentials}) (The
121
- # parameter `keyfile` is considered deprecated, but may also be used.)
117
+ # Google::Auth::Credentials object. (See {PubSub::Credentials})
122
118
  # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
123
119
  # the set of resources and operations that the connection can access.
124
120
  # * `quota_project` - (String) The project ID for a project that can be
@@ -130,7 +126,7 @@ module Google
130
126
  # `ENV["PUBSUB_EMULATOR_HOST"]`
131
127
  # * `on_error` - (Proc) A Proc to be run when an error is encountered
132
128
  # on a background thread. The Proc must take the error object as the
133
- # single argument. (See {Subscriber.on_error}.)
129
+ # single argument. (See {MessageListener.on_error}.)
134
130
  #
135
131
  # @return [Google::Cloud::Config] The configuration object the
136
132
  # Google::Cloud::PubSub library uses.
@@ -50,8 +50,9 @@ module Google
50
50
  #
51
51
  # gcloud = Google::Cloud.new
52
52
  # pubsub = gcloud.pubsub
53
- # topic = pubsub.topic "my-topic"
54
- # topic.publish "task completed"
53
+ # topic_admin = pubsub.topic_admin
54
+ # publisher = pubsub.publisher "my-topic"
55
+ # publisher.publish "task completed"
55
56
  #
56
57
  # @example The default scope can be overridden with the `scope` option:
57
58
  # require "google/cloud"
@@ -96,8 +97,8 @@ module Google
96
97
  #
97
98
  # pubsub = Google::Cloud.pubsub
98
99
  #
99
- # topic = pubsub.topic "my-topic"
100
- # topic.publish "task completed"
100
+ # publisher = pubsub.publisher "my-topic"
101
+ # publisher.publish "task completed"
101
102
  #
102
103
  def self.pubsub project_id = nil,
103
104
  credentials = nil,
@@ -110,7 +111,7 @@ module Google
110
111
  end
111
112
 
112
113
  # Set the default pubsub configuration
113
- Google::Cloud.configure.add_config! :pubsub do |config|
114
+ Google::Cloud.configure.add_config! :pubsub do |config| # rubocop:disable Metrics/BlockLength
114
115
  default_project = Google::Cloud::Config.deferred do
115
116
  ENV["PUBSUB_PROJECT"]
116
117
  end
@@ -136,5 +137,6 @@ Google::Cloud.configure.add_config! :pubsub do |config|
136
137
  config.add_field! :timeout, nil, match: Numeric
137
138
  config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
138
139
  config.add_field! :on_error, nil, match: Proc
139
- config.add_field! :endpoint, "pubsub.googleapis.com", match: String
140
+ config.add_field! :endpoint, nil, match: String
141
+ config.add_field! :universe_domain, nil, match: String
140
142
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.3
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
8
8
  - Chris Smith
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2023-04-19 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: concurrent-ruby
@@ -17,42 +16,42 @@ dependencies:
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: '1.1'
19
+ version: '1.3'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: '1.1'
26
+ version: '1.3'
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: google-cloud-core
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - "~>"
33
32
  - !ruby/object:Gem::Version
34
- version: '1.5'
33
+ version: '1.8'
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - "~>"
40
39
  - !ruby/object:Gem::Version
41
- version: '1.5'
40
+ version: '1.8'
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: google-cloud-pubsub-v1
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
45
  - - "~>"
47
46
  - !ruby/object:Gem::Version
48
- version: '0.8'
47
+ version: '1.11'
49
48
  type: :runtime
50
49
  prerelease: false
51
50
  version_requirements: !ruby/object:Gem::Requirement
52
51
  requirements:
53
52
  - - "~>"
54
53
  - !ruby/object:Gem::Version
55
- version: '0.8'
54
+ version: '1.11'
56
55
  - !ruby/object:Gem::Dependency
57
56
  name: retriable
58
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,160 +66,6 @@ dependencies:
67
66
  - - "~>"
68
67
  - !ruby/object:Gem::Version
69
68
  version: '3.1'
70
- - !ruby/object:Gem::Dependency
71
- name: autotest-suffix
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '1.1'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '1.1'
84
- - !ruby/object:Gem::Dependency
85
- name: avro
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '1.10'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '1.10'
98
- - !ruby/object:Gem::Dependency
99
- name: google-style
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: 1.25.1
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: 1.25.1
112
- - !ruby/object:Gem::Dependency
113
- name: minitest
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - "~>"
117
- - !ruby/object:Gem::Version
118
- version: '5.16'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: '5.16'
126
- - !ruby/object:Gem::Dependency
127
- name: minitest-autotest
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - "~>"
131
- - !ruby/object:Gem::Version
132
- version: '1.0'
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: '1.0'
140
- - !ruby/object:Gem::Dependency
141
- name: minitest-focus
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - "~>"
145
- - !ruby/object:Gem::Version
146
- version: '1.1'
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - "~>"
152
- - !ruby/object:Gem::Version
153
- version: '1.1'
154
- - !ruby/object:Gem::Dependency
155
- name: minitest-rg
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - "~>"
159
- - !ruby/object:Gem::Version
160
- version: '5.2'
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - "~>"
166
- - !ruby/object:Gem::Version
167
- version: '5.2'
168
- - !ruby/object:Gem::Dependency
169
- name: redcarpet
170
- requirement: !ruby/object:Gem::Requirement
171
- requirements:
172
- - - "~>"
173
- - !ruby/object:Gem::Version
174
- version: '3.0'
175
- type: :development
176
- prerelease: false
177
- version_requirements: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - "~>"
180
- - !ruby/object:Gem::Version
181
- version: '3.0'
182
- - !ruby/object:Gem::Dependency
183
- name: simplecov
184
- requirement: !ruby/object:Gem::Requirement
185
- requirements:
186
- - - "~>"
187
- - !ruby/object:Gem::Version
188
- version: '0.9'
189
- type: :development
190
- prerelease: false
191
- version_requirements: !ruby/object:Gem::Requirement
192
- requirements:
193
- - - "~>"
194
- - !ruby/object:Gem::Version
195
- version: '0.9'
196
- - !ruby/object:Gem::Dependency
197
- name: yard
198
- requirement: !ruby/object:Gem::Requirement
199
- requirements:
200
- - - "~>"
201
- - !ruby/object:Gem::Version
202
- version: '0.9'
203
- type: :development
204
- prerelease: false
205
- version_requirements: !ruby/object:Gem::Requirement
206
- requirements:
207
- - - "~>"
208
- - !ruby/object:Gem::Version
209
- version: '0.9'
210
- - !ruby/object:Gem::Dependency
211
- name: yard-doctest
212
- requirement: !ruby/object:Gem::Requirement
213
- requirements:
214
- - - "~>"
215
- - !ruby/object:Gem::Version
216
- version: 0.1.13
217
- type: :development
218
- prerelease: false
219
- version_requirements: !ruby/object:Gem::Requirement
220
- requirements:
221
- - - "~>"
222
- - !ruby/object:Gem::Version
223
- version: 0.1.13
224
69
  description: google-cloud-pubsub is the official library for Google Cloud Pub/Sub.
225
70
  email:
226
71
  - mike@blowmage.com
@@ -242,6 +87,7 @@ files:
242
87
  - lib/google-cloud-pubsub.rb
243
88
  - lib/google/cloud/pubsub.rb
244
89
  - lib/google/cloud/pubsub/acknowledge_result.rb
90
+ - lib/google/cloud/pubsub/admin_clients.rb
245
91
  - lib/google/cloud/pubsub/async_publisher.rb
246
92
  - lib/google/cloud/pubsub/async_publisher/batch.rb
247
93
  - lib/google/cloud/pubsub/batch_publisher.rb
@@ -250,33 +96,23 @@ files:
250
96
  - lib/google/cloud/pubsub/errors.rb
251
97
  - lib/google/cloud/pubsub/flow_controller.rb
252
98
  - lib/google/cloud/pubsub/message.rb
253
- - lib/google/cloud/pubsub/policy.rb
99
+ - lib/google/cloud/pubsub/message_listener.rb
100
+ - lib/google/cloud/pubsub/message_listener/enumerator_queue.rb
101
+ - lib/google/cloud/pubsub/message_listener/inventory.rb
102
+ - lib/google/cloud/pubsub/message_listener/sequencer.rb
103
+ - lib/google/cloud/pubsub/message_listener/stream.rb
104
+ - lib/google/cloud/pubsub/message_listener/timed_unary_buffer.rb
254
105
  - lib/google/cloud/pubsub/project.rb
255
106
  - lib/google/cloud/pubsub/publish_result.rb
107
+ - lib/google/cloud/pubsub/publisher.rb
256
108
  - lib/google/cloud/pubsub/received_message.rb
257
- - lib/google/cloud/pubsub/retry_policy.rb
258
- - lib/google/cloud/pubsub/schema.rb
259
- - lib/google/cloud/pubsub/schema/list.rb
260
109
  - lib/google/cloud/pubsub/service.rb
261
- - lib/google/cloud/pubsub/snapshot.rb
262
- - lib/google/cloud/pubsub/snapshot/list.rb
263
110
  - lib/google/cloud/pubsub/subscriber.rb
264
- - lib/google/cloud/pubsub/subscriber/enumerator_queue.rb
265
- - lib/google/cloud/pubsub/subscriber/inventory.rb
266
- - lib/google/cloud/pubsub/subscriber/sequencer.rb
267
- - lib/google/cloud/pubsub/subscriber/stream.rb
268
- - lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb
269
- - lib/google/cloud/pubsub/subscription.rb
270
- - lib/google/cloud/pubsub/subscription/list.rb
271
- - lib/google/cloud/pubsub/subscription/push_config.rb
272
- - lib/google/cloud/pubsub/topic.rb
273
- - lib/google/cloud/pubsub/topic/list.rb
274
111
  - lib/google/cloud/pubsub/version.rb
275
112
  homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-pubsub
276
113
  licenses:
277
114
  - Apache-2.0
278
115
  metadata: {}
279
- post_install_message:
280
116
  rdoc_options: []
281
117
  require_paths:
282
118
  - lib
@@ -284,15 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
120
  requirements:
285
121
  - - ">="
286
122
  - !ruby/object:Gem::Version
287
- version: '2.5'
123
+ version: '3.1'
288
124
  required_rubygems_version: !ruby/object:Gem::Requirement
289
125
  requirements:
290
126
  - - ">="
291
127
  - !ruby/object:Gem::Version
292
128
  version: '0'
293
129
  requirements: []
294
- rubygems_version: 3.4.2
295
- signing_key:
130
+ rubygems_version: 3.6.9
296
131
  specification_version: 4
297
132
  summary: API Client library for Google Cloud Pub/Sub
298
133
  test_files: []
@@ -1,188 +0,0 @@
1
- # Copyright 2016 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
-
16
- require "google/cloud/errors"
17
-
18
- module Google
19
- module Cloud
20
- module PubSub
21
- ##
22
- # # Policy
23
- #
24
- # Represents a Cloud IAM Policy for the Pub/Sub service.
25
- #
26
- # A common pattern for updating a resource's metadata, such as its Policy,
27
- # is to read the current data from the service, update the data locally,
28
- # and then send the modified data for writing. This pattern may result in
29
- # a conflict if two or more processes attempt the sequence simultaneously.
30
- # IAM solves this problem with the {Google::Cloud::PubSub::Policy#etag}
31
- # property, which is used to verify whether the policy has changed since
32
- # the last request. When you make a request to with an `etag` value, Cloud
33
- # IAM compares the `etag` value in the request with the existing `etag`
34
- # value associated with the policy. It writes the policy only if the
35
- # `etag` values match.
36
- #
37
- # When you update a policy, first read the policy (and its current `etag`)
38
- # from the service, then modify the policy locally, and then write the
39
- # modified policy to the service. See
40
- # {Google::Cloud::PubSub::Topic#policy} and
41
- # {Google::Cloud::PubSub::Topic#policy=}.
42
- #
43
- # @see https://cloud.google.com/iam/docs/managing-policies Managing
44
- # policies
45
- # @see https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#iampolicy
46
- # google.iam.v1.IAMPolicy
47
- #
48
- # @attr [String] etag Used to verify whether the policy has changed since
49
- # the last request. The policy will be written only if the `etag` values
50
- # match.
51
- # @attr [Hash{String => Array<String>}] roles The bindings that associate
52
- # roles with an array of members. See [Understanding
53
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
54
- # listing of primitive and curated roles.
55
- # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
56
- # for a listing of values and patterns for members.
57
- #
58
- # @example
59
- # require "google/cloud/pubsub"
60
- #
61
- # pubsub = Google::Cloud::PubSub.new
62
- # topic = pubsub.topic "my-topic"
63
- #
64
- # topic.policy do |p|
65
- # p.remove "roles/owner", "user:owner@example.com"
66
- # p.add "roles/owner", "user:newowner@example.com"
67
- # p.roles["roles/viewer"] = ["allUsers"]
68
- # end
69
- #
70
- class Policy
71
- attr_reader :etag
72
- attr_reader :roles
73
-
74
- ##
75
- # @private Creates a Policy object.
76
- def initialize etag, roles
77
- @etag = etag
78
- @roles = roles
79
- end
80
-
81
- ##
82
- # Convenience method for adding a member to a binding on this policy.
83
- # See [Understanding
84
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
85
- # listing of primitive and curated roles.
86
- # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
87
- # for a listing of values and patterns for members.
88
- #
89
- # @param [String] role_name A Cloud IAM role, such as
90
- # `"roles/pubsub.admin"`.
91
- # @param [String] member A Cloud IAM identity, such as
92
- # `"user:owner@example.com"`.
93
- #
94
- # @example
95
- # require "google/cloud/pubsub"
96
- #
97
- # pubsub = Google::Cloud::PubSub.new
98
- # topic = pubsub.topic "my-topic"
99
- #
100
- # topic.policy do |p|
101
- # p.add "roles/owner", "user:newowner@example.com"
102
- # end
103
- #
104
- def add role_name, member
105
- role(role_name) << member
106
- end
107
-
108
- ##
109
- # Convenience method for removing a member from a binding on this
110
- # policy. See [Understanding
111
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
112
- # listing of primitive and curated roles. See
113
- # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
114
- # for a listing of values and patterns for members.
115
- #
116
- # @param [String] role_name A Cloud IAM role, such as
117
- # `"roles/pubsub.admin"`.
118
- # @param [String] member A Cloud IAM identity, such as
119
- # `"user:owner@example.com"`.
120
- #
121
- # @example
122
- # require "google/cloud/pubsub"
123
- #
124
- # pubsub = Google::Cloud::PubSub.new
125
- # topic = pubsub.topic "my-topic"
126
- #
127
- # topic.policy do |p|
128
- # p.remove "roles/owner", "user:owner@example.com"
129
- # end
130
- #
131
- def remove role_name, member
132
- role(role_name).delete member
133
- end
134
-
135
- ##
136
- # Convenience method returning the array of members bound to a role in
137
- # this policy, or an empty array if no value is present for the role in
138
- # {#roles}. See [Understanding
139
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
140
- # listing of primitive and curated roles. See
141
- # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
142
- # for a listing of values and patterns for members.
143
- #
144
- # @return [Array<String>] The members strings, or an empty array.
145
- #
146
- # @example
147
- # require "google/cloud/pubsub"
148
- #
149
- # pubsub = Google::Cloud::PubSub.new
150
- # topic = pubsub.topic "my-topic"
151
- #
152
- # topic.policy do |p|
153
- # p.role("roles/viewer") << "user:viewer@example.com"
154
- # end
155
- #
156
- def role role_name
157
- roles[role_name] ||= []
158
- end
159
-
160
- ##
161
- # @private Convert the Policy to a Google::Iam::V1::Policy object.
162
- def to_grpc
163
- Google::Iam::V1::Policy.new(
164
- etag: etag,
165
- bindings: roles.keys.map do |role_name|
166
- next if roles[role_name].empty?
167
- Google::Iam::V1::Binding.new(
168
- role: role_name,
169
- members: roles[role_name]
170
- )
171
- end.compact
172
- )
173
- end
174
-
175
- ##
176
- # @private New Policy from a Google::Iam::V1::Policy object.
177
- def self.from_grpc grpc
178
- roles = grpc.bindings.each_with_object({}) do |binding, memo|
179
- memo[binding.role] = binding.members.to_a
180
- end
181
- new grpc.etag, roles
182
- end
183
- end
184
- end
185
-
186
- Pubsub = PubSub unless const_defined? :Pubsub
187
- end
188
- end