pubnub 4.6.1 → 4.8.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.
Potentially problematic release.
This version of pubnub might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +3 -1
- data/.github/workflows/commands-handler.yml +27 -0
- data/.github/workflows/release/versions.json +17 -0
- data/.github/workflows/release.yml +58 -0
- data/.github/workflows/run_acceptance_tests.yml +46 -0
- data/.gitignore +18 -0
- data/.pubnub.yml +32 -4
- data/.travis.yml +0 -4
- data/CHANGELOG.md +31 -6
- data/Gemfile +2 -0
- data/Gemfile.lock +42 -1
- data/VERSION +1 -1
- data/config/cucumber.yml +7 -0
- data/features/step_definitions/access_steps.rb +256 -0
- data/features/support/env.rb +15 -0
- data/features/support/helper.rb +39 -0
- data/features/support/hooks.rb +98 -0
- data/lib/pubnub/cbor.rb +182 -0
- data/lib/pubnub/client/events.rb +1 -1
- data/lib/pubnub/client/paged_history.rb +144 -17
- data/lib/pubnub/client.rb +14 -0
- data/lib/pubnub/constants.rb +10 -7
- data/lib/pubnub/event.rb +21 -10
- data/lib/pubnub/events/grant_token.rb +172 -0
- data/lib/pubnub/events/revoke_token.rb +66 -0
- data/lib/pubnub/validators/grant_token.rb +51 -0
- data/lib/pubnub/validators/revoke_token.rb +31 -0
- data/lib/pubnub/version.rb +1 -1
- metadata +22 -4
data/lib/pubnub/event.rb
CHANGED
@@ -24,8 +24,8 @@ module Pubnub
|
|
24
24
|
env.delete(:state)
|
25
25
|
create_variables_from_options(env.merge(options))
|
26
26
|
@origin = @app.current_origin
|
27
|
-
format_channels
|
28
|
-
format_group
|
27
|
+
format_channels if enable_format_channels?
|
28
|
+
format_group if enable_format_group?
|
29
29
|
set_timestamp
|
30
30
|
validate!
|
31
31
|
telemetry = @app.telemetry_for(@telemetry_name)
|
@@ -44,7 +44,7 @@ module Pubnub
|
|
44
44
|
envelopes
|
45
45
|
end
|
46
46
|
|
47
|
-
def send_request(compressed_body = '')
|
47
|
+
def send_request(compressed_body = '', header = {})
|
48
48
|
Pubnub.logger.debug('Pubnub::Event') { '#send_request called' }
|
49
49
|
|
50
50
|
@compressed_body = compressed_body
|
@@ -54,13 +54,13 @@ module Pubnub
|
|
54
54
|
telemetry_time_start = ::Time.now.to_f
|
55
55
|
response = case operation_http_method
|
56
56
|
when "get"
|
57
|
-
sender.get(uri.to_s)
|
57
|
+
sender.get(uri.to_s, header: header)
|
58
58
|
when "post"
|
59
|
-
sender.post(uri.to_s, body: compressed_body)
|
59
|
+
sender.post(uri.to_s, body: compressed_body, header: header)
|
60
60
|
when "patch"
|
61
|
-
sender.patch(uri.to_s, body: compressed_body)
|
61
|
+
sender.patch(uri.to_s, body: compressed_body, header: header)
|
62
62
|
else
|
63
|
-
sender.delete(uri.to_s)
|
63
|
+
sender.delete(uri.to_s, header: header)
|
64
64
|
end
|
65
65
|
|
66
66
|
begin
|
@@ -102,9 +102,18 @@ module Pubnub
|
|
102
102
|
|
103
103
|
private
|
104
104
|
|
105
|
+
def enable_format_channels?
|
106
|
+
true
|
107
|
+
end
|
108
|
+
|
109
|
+
def enable_format_group?
|
110
|
+
true
|
111
|
+
end
|
112
|
+
|
105
113
|
def operation_http_method
|
106
114
|
case @event
|
107
|
-
when Pubnub::Constants::OPERATION_DELETE, Pubnub::Constants::OPERATION_REMOVE_CHANNEL_METADATA,
|
115
|
+
when Pubnub::Constants::OPERATION_DELETE, Pubnub::Constants::OPERATION_REMOVE_CHANNEL_METADATA,
|
116
|
+
Pubnub::Constants::OPERATION_REMOVE_UUID_METADATA, Pubnub::Constants::OPERATION_REVOKE_TOKEN
|
108
117
|
"delete"
|
109
118
|
when Pubnub::Constants::OPERATION_SET_UUID_METADATA, Pubnub::Constants::OPERATION_SET_CHANNEL_METADATA,
|
110
119
|
Pubnub::Constants::OPERATION_SET_CHANNEL_MEMBERS, Pubnub::Constants::OPERATION_SET_MEMBERSHIPS,
|
@@ -136,8 +145,9 @@ module Pubnub
|
|
136
145
|
pnsdk: @app.sdk_version
|
137
146
|
}
|
138
147
|
|
148
|
+
token = @app.env[:token]
|
139
149
|
empty_if_blank = {
|
140
|
-
auth: @auth_key,
|
150
|
+
auth: token ? token : @auth_key,
|
141
151
|
uuid: @app.env[:uuid],
|
142
152
|
@telemetry_name => @current_telemetry
|
143
153
|
}
|
@@ -164,7 +174,8 @@ module Pubnub
|
|
164
174
|
end count limit reverse presence_callback store skip_validate
|
165
175
|
state channel_group channel_groups compressed meta customs include_token
|
166
176
|
replicate with_presence cipher_key_selector include_meta join update get
|
167
|
-
add remove push_token push_gateway environment topic
|
177
|
+
add remove push_token push_gateway environment topic authorized_uuid
|
178
|
+
token
|
168
179
|
]
|
169
180
|
|
170
181
|
options = options.each_with_object({}) { |option, obj| obj[option.first.to_sym] = option.last }
|
@@ -0,0 +1,172 @@
|
|
1
|
+
module Pubnub
|
2
|
+
# Holds grant token functionality
|
3
|
+
class GrantToken < SingleEvent
|
4
|
+
include Concurrent::Async
|
5
|
+
include Pubnub::Validator::GrantToken
|
6
|
+
|
7
|
+
def initialize(options, app)
|
8
|
+
@event = current_operation
|
9
|
+
@telemetry_name = :l_pamv3
|
10
|
+
@uuids = options[:uuids] || {}
|
11
|
+
options[:channels] = options[:channels] || {}
|
12
|
+
options[:channel_groups] = options[:channel_groups] || {}
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def fire
|
17
|
+
Pubnub.logger.debug('Pubnub::GrantToken') { "Fired event #{self.class}" }
|
18
|
+
|
19
|
+
raw_body = {
|
20
|
+
ttl: @ttl,
|
21
|
+
permissions: {
|
22
|
+
meta: @meta,
|
23
|
+
uuid: @authorized_uuid,
|
24
|
+
resources: prepare_permissions(:resource, @channels, @channel_groups, @uuids),
|
25
|
+
patterns: prepare_permissions(:pattern, @channels, @channel_groups, @uuids)
|
26
|
+
}.select { |_, v| v }
|
27
|
+
}
|
28
|
+
body = Formatter.format_message(raw_body, "", false, false)
|
29
|
+
response = send_request(body, { "Content-Type": "application/json" })
|
30
|
+
|
31
|
+
envelopes = fire_callbacks(handle(response, uri))
|
32
|
+
finalize_event(envelopes)
|
33
|
+
envelopes
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def enable_format_channels?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def enable_format_group?
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_operation
|
47
|
+
Pubnub::Constants::OPERATION_GRANT_TOKEN
|
48
|
+
end
|
49
|
+
|
50
|
+
def prepare_permissions(type, channels, groups, uuids)
|
51
|
+
{
|
52
|
+
channels: prepare_single_permissions(type, channels),
|
53
|
+
groups: prepare_single_permissions(type, groups),
|
54
|
+
uuids: prepare_single_permissions(type, uuids)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def prepare_single_permissions(type, resources)
|
59
|
+
resources
|
60
|
+
.select { |_, v| v.type == type }
|
61
|
+
.to_h { |k, v| [k, v.calculate_bitmask] }
|
62
|
+
end
|
63
|
+
|
64
|
+
def valid_envelope(parsed_response, req_res_objects)
|
65
|
+
Pubnub::Envelope.new(
|
66
|
+
event: @event,
|
67
|
+
event_options: @given_options,
|
68
|
+
timetoken: nil,
|
69
|
+
status: {
|
70
|
+
code: req_res_objects[:response].code,
|
71
|
+
client_request: req_res_objects[:request],
|
72
|
+
server_response: req_res_objects[:response],
|
73
|
+
category: Pubnub::Constants::STATUS_ACK,
|
74
|
+
error: false,
|
75
|
+
auto_retried: false,
|
76
|
+
|
77
|
+
current_timetoken: nil,
|
78
|
+
last_timetoken: nil,
|
79
|
+
subscribed_channels: nil,
|
80
|
+
subscribed_channel_groups: nil,
|
81
|
+
|
82
|
+
data: nil,
|
83
|
+
|
84
|
+
config: get_config
|
85
|
+
|
86
|
+
},
|
87
|
+
result: {
|
88
|
+
code: req_res_objects[:response].code,
|
89
|
+
operation: current_operation,
|
90
|
+
client_request: req_res_objects[:request],
|
91
|
+
server_response: req_res_objects[:response],
|
92
|
+
|
93
|
+
data: parsed_response['data']
|
94
|
+
}
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def path
|
99
|
+
'/' + [
|
100
|
+
'v3',
|
101
|
+
'pam',
|
102
|
+
@subscribe_key,
|
103
|
+
'grant'
|
104
|
+
].join('/')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class Permissions
|
109
|
+
attr_reader :type
|
110
|
+
|
111
|
+
class << Permissions
|
112
|
+
def pat(read: false, write: false, manage: false, delete: false,
|
113
|
+
create: false, get: false, update: false, join: false)
|
114
|
+
Permissions.new(
|
115
|
+
type: :pattern,
|
116
|
+
read: read,
|
117
|
+
write: write,
|
118
|
+
manage: manage,
|
119
|
+
delete: delete,
|
120
|
+
create: create,
|
121
|
+
get: get,
|
122
|
+
update: update,
|
123
|
+
join: join
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
def res(read: false, write: false, manage: false, delete: false, create: false, get: false, update: false, join: false)
|
128
|
+
Permissions.new(
|
129
|
+
type: :resource,
|
130
|
+
read: read,
|
131
|
+
write: write,
|
132
|
+
manage: manage,
|
133
|
+
delete: delete,
|
134
|
+
create: create,
|
135
|
+
get: get,
|
136
|
+
update: update,
|
137
|
+
join: join
|
138
|
+
)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def initialize(options)
|
143
|
+
@type = options[:type]
|
144
|
+
@read = options[:read] || false
|
145
|
+
@write = options[:write] || false
|
146
|
+
@manage = options[:manage] || false
|
147
|
+
@delete = options[:delete] || false
|
148
|
+
@create = options[:create] || false
|
149
|
+
@get = options[:get] || false
|
150
|
+
@update = options[:update] || false
|
151
|
+
@join = options[:join] || false
|
152
|
+
end
|
153
|
+
|
154
|
+
def to_s
|
155
|
+
"Permissions: {:read => #{@read}, :write => #{@write}, :manage => #{@manage} , :delete => #{@delete}, :create => #{@create}, :get => #{@get}, :update => #{@update}, :join => #{@join}}"
|
156
|
+
end
|
157
|
+
|
158
|
+
def calculate_bitmask
|
159
|
+
sum = 0
|
160
|
+
|
161
|
+
sum |= 1 if @read
|
162
|
+
sum |= 2 if @write
|
163
|
+
sum |= 4 if @manage
|
164
|
+
sum |= 8 if @delete
|
165
|
+
sum |= 16 if @create
|
166
|
+
sum |= 32 if @get
|
167
|
+
sum |= 64 if @update
|
168
|
+
sum |= 128 if @join
|
169
|
+
sum
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Pubnub
|
2
|
+
# Holds revoke token functionality
|
3
|
+
class RevokeToken < SingleEvent
|
4
|
+
include Concurrent::Async
|
5
|
+
include Pubnub::Validator::RevokeToken
|
6
|
+
|
7
|
+
def initialize(options, app)
|
8
|
+
@event = :revoke_token
|
9
|
+
super
|
10
|
+
@token = @token.split(' ')
|
11
|
+
.map{ |part| CGI.escape(part) }
|
12
|
+
.join("%20")
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def current_operation
|
18
|
+
Pubnub::Constants::OPERATION_GRANT_TOKEN
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_envelope(parsed_response, req_res_objects)
|
22
|
+
Pubnub::Envelope.new(
|
23
|
+
event: @event,
|
24
|
+
event_options: @given_options,
|
25
|
+
timetoken: nil,
|
26
|
+
status: {
|
27
|
+
code: req_res_objects[:response].code,
|
28
|
+
client_request: req_res_objects[:request],
|
29
|
+
server_response: req_res_objects[:response],
|
30
|
+
category: Pubnub::Constants::STATUS_ACK,
|
31
|
+
error: false,
|
32
|
+
auto_retried: false,
|
33
|
+
|
34
|
+
current_timetoken: nil,
|
35
|
+
last_timetoken: nil,
|
36
|
+
subscribed_channels: nil,
|
37
|
+
subscribed_channel_groups: nil,
|
38
|
+
|
39
|
+
data: nil,
|
40
|
+
|
41
|
+
config: get_config
|
42
|
+
|
43
|
+
},
|
44
|
+
result: {
|
45
|
+
code: req_res_objects[:response].code,
|
46
|
+
operation: current_operation,
|
47
|
+
client_request: req_res_objects[:request],
|
48
|
+
server_response: req_res_objects[:response],
|
49
|
+
|
50
|
+
data: parsed_response['data']
|
51
|
+
}
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def path
|
57
|
+
'/' + [
|
58
|
+
'v3',
|
59
|
+
'pam',
|
60
|
+
@subscribe_key,
|
61
|
+
'grant',
|
62
|
+
@token
|
63
|
+
].join('/')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Toplevel Pubnub module.
|
2
|
+
module Pubnub
|
3
|
+
# Validator module that holds all validators modules
|
4
|
+
module Validator
|
5
|
+
# Validator for Grant event
|
6
|
+
module GrantToken
|
7
|
+
include CommonValidator
|
8
|
+
|
9
|
+
def validate!
|
10
|
+
validate_keys!
|
11
|
+
validate_ttl!
|
12
|
+
validate_permissions!(@uuids, ":uuids")
|
13
|
+
validate_permissions!(@channels, ":channels")
|
14
|
+
validate_permissions!(@channel_groups, ":uuids")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def validate_keys!
|
20
|
+
raise(
|
21
|
+
ArgumentError.new(object: self, message: ':subscribe_key is required for grant token event.'),
|
22
|
+
':subscribe_key is required for grant token event.'
|
23
|
+
) if @subscribe_key.nil? || @subscribe_key.empty?
|
24
|
+
|
25
|
+
raise(
|
26
|
+
ArgumentError.new(object: self, message: ':secret_key is required for grant token event.'),
|
27
|
+
':publish_key is required for grant token event.'
|
28
|
+
) if @secret_key.nil? || @secret_key.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_ttl!
|
32
|
+
return unless !@ttl.nil? && !@ttl.is_a?(Integer)
|
33
|
+
|
34
|
+
raise(
|
35
|
+
ArgumentError.new(object: self, message: ':ttl has to be kind of Integer for grant token event.'),
|
36
|
+
':ttl has to be kind of Integer for grant token event.'
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_permissions!(arg, name)
|
41
|
+
return if arg.nil?
|
42
|
+
|
43
|
+
raise(
|
44
|
+
ArgumentError.new(object: self, message: ":#{name} has to be kind of Hash for grant token event."),
|
45
|
+
":#{name} has to be kind of Hash for grant token event."
|
46
|
+
) unless arg.is_a?(Hash)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Toplevel Pubnub module.
|
2
|
+
module Pubnub
|
3
|
+
# Validator module that holds all validators modules
|
4
|
+
module Validator
|
5
|
+
# Validator for Grant event
|
6
|
+
module RevokeToken
|
7
|
+
include CommonValidator
|
8
|
+
|
9
|
+
def validate!
|
10
|
+
validate_keys!
|
11
|
+
validate_token!
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def validate_keys!
|
17
|
+
raise(
|
18
|
+
ArgumentError.new(object: self, message: ':subscribe_key is required for revoke token event.'),
|
19
|
+
':subscribe_key is required for grant token event.'
|
20
|
+
) if @subscribe_key.nil? || @subscribe_key.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_token!
|
24
|
+
raise(
|
25
|
+
ArgumentError.new(object: self, message: ':token is required for revoke token event.'),
|
26
|
+
':token is required for revoke token event.'
|
27
|
+
) if @token.nil? || @token.empty?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/pubnub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubnub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PubNub
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -130,6 +130,10 @@ files:
|
|
130
130
|
- ".bundle/config"
|
131
131
|
- ".codeclimate.yml"
|
132
132
|
- ".github/CODEOWNERS"
|
133
|
+
- ".github/workflows/commands-handler.yml"
|
134
|
+
- ".github/workflows/release.yml"
|
135
|
+
- ".github/workflows/release/versions.json"
|
136
|
+
- ".github/workflows/run_acceptance_tests.yml"
|
133
137
|
- ".github/workflows/validate-pubnub-yml.yml"
|
134
138
|
- ".github/workflows/validate-yml.js"
|
135
139
|
- ".gitignore"
|
@@ -145,7 +149,12 @@ files:
|
|
145
149
|
- README.md
|
146
150
|
- Rakefile
|
147
151
|
- VERSION
|
152
|
+
- config/cucumber.yml
|
148
153
|
- docs.md
|
154
|
+
- features/step_definitions/access_steps.rb
|
155
|
+
- features/support/env.rb
|
156
|
+
- features/support/helper.rb
|
157
|
+
- features/support/hooks.rb
|
149
158
|
- gemfiles/celluloid_017.gemfile
|
150
159
|
- gemfiles/celluloid_017.gemfile.lock
|
151
160
|
- gemfiles/celluloid_018.gemfile
|
@@ -155,6 +164,7 @@ files:
|
|
155
164
|
- gemfiles/concurrent-ruby-1.0.5.gem
|
156
165
|
- gemfiles/concurrent-ruby-edge-0.3.1.gem
|
157
166
|
- lib/pubnub.rb
|
167
|
+
- lib/pubnub/cbor.rb
|
158
168
|
- lib/pubnub/client.rb
|
159
169
|
- lib/pubnub/client/events.rb
|
160
170
|
- lib/pubnub/client/getters_setters.rb
|
@@ -180,6 +190,7 @@ files:
|
|
180
190
|
- lib/pubnub/events/get_memberships.rb
|
181
191
|
- lib/pubnub/events/get_uuid_metadata.rb
|
182
192
|
- lib/pubnub/events/grant.rb
|
193
|
+
- lib/pubnub/events/grant_token.rb
|
183
194
|
- lib/pubnub/events/heartbeat.rb
|
184
195
|
- lib/pubnub/events/here_now.rb
|
185
196
|
- lib/pubnub/events/history.rb
|
@@ -195,6 +206,7 @@ files:
|
|
195
206
|
- lib/pubnub/events/remove_memberships.rb
|
196
207
|
- lib/pubnub/events/remove_uuid_metadata.rb
|
197
208
|
- lib/pubnub/events/revoke.rb
|
209
|
+
- lib/pubnub/events/revoke_token.rb
|
198
210
|
- lib/pubnub/events/set_channel_members.rb
|
199
211
|
- lib/pubnub/events/set_channel_metadata.rb
|
200
212
|
- lib/pubnub/events/set_memberships.rb
|
@@ -235,6 +247,7 @@ files:
|
|
235
247
|
- lib/pubnub/validators/get_memberships.rb
|
236
248
|
- lib/pubnub/validators/get_uuid_metadata.rb
|
237
249
|
- lib/pubnub/validators/grant.rb
|
250
|
+
- lib/pubnub/validators/grant_token.rb
|
238
251
|
- lib/pubnub/validators/heartbeat.rb
|
239
252
|
- lib/pubnub/validators/here_now.rb
|
240
253
|
- lib/pubnub/validators/history.rb
|
@@ -250,6 +263,7 @@ files:
|
|
250
263
|
- lib/pubnub/validators/remove_memberships.rb
|
251
264
|
- lib/pubnub/validators/remove_uuid_metadata.rb
|
252
265
|
- lib/pubnub/validators/revoke.rb
|
266
|
+
- lib/pubnub/validators/revoke_token.rb
|
253
267
|
- lib/pubnub/validators/set_channel_members.rb
|
254
268
|
- lib/pubnub/validators/set_channel_metadata.rb
|
255
269
|
- lib/pubnub/validators/set_memberships.rb
|
@@ -281,8 +295,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
295
|
- !ruby/object:Gem::Version
|
282
296
|
version: '0'
|
283
297
|
requirements: []
|
284
|
-
rubygems_version: 3.2
|
298
|
+
rubygems_version: 3.1.2
|
285
299
|
signing_key:
|
286
300
|
specification_version: 4
|
287
301
|
summary: PubNub Official Ruby gem.
|
288
|
-
test_files:
|
302
|
+
test_files:
|
303
|
+
- features/step_definitions/access_steps.rb
|
304
|
+
- features/support/env.rb
|
305
|
+
- features/support/helper.rb
|
306
|
+
- features/support/hooks.rb
|