google-cloud-pubsub 2.22.0 → 3.2.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 +4 -4
- data/AUTHENTICATION.md +12 -1
- data/CHANGELOG.md +69 -0
- data/OVERVIEW.md +189 -145
- data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
- data/lib/google/cloud/pubsub/async_publisher.rb +20 -19
- data/lib/google/cloud/pubsub/batch_publisher.rb +7 -5
- data/lib/google/cloud/pubsub/errors.rb +3 -3
- data/lib/google/cloud/pubsub/internal_logger.rb +76 -0
- data/lib/google/cloud/pubsub/message.rb +8 -8
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +13 -10
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +61 -18
- data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +29 -9
- data/lib/google/cloud/pubsub/message_listener.rb +414 -0
- data/lib/google/cloud/pubsub/project.rb +102 -530
- data/lib/google/cloud/pubsub/publisher.rb +424 -0
- data/lib/google/cloud/pubsub/received_message.rb +50 -45
- data/lib/google/cloud/pubsub/service.rb +34 -385
- data/lib/google/cloud/pubsub/subscriber.rb +442 -279
- data/lib/google/cloud/pubsub/version.rb +1 -1
- data/lib/google/cloud/pubsub.rb +37 -19
- data/lib/google-cloud-pubsub.rb +27 -8
- metadata +19 -26
- data/lib/google/cloud/pubsub/policy.rb +0 -188
- data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
- data/lib/google/cloud/pubsub/schema/list.rb +0 -180
- data/lib/google/cloud/pubsub/schema.rb +0 -378
- data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
- data/lib/google/cloud/pubsub/snapshot.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
- data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
- data/lib/google/cloud/pubsub/subscription.rb +0 -1467
- data/lib/google/cloud/pubsub/topic/list.rb +0 -171
- data/lib/google/cloud/pubsub/topic.rb +0 -1100
data/lib/google/cloud/pubsub.rb
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
require "google-cloud-pubsub"
|
|
17
|
+
require "google/cloud/pubsub/internal_logger"
|
|
17
18
|
require "google/cloud/pubsub/project"
|
|
18
19
|
require "google/cloud/config"
|
|
19
20
|
require "google/cloud/env"
|
|
@@ -43,9 +44,24 @@ module Google
|
|
|
43
44
|
# @param [String] project_id Project identifier for the Pub/Sub service
|
|
44
45
|
# you are connecting to. If not present, the default project for the
|
|
45
46
|
# credentials is used.
|
|
46
|
-
# @param [
|
|
47
|
-
#
|
|
48
|
-
#
|
|
47
|
+
# @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
|
|
48
|
+
# object. (See {PubSub::Credentials})
|
|
49
|
+
# @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
|
|
50
|
+
# is deprecated. Providing an unvalidated credential configuration to
|
|
51
|
+
# Google APIs can compromise the security of your systems and data.
|
|
52
|
+
#
|
|
53
|
+
# @example
|
|
54
|
+
#
|
|
55
|
+
# # The recommended way to provide credentials is to use the `make_creds` method
|
|
56
|
+
# # on the appropriate credentials class for your environment.
|
|
57
|
+
#
|
|
58
|
+
# require "googleauth"
|
|
59
|
+
#
|
|
60
|
+
# credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
|
|
61
|
+
# json_key_io: ::File.open("/path/to/keyfile.json")
|
|
62
|
+
# )
|
|
63
|
+
#
|
|
64
|
+
# pubsub = Google::Cloud::Pubsub.new project_id: "my-project", credentials: credentials
|
|
49
65
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
|
|
50
66
|
# the set of resources and operations that the connection can access.
|
|
51
67
|
# See [Using OAuth 2.0 to Access Google
|
|
@@ -55,14 +71,16 @@ module Google
|
|
|
55
71
|
#
|
|
56
72
|
# * `https://www.googleapis.com/auth/pubsub`
|
|
57
73
|
# @param [Numeric] timeout Default timeout to use in requests. Optional.
|
|
74
|
+
# @param [String] universe_domain A custom universe domain. Optional.
|
|
58
75
|
# @param [String] endpoint Override of the endpoint host name. Optional.
|
|
59
76
|
# If the param is nil, uses the default endpoint.
|
|
60
77
|
# @param [String] emulator_host Pub/Sub emulator host. Optional.
|
|
61
78
|
# If the param is nil, uses the value of the `emulator_host` config.
|
|
62
|
-
# @param [
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
79
|
+
# @param [Logger] logger Optional Logger instance for emitting
|
|
80
|
+
# library-level debug logs. If not provided, it will default to
|
|
81
|
+
# configure.logger, which defaults to Logger.new STDOUT if not set. To
|
|
82
|
+
# enable logging, set environment variable GOOGLE_SDK_RUBY_LOGGING_GEMS
|
|
83
|
+
# to "all" or a comma separated list of gem names, including "pubsub".
|
|
66
84
|
#
|
|
67
85
|
# @return [Google::Cloud::PubSub::Project]
|
|
68
86
|
#
|
|
@@ -71,8 +89,8 @@ module Google
|
|
|
71
89
|
#
|
|
72
90
|
# pubsub = Google::Cloud::PubSub.new
|
|
73
91
|
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
92
|
+
# publisher = pubsub.publisher "my-topic"
|
|
93
|
+
# publisher.publish "task completed"
|
|
76
94
|
#
|
|
77
95
|
def self.new project_id: nil,
|
|
78
96
|
credentials: nil,
|
|
@@ -81,20 +99,20 @@ module Google
|
|
|
81
99
|
universe_domain: nil,
|
|
82
100
|
endpoint: nil,
|
|
83
101
|
emulator_host: nil,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
project_id ||= project || default_project_id
|
|
102
|
+
logger: nil
|
|
103
|
+
project_id ||= default_project_id
|
|
87
104
|
scope ||= configure.scope
|
|
88
105
|
timeout ||= configure.timeout
|
|
89
106
|
endpoint ||= configure.endpoint
|
|
90
107
|
universe_domain ||= configure.universe_domain
|
|
91
108
|
emulator_host ||= configure.emulator_host
|
|
109
|
+
logger ||= configure.logger
|
|
92
110
|
|
|
93
111
|
if emulator_host
|
|
94
112
|
credentials = :this_channel_is_insecure
|
|
95
113
|
endpoint = emulator_host
|
|
96
114
|
else
|
|
97
|
-
credentials ||=
|
|
115
|
+
credentials ||= default_credentials scope: scope
|
|
98
116
|
unless credentials.is_a? Google::Auth::Credentials
|
|
99
117
|
credentials = PubSub::Credentials.new credentials, scope: scope
|
|
100
118
|
end
|
|
@@ -104,10 +122,12 @@ module Google
|
|
|
104
122
|
project_id = project_id.to_s # Always cast to a string
|
|
105
123
|
raise ArgumentError, "project_id is missing" if project_id.empty?
|
|
106
124
|
|
|
125
|
+
logger = Google::Cloud::PubSub::InternalLogger.new logger
|
|
107
126
|
service = PubSub::Service.new project_id, credentials,
|
|
108
127
|
host: endpoint,
|
|
109
128
|
timeout: timeout,
|
|
110
|
-
universe_domain: universe_domain
|
|
129
|
+
universe_domain: universe_domain,
|
|
130
|
+
logger: logger
|
|
111
131
|
PubSub::Project.new service
|
|
112
132
|
end
|
|
113
133
|
|
|
@@ -116,12 +136,10 @@ module Google
|
|
|
116
136
|
#
|
|
117
137
|
# The following PubSub configuration parameters are supported:
|
|
118
138
|
#
|
|
119
|
-
# * `project_id` - (String) Identifier for a PubSub project.
|
|
120
|
-
# parameter `project` is considered deprecated, but may also be used.)
|
|
139
|
+
# * `project_id` - (String) Identifier for a PubSub project.
|
|
121
140
|
# * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
|
|
122
141
|
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
|
123
|
-
# Google::Auth::Credentials object. (See {PubSub::Credentials})
|
|
124
|
-
# parameter `keyfile` is considered deprecated, but may also be used.)
|
|
142
|
+
# Google::Auth::Credentials object. (See {PubSub::Credentials})
|
|
125
143
|
# * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
|
|
126
144
|
# the set of resources and operations that the connection can access.
|
|
127
145
|
# * `quota_project` - (String) The project ID for a project that can be
|
|
@@ -133,7 +151,7 @@ module Google
|
|
|
133
151
|
# `ENV["PUBSUB_EMULATOR_HOST"]`
|
|
134
152
|
# * `on_error` - (Proc) A Proc to be run when an error is encountered
|
|
135
153
|
# on a background thread. The Proc must take the error object as the
|
|
136
|
-
# single argument. (See {
|
|
154
|
+
# single argument. (See {MessageListener.on_error}.)
|
|
137
155
|
#
|
|
138
156
|
# @return [Google::Cloud::Config] The configuration object the
|
|
139
157
|
# Google::Cloud::PubSub library uses.
|
data/lib/google-cloud-pubsub.rb
CHANGED
|
@@ -23,6 +23,7 @@ gem "google-cloud-core"
|
|
|
23
23
|
require "google/cloud" unless defined? Google::Cloud.new
|
|
24
24
|
require "google/cloud/config"
|
|
25
25
|
require "googleauth"
|
|
26
|
+
require "logger"
|
|
26
27
|
|
|
27
28
|
module Google
|
|
28
29
|
module Cloud
|
|
@@ -50,8 +51,9 @@ module Google
|
|
|
50
51
|
#
|
|
51
52
|
# gcloud = Google::Cloud.new
|
|
52
53
|
# pubsub = gcloud.pubsub
|
|
53
|
-
#
|
|
54
|
-
#
|
|
54
|
+
# topic_admin = pubsub.topic_admin
|
|
55
|
+
# publisher = pubsub.publisher "my-topic"
|
|
56
|
+
# publisher.publish "task completed"
|
|
55
57
|
#
|
|
56
58
|
# @example The default scope can be overridden with the `scope` option:
|
|
57
59
|
# require "google/cloud"
|
|
@@ -75,10 +77,24 @@ module Google
|
|
|
75
77
|
# @param [String] project_id Project identifier for the Pub/Sub service you
|
|
76
78
|
# are connecting to. If not present, the default project for the
|
|
77
79
|
# credentials is used.
|
|
78
|
-
# @param [
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
80
|
+
# @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
|
|
81
|
+
# object. (See {Google::Cloud::PubSub::Credentials})
|
|
82
|
+
# @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
|
|
83
|
+
# is deprecated. Providing an unvalidated credential configuration to
|
|
84
|
+
# Google APIs can compromise the security of your systems and data.
|
|
85
|
+
#
|
|
86
|
+
# @example
|
|
87
|
+
#
|
|
88
|
+
# # The recommended way to provide credentials is to use the `make_creds` method
|
|
89
|
+
# # on the appropriate credentials class for your environment.
|
|
90
|
+
#
|
|
91
|
+
# require "googleauth"
|
|
92
|
+
#
|
|
93
|
+
# credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
|
|
94
|
+
# json_key_io: ::File.open("/path/to/keyfile.json")
|
|
95
|
+
# )
|
|
96
|
+
#
|
|
97
|
+
# pubsub = Google::Cloud::Pubsub.new project_id: "my-project", credentials: credentials
|
|
82
98
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
|
83
99
|
# set of resources and operations that the connection can access. See
|
|
84
100
|
# [Using OAuth 2.0 to Access Google
|
|
@@ -96,8 +112,8 @@ module Google
|
|
|
96
112
|
#
|
|
97
113
|
# pubsub = Google::Cloud.pubsub
|
|
98
114
|
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
115
|
+
# publisher = pubsub.publisher "my-topic"
|
|
116
|
+
# publisher.publish "task completed"
|
|
101
117
|
#
|
|
102
118
|
def self.pubsub project_id = nil,
|
|
103
119
|
credentials = nil,
|
|
@@ -127,6 +143,8 @@ Google::Cloud.configure.add_config! :pubsub do |config| # rubocop:disable Metric
|
|
|
127
143
|
"https://www.googleapis.com/auth/pubsub"
|
|
128
144
|
]
|
|
129
145
|
|
|
146
|
+
default_logger = Logger.new $stdout
|
|
147
|
+
|
|
130
148
|
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
|
131
149
|
config.add_alias! :project, :project_id
|
|
132
150
|
config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
|
|
@@ -138,4 +156,5 @@ Google::Cloud.configure.add_config! :pubsub do |config| # rubocop:disable Metric
|
|
|
138
156
|
config.add_field! :on_error, nil, match: Proc
|
|
139
157
|
config.add_field! :endpoint, nil, match: String
|
|
140
158
|
config.add_field! :universe_domain, nil, match: String
|
|
159
|
+
config.add_field! :logger, default_logger, match: Logger, allow_nil: true
|
|
141
160
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: google-cloud-pubsub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 3.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Moore
|
|
8
8
|
- Chris Smith
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: concurrent-ruby
|
|
@@ -16,42 +16,42 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.
|
|
19
|
+
version: '1.3'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.
|
|
26
|
+
version: '1.3'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: google-cloud-core
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '1.
|
|
33
|
+
version: '1.8'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '1.
|
|
40
|
+
version: '1.8'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: google-cloud-pubsub-v1
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '1.
|
|
47
|
+
version: '1.11'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '1.
|
|
54
|
+
version: '1.11'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: retriable
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -87,6 +87,7 @@ files:
|
|
|
87
87
|
- lib/google-cloud-pubsub.rb
|
|
88
88
|
- lib/google/cloud/pubsub.rb
|
|
89
89
|
- lib/google/cloud/pubsub/acknowledge_result.rb
|
|
90
|
+
- lib/google/cloud/pubsub/admin_clients.rb
|
|
90
91
|
- lib/google/cloud/pubsub/async_publisher.rb
|
|
91
92
|
- lib/google/cloud/pubsub/async_publisher/batch.rb
|
|
92
93
|
- lib/google/cloud/pubsub/batch_publisher.rb
|
|
@@ -94,28 +95,20 @@ files:
|
|
|
94
95
|
- lib/google/cloud/pubsub/credentials.rb
|
|
95
96
|
- lib/google/cloud/pubsub/errors.rb
|
|
96
97
|
- lib/google/cloud/pubsub/flow_controller.rb
|
|
98
|
+
- lib/google/cloud/pubsub/internal_logger.rb
|
|
97
99
|
- lib/google/cloud/pubsub/message.rb
|
|
98
|
-
- lib/google/cloud/pubsub/
|
|
100
|
+
- lib/google/cloud/pubsub/message_listener.rb
|
|
101
|
+
- lib/google/cloud/pubsub/message_listener/enumerator_queue.rb
|
|
102
|
+
- lib/google/cloud/pubsub/message_listener/inventory.rb
|
|
103
|
+
- lib/google/cloud/pubsub/message_listener/sequencer.rb
|
|
104
|
+
- lib/google/cloud/pubsub/message_listener/stream.rb
|
|
105
|
+
- lib/google/cloud/pubsub/message_listener/timed_unary_buffer.rb
|
|
99
106
|
- lib/google/cloud/pubsub/project.rb
|
|
100
107
|
- lib/google/cloud/pubsub/publish_result.rb
|
|
108
|
+
- lib/google/cloud/pubsub/publisher.rb
|
|
101
109
|
- lib/google/cloud/pubsub/received_message.rb
|
|
102
|
-
- lib/google/cloud/pubsub/retry_policy.rb
|
|
103
|
-
- lib/google/cloud/pubsub/schema.rb
|
|
104
|
-
- lib/google/cloud/pubsub/schema/list.rb
|
|
105
110
|
- lib/google/cloud/pubsub/service.rb
|
|
106
|
-
- lib/google/cloud/pubsub/snapshot.rb
|
|
107
|
-
- lib/google/cloud/pubsub/snapshot/list.rb
|
|
108
111
|
- lib/google/cloud/pubsub/subscriber.rb
|
|
109
|
-
- lib/google/cloud/pubsub/subscriber/enumerator_queue.rb
|
|
110
|
-
- lib/google/cloud/pubsub/subscriber/inventory.rb
|
|
111
|
-
- lib/google/cloud/pubsub/subscriber/sequencer.rb
|
|
112
|
-
- lib/google/cloud/pubsub/subscriber/stream.rb
|
|
113
|
-
- lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb
|
|
114
|
-
- lib/google/cloud/pubsub/subscription.rb
|
|
115
|
-
- lib/google/cloud/pubsub/subscription/list.rb
|
|
116
|
-
- lib/google/cloud/pubsub/subscription/push_config.rb
|
|
117
|
-
- lib/google/cloud/pubsub/topic.rb
|
|
118
|
-
- lib/google/cloud/pubsub/topic/list.rb
|
|
119
112
|
- lib/google/cloud/pubsub/version.rb
|
|
120
113
|
homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-pubsub
|
|
121
114
|
licenses:
|
|
@@ -128,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
128
121
|
requirements:
|
|
129
122
|
- - ">="
|
|
130
123
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: '3.
|
|
124
|
+
version: '3.1'
|
|
132
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
126
|
requirements:
|
|
134
127
|
- - ">="
|
|
135
128
|
- !ruby/object:Gem::Version
|
|
136
129
|
version: '0'
|
|
137
130
|
requirements: []
|
|
138
|
-
rubygems_version: 3.6.
|
|
131
|
+
rubygems_version: 3.6.9
|
|
139
132
|
specification_version: 4
|
|
140
133
|
summary: API Client library for Google Cloud Pub/Sub
|
|
141
134
|
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
|
|
@@ -1,88 +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
|
-
# # RetryPolicy
|
|
23
|
-
#
|
|
24
|
-
# An immutable Retry Policy value object that specifies how Cloud Pub/Sub retries message delivery.
|
|
25
|
-
#
|
|
26
|
-
# Retry delay will be exponential based on provided minimum and maximum backoffs. (See [Exponential
|
|
27
|
-
# backoff](https://en.wikipedia.org/wiki/Exponential_backoff).)
|
|
28
|
-
#
|
|
29
|
-
# Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events for a given message.
|
|
30
|
-
#
|
|
31
|
-
# Retry Policy is implemented on a best effort basis. At times, the delay between consecutive deliveries may not
|
|
32
|
-
# match the configuration. That is, delay can be more or less than configured backoff.
|
|
33
|
-
#
|
|
34
|
-
# @attr [Numeric] minimum_backoff The minimum delay between consecutive deliveries of a given message. Value
|
|
35
|
-
# should be between 0 and 600 seconds. The default value is 10 seconds.
|
|
36
|
-
# @attr [Numeric] maximum_backoff The maximum delay between consecutive deliveries of a given message. Value
|
|
37
|
-
# should be between 0 and 600 seconds. The default value is 600 seconds.
|
|
38
|
-
#
|
|
39
|
-
# @example
|
|
40
|
-
# require "google/cloud/pubsub"
|
|
41
|
-
#
|
|
42
|
-
# pubsub = Google::Cloud::PubSub.new
|
|
43
|
-
#
|
|
44
|
-
# sub = pubsub.subscription "my-topic-sub"
|
|
45
|
-
#
|
|
46
|
-
# sub.retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
|
|
47
|
-
#
|
|
48
|
-
# sub.retry_policy.minimum_backoff #=> 5
|
|
49
|
-
# sub.retry_policy.maximum_backoff #=> 300
|
|
50
|
-
#
|
|
51
|
-
class RetryPolicy
|
|
52
|
-
attr_reader :minimum_backoff
|
|
53
|
-
attr_reader :maximum_backoff
|
|
54
|
-
|
|
55
|
-
##
|
|
56
|
-
# Creates a new, immutable RetryPolicy value object.
|
|
57
|
-
#
|
|
58
|
-
# @attr [Numeric, nil] minimum_backoff The minimum delay between consecutive deliveries of a given message.
|
|
59
|
-
# Value should be between 0 and 600 seconds. If `nil` is provided, the default value is 10 seconds.
|
|
60
|
-
# @attr [Numeric, nil] maximum_backoff The maximum delay between consecutive deliveries of a given message.
|
|
61
|
-
# Value should be between 0 and 600 seconds. If `nil` is provided, the default value is 600 seconds.
|
|
62
|
-
#
|
|
63
|
-
def initialize minimum_backoff: nil, maximum_backoff: nil
|
|
64
|
-
@minimum_backoff = minimum_backoff
|
|
65
|
-
@maximum_backoff = maximum_backoff
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
##
|
|
69
|
-
# @private Convert the RetryPolicy to a Google::Cloud::PubSub::V1::RetryPolicy object.
|
|
70
|
-
def to_grpc
|
|
71
|
-
Google::Cloud::PubSub::V1::RetryPolicy.new(
|
|
72
|
-
minimum_backoff: Convert.number_to_duration(minimum_backoff),
|
|
73
|
-
maximum_backoff: Convert.number_to_duration(maximum_backoff)
|
|
74
|
-
)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
##
|
|
78
|
-
# @private New RetryPolicy from a Google::Cloud::PubSub::V1::RetryPolicy object.
|
|
79
|
-
def self.from_grpc grpc
|
|
80
|
-
new(
|
|
81
|
-
minimum_backoff: Convert.duration_to_number(grpc.minimum_backoff),
|
|
82
|
-
maximum_backoff: Convert.duration_to_number(grpc.maximum_backoff)
|
|
83
|
-
)
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|