pubnub 4.7.1 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c52a9cfe08cbc90c671a74610beb900b5627c81e9f24da57e0c60530aa05c5b9
4
- data.tar.gz: 5dd3300e2b6667e2364ab3e6d56f6583d3ca1eb71caa1839e9e97d3dbe68ec50
3
+ metadata.gz: e9393969418b064ec9d7b89500f7fbf2556607985ba14c3a61f77a5452830b2d
4
+ data.tar.gz: bb033ee292892b54dd13d606eee102f719bd1d51012307e3e87aa8f33ed6cde0
5
5
  SHA512:
6
- metadata.gz: 3385c44fe3b07c3f84ff233e3bc42456e0907ff56e2fd65bd6197b2bcaa6edd75c3d53268959bb1491b88e7eaf3e49308a3afbed86a3bbebc2062364336b95be
7
- data.tar.gz: 50506cf261d7d8c8240b8a25683dbe1032ebbb99b4f9dc3ba609228672fb8e3609ee43c3a0cc94052e8d80177e7e3554ee8b57458275d5a9865b37b7ad81ca1a
6
+ metadata.gz: 0a9eabe43321053374680972c48aea024f80c47b53fb98650698bffb522fd53995246749eb9561b2e136564c1a1367e6eda7a6b2307646690e8f670ff88bd30f
7
+ data.tar.gz: 2160579b9069914c28f0fdc2992608737cfc5a7235b9eac86e42a2f02fa984f5179c327cb1a3a93c4f22d0de596e662e2ce8dea84e51ade44a29f770196c60a6
@@ -25,10 +25,10 @@ jobs:
25
25
  sudo gem install bundler &&
26
26
  bundle install
27
27
  - name: Run acceptance tests (optional)
28
- run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_beta -p report_beta
28
+ run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_beta -p report_beta -f pretty
29
29
  continue-on-error: true
30
30
  - name: Run acceptance tests (required)
31
- run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_main -p report_main
31
+ run: bundle exec cucumber sdk-specifications/features/ -p mock -p run_main -p report_main -f pretty
32
32
  - name: Combine test results
33
33
  if: always()
34
34
  run: |
data/.pubnub.yml CHANGED
@@ -1,6 +1,23 @@
1
1
  ---
2
- version: "4.7.1"
2
+ version: "5.1.0"
3
3
  changelog:
4
+ - date: 2022-07-26
5
+ version: v5.1.0
6
+ changes:
7
+ - type: feature
8
+ text: "Add support for spaces and users permissions in grant_token."
9
+ - type: feature
10
+ text: "Add user_id and deprecate uuid when creating new pubnub instance."
11
+ - date: 2022-01-13
12
+ version: v5.0.0
13
+ changes:
14
+ - type: improvement
15
+ text: "BREAKING CHANGES: uuid is required parameter to create PubNub instance."
16
+ - date: 2021-12-16
17
+ version: v4.8.0
18
+ changes:
19
+ - type: feature
20
+ text: "Add revoke token feature."
4
21
  - date: 2021-11-24
5
22
  version: v4.7.1
6
23
  changes:
@@ -403,6 +420,10 @@ features:
403
420
  access:
404
421
  - ACCESS-GRANT
405
422
  - ACCESS-SECRET-KEY-ALL-ACCESS
423
+ - ACCESS-GRANT-TOKEN
424
+ - ACCESS-PARSE-TOKEN
425
+ - ACCESS-SET-TOKEN
426
+ - ACCESS-REVOKE-TOKEN
406
427
  channel-groups:
407
428
  - CHANNEL-GROUPS-ADD-CHANNELS
408
429
  - CHANNEL-GROUPS-REMOVE-CHANNELS
@@ -433,7 +454,6 @@ features:
433
454
  - PUSH-TYPE-APNS
434
455
  - PUSH-TYPE-APNS2
435
456
  - PUSH-TYPE-FCM
436
- - PUSH-TYPE-MPNS
437
457
  storage:
438
458
  - STORAGE-REVERSE
439
459
  - STORAGE-INCLUDE-TIMETOKEN
@@ -612,7 +632,7 @@ sdks:
612
632
  - x86-64
613
633
  - distribution-type: package
614
634
  distribution-repository: RubyGems
615
- package-name: pubnub-4.7.1.gem
635
+ package-name: pubnub-5.1.0.gem
616
636
  location: https://rubygems.org/gems/pubnub
617
637
  requires:
618
638
  - name: addressable
@@ -717,8 +737,8 @@ sdks:
717
737
  - x86-64
718
738
  - distribution-type: library
719
739
  distribution-repository: GitHub release
720
- package-name: pubnub-4.7.1.gem
721
- location: https://github.com/pubnub/ruby/releases/download/v4.7.1/pubnub-4.7.1.gem
740
+ package-name: pubnub-5.1.0.gem
741
+ location: https://github.com/pubnub/ruby/releases/download/v5.1.0/pubnub-5.1.0.gem
722
742
  requires:
723
743
  - name: addressable
724
744
  min-version: 2.0.0
data/.travis.yml CHANGED
@@ -26,7 +26,7 @@ jobs:
26
26
  rvm: '2.7.1'
27
27
  script: bundle exec rspec
28
28
  - name: 'Ruby JRuby'
29
- rvm: 'jruby-head'
29
+ rvm: 'jruby-9.3.4.0'
30
30
  env: JRUBY_TEST=true NO_COVERAGE=true JRUBY_OPTS="--server -J-Xms2048m -J-Xmx2048m -J-XX:-UseGCOverheadLimit -J-XX:+CMSClassUnloadingEnabled"
31
31
  jdk: oraclejdk11
32
32
  script:
data/CHANGELOG.md CHANGED
@@ -1,12 +1,31 @@
1
- ## v4.7.1
2
- November 24 2021
1
+ ## v5.1.0
2
+ July 26 2022
3
3
 
4
4
  #### Added
5
- - Add new method `all_history_messages` which return messages from requested interval or `since` / `before` date in single object.
5
+ - Add support for spaces and users permissions in grant_token.
6
+ - Add user_id and deprecate uuid when creating new pubnub instance.
6
7
 
7
- #### Fixed
8
- - Fix exception raised when optional start / end not passed to `paged_history`.
8
+ ## v5.0.0
9
+ January 13 2022
9
10
 
11
+ #### Modified
12
+ - BREAKING CHANGES: uuid is required parameter to create PubNub instance.
13
+
14
+ ## v4.8.0
15
+ December 16 2021
16
+
17
+ #### Added
18
+ - Add revoke token feature.
19
+
20
+ ## v4.7.1
21
+ November 24 2021
22
+
23
+ #### Added
24
+ - Add new method `all_history_messages` which return messages from requested interval or `since` / `before` date in single object.
25
+
26
+ #### Fixed
27
+ - Fix exception raised when optional start / end not passed to `paged_history`.
28
+
10
29
  ## v4.7.0
11
30
  November 09 2021
12
31
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pubnub (4.7.1)
4
+ pubnub (5.1.0)
5
5
  addressable (>= 2.0.0)
6
6
  concurrent-ruby (~> 1.1.5)
7
7
  concurrent-ruby-edge (~> 0.5.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.7.1
1
+ 5.1.0
@@ -12,6 +12,20 @@ Given('I have a keyset with access manager enabled') do
12
12
  logger = Logger.new(STDOUT)
13
13
  logger.level = Logger::DEBUG
14
14
  @pn_configuration['logger'] = logger
15
+ @pn_configuration['uuid'] = Pubnub::UUID.generate
16
+
17
+ @pubnub = Pubnub.new(@pn_configuration)
18
+ end
19
+
20
+ Given('I have a keyset with access manager enabled - without secret key') do
21
+ expect(ENV['PAM_SUB_KEY']).not_to be_nil
22
+ expect(ENV['PAM_PUB_KEY']).not_to be_nil
23
+ @pn_configuration['subscribe_key'] = ENV['PAM_SUB_KEY']
24
+ @pn_configuration['publish_key'] = ENV['PAM_PUB_KEY']
25
+ logger = Logger.new(STDOUT)
26
+ logger.level = Logger::DEBUG
27
+ @pn_configuration['logger'] = logger
28
+ @pn_configuration['uuid'] = Pubnub::UUID.generate
15
29
 
16
30
  @pubnub = Pubnub.new(@pn_configuration)
17
31
  end
@@ -48,17 +62,56 @@ Given('the {string} {resourceType} pattern access permissions') do |pattern, res
48
62
  }
49
63
  end
50
64
 
65
+ Given('a valid token with permissions to publish with channel {string}') do |string|
66
+ @grant_token_state[:token] = token_with_all
67
+ end
68
+
69
+ Given('a token') do
70
+ @grant_token_state[:token] = token_with_all
71
+ end
72
+
73
+ Given('an expired token with permissions to publish with channel {string}') do |string|
74
+ @grant_token_state[:token] = token_with_all
75
+ end
76
+
51
77
  And('grant pattern permission {permissionType}') do |permission_type|
52
78
  current_pattern = @grant_token_state[:current_pattern]
53
79
  @grant_token_state[:current_grant][current_pattern][:permission_type].push(permission_type)
54
80
  end
55
81
 
56
-
57
82
  When('I grant a token specifying those permissions') do
58
83
  res = call_grant_token(@pubnub, @grant_token_state)
59
84
  @grant_token_state[:parsed_token] = @pubnub.parse_token(res.result[:data]["token"])
60
85
  end
61
86
 
87
+ When('I publish a message using that auth token with channel {string}') do |channel|
88
+ @pubnub.set_token(@grant_token_state[:token])
89
+ res = @pubnub.publish(
90
+ message: "This is message",
91
+ channel: channel,
92
+ http_sync: true
93
+ )
94
+ @global_state[:last_call_res] = res
95
+ end
96
+
97
+ When('I attempt to publish a message using that auth token with channel {string}') do |channel|
98
+ @pubnub.set_token(@grant_token_state[:token])
99
+ res = @pubnub.publish(
100
+ message: "This is message",
101
+ channel: channel,
102
+ http_sync: true
103
+ )
104
+ @global_state[:last_call_res] = res
105
+ end
106
+
107
+ When('I revoke a token') do
108
+ res = @pubnub.revoke_token(
109
+ token: @grant_token_state[:token],
110
+ http_sync: true
111
+ )
112
+ @global_state[:last_call_res] = res
113
+ end
114
+
62
115
  Then('the token contains the authorized UUID {string}') do |expected_uuid|
63
116
  expect(@grant_token_state[:parsed_token]["uuid"]).to eq expected_uuid
64
117
  end
@@ -115,35 +168,37 @@ Given('deny resource permission {permissionType}') do |permission_type|
115
168
  end
116
169
 
117
170
  When('I attempt to grant a token specifying those permissions') do
118
- @grant_token_state[:error_response] = call_grant_token(@pubnub, @grant_token_state)
171
+ @global_state[:last_call_res] = call_grant_token(@pubnub, @grant_token_state)
119
172
  end
120
173
 
121
174
  Then('an error is returned') do
122
- expect(@grant_token_state[:error_response]).not_to eq nil
175
+ envelope = @global_state[:last_call_res]
176
+ expect(envelope).not_to eq nil
177
+ expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
123
178
  end
124
179
 
125
180
  Then('the error status code is {int}') do |code|
126
- expect(@grant_token_state[:error_response].status[:code]).to eq code
181
+ expect(@global_state[:last_call_res].status[:code]).to eq code
127
182
  end
128
183
 
129
184
  Then('the error message is {string}') do |error_message|
130
- expect(parse_error_body(@grant_token_state[:error_response])["error"]["message"]).to eq error_message
185
+ expect(parse_error_body(@global_state[:last_call_res])["error"]["message"]).to eq error_message
131
186
  end
132
187
 
133
188
  Then('the error source is {string}') do |error_source|
134
- expect(parse_error_body(@grant_token_state[:error_response])["error"]["source"]).to eq error_source
189
+ expect(parse_error_body(@global_state[:last_call_res])["error"]["source"]).to eq error_source
135
190
  end
136
191
 
137
192
  Then('the error detail message is {string}') do |details_message|
138
- expect(parse_error_body(@grant_token_state[:error_response])["error"]["details"][0]["message"]).to eq details_message
193
+ expect(parse_error_body(@global_state[:last_call_res])["error"]["details"][0]["message"]).to eq details_message
139
194
  end
140
195
 
141
196
  Then('the error detail location is {string}') do |details_location|
142
- expect(parse_error_body(@grant_token_state[:error_response])["error"]["details"][0]["location"]).to eq details_location
197
+ expect(parse_error_body(@global_state[:last_call_res])["error"]["details"][0]["location"]).to eq details_location
143
198
  end
144
199
 
145
200
  Then('the error detail location type is {string}') do |location_type|
146
- expect(parse_error_body(@grant_token_state[:error_response])["error"]["details"][0]["locationType"]).to eq location_type
201
+ expect(parse_error_body(@global_state[:last_call_res])["error"]["details"][0]["locationType"]).to eq location_type
147
202
  end
148
203
 
149
204
  Given('I have a known token containing an authorized UUID') do
@@ -165,3 +220,39 @@ end
165
220
  Given('I have a known token containing UUID pattern Permissions') do
166
221
  @grant_token_state[:token] = token_with_all
167
222
  end
223
+
224
+ Given('the token string {string}') do |token|
225
+ @grant_token_state[:token] = token
226
+ end
227
+
228
+ Then('the result is successful') do
229
+ envelope = @global_state[:last_call_res]
230
+ expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq false
231
+ expect(envelope.status[:code]).to eq 200
232
+ end
233
+
234
+ Then('an auth error is returned') do
235
+ envelope = @global_state[:last_call_res]
236
+ expect(envelope).not_to eq nil
237
+ expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq true
238
+ end
239
+
240
+ Then('the auth error message is {string}') do |error_message|
241
+ expect(parse_error_body(@global_state[:last_call_res])["message"]).to eq error_message
242
+ end
243
+
244
+ Then('the error service is {string}') do |service|
245
+ expect(parse_error_body(@global_state[:last_call_res])["service"]).to eq service
246
+ end
247
+
248
+ Then('I get confirmation that token has been revoked') do
249
+ envelope = @global_state[:last_call_res]
250
+ expect(envelope.is_a?(Pubnub::ErrorEnvelope)).to eq false
251
+ expect(envelope.status[:code]).to eq 200
252
+ end
253
+
254
+ Then('the error detail message is not empty') do
255
+ expect(parse_error_body(@global_state[:last_call_res])["error"]["message"].empty?).to eq false
256
+ end
257
+
258
+
@@ -3,6 +3,7 @@ require 'json'
3
3
 
4
4
  Before do |scenario|
5
5
  @grant_token_state = {}
6
+ @global_state = {}
6
7
  @grant_token_state[:current_grant] = {}
7
8
  @pn_configuration = {}
8
9
 
@@ -4,7 +4,7 @@ module Pubnub
4
4
  class Client
5
5
  # Module that holds generator for all events
6
6
  module Events
7
- EVENTS = %w[publish subscribe presence leave history here_now audit grant grant_token delete_messages
7
+ EVENTS = %w[publish subscribe presence leave history here_now audit grant grant_token revoke_token delete_messages
8
8
  revoke time heartbeat where_now set_state state channel_registration message_counts signal
9
9
  add_channels_to_push list_push_provisions remove_channels_from_push remove_device_from_push
10
10
  set_uuid_metadata set_channel_metadata remove_uuid_metadata remove_channel_metadata
@@ -1,9 +1,14 @@
1
+ require 'pubnub/validators/common_validator'
2
+
1
3
  # Toplevel Pubnub module.
2
4
  module Pubnub
3
5
  # Pubnub client Class
4
6
  class Client
5
7
  # Module that holds some getters and setters
6
8
  module GettersSetters
9
+
10
+ extend Gem::Deprecate
11
+
7
12
  def sdk_version
8
13
  "PubNub-Ruby/#{Pubnub::VERSION}"
9
14
  end
@@ -12,7 +17,7 @@ module Pubnub
12
17
  # ===========
13
18
  # <dl>
14
19
  # <dt>uuid</dt>
15
- # <dd>New uuid to be set.</dd>
20
+ # <dd>New uuid to be set. Note that this will override user_id value</dd>
16
21
  # </dl>
17
22
  #
18
23
  # Returns:
@@ -23,14 +28,38 @@ module Pubnub
23
28
  # ==============
24
29
  # Can't change uuid while subscribed. You have to leave every subscribed channel.
25
30
  def change_uuid(uuid)
26
- Pubnub.logger.debug('Pubnub::Client') { 'Changing uuid' }
27
- raise('Cannot change UUID while subscribed.') if subscribed?
28
- @env[:uuid] = uuid
31
+ change_user_id(uuid)
32
+ end
33
+ deprecate :change_uuid, :change_user_id, 2023, 1
34
+
35
+ # Parameters:
36
+ # ===========
37
+ # <dl>
38
+ # <dt>user_id</dt>
39
+ # <dd>New user_id to be set. Note that this will override uuid value</dd>
40
+ # </dl>
41
+ #
42
+ # Returns:
43
+ # ========
44
+ # New user_id.
45
+ #
46
+ # Functionality:
47
+ # ==============
48
+ # Can't change user_id while subscribed. You have to leave every subscribed channel.
49
+ def change_user_id(user_id)
50
+ Pubnub.logger.debug('Pubnub::Client') { 'Changing user_id' }
51
+ raise('Cannot change user_id while subscribed.') if subscribed?
52
+ Validator::Client.validate_user_id user_id
53
+
54
+ @env[:user_id] = user_id
29
55
  end
30
56
 
31
57
  alias session_uuid= change_uuid
32
58
  alias uuid= change_uuid
33
59
  alias set_uuid= change_uuid
60
+ alias session_user_id= change_user_id
61
+ alias user_id= change_user_id
62
+ alias set_user_id= change_user_id
34
63
 
35
64
  # Returns:
36
65
  # ========
@@ -92,7 +121,15 @@ module Pubnub
92
121
  # ========
93
122
  # Current uuid.
94
123
  def uuid
95
- @env[:uuid]
124
+ user_id
125
+ end
126
+ deprecate :uuid, :user_id, 2023, 1
127
+
128
+ # Returns:
129
+ # ========
130
+ # Current user_id.
131
+ def user_id
132
+ @env[:user_id]
96
133
  end
97
134
 
98
135
  # Returns:
data/lib/pubnub/client.rb CHANGED
@@ -37,6 +37,7 @@ require 'pubnub/validators/audit'
37
37
  require 'pubnub/validators/channel_registration'
38
38
  require 'pubnub/validators/grant'
39
39
  require 'pubnub/validators/grant_token'
40
+ require 'pubnub/validators/revoke_token'
40
41
  require 'pubnub/validators/heartbeat'
41
42
  require 'pubnub/validators/here_now'
42
43
  require 'pubnub/validators/history'
@@ -110,7 +111,10 @@ module Pubnub
110
111
  # <dd><b>optional.</b> Required to encrypt messages.</dd>
111
112
  #
112
113
  # <dt>uuid</dt>
113
- # <dd><b>optional.</b> Sets given uuid as client uuid, does not generates random uuid on init as usually.</dd>
114
+ # <dd><b>optional.</b> <b>Deprecated.</b> Sets given uuid as client uuid, does not generates random uuid on init as usually</dd>
115
+ #
116
+ # <dt>user_id</dt>
117
+ # <dd><b>required.</b> Sets given user_id as client user_id.</dd>
114
118
  #
115
119
  # <dt>origin</dt>
116
120
  # <dd><b>optional.</b> Specifies the fully qualified domain name of the PubNub origin.
@@ -154,7 +158,7 @@ module Pubnub
154
158
  # publish_key: :demo,
155
159
  # secret_key: :secret,
156
160
  # cipher_key: :other_secret,
157
- # uuid: :mad_max,
161
+ # user_id: :mad_max,
158
162
  # origin: 'custom.pubnub.com',
159
163
  # callback: ->(envelope) { puts envelope.message },
160
164
  # connect_callback: ->(message) { puts message },
@@ -288,7 +292,7 @@ module Pubnub
288
292
 
289
293
  def sequence_number_for_publish!
290
294
  @env[:sequence_number_for_publish] += 1
291
- @env[:sequence_number_for_publish] % 2**32
295
+ @env[:sequence_number_for_publish] % 2 ** 32
292
296
  end
293
297
 
294
298
  def apply_state(event)
@@ -378,19 +382,15 @@ module Pubnub
378
382
  Pubnub.logger = options[:logger] || Logger.new('pubnub.log')
379
383
  Concurrent.global_logger = Pubnub.logger
380
384
  @subscriber = Subscriber.new(self)
385
+ options[:user_id] = options[:uuid] if options[:user_id].nil?
381
386
  @env = options
382
387
  end
383
388
 
384
389
  def prepare_env
385
390
  assign_defaults
386
- generate_uuid if @env[:uuid].blank?
387
391
  setup_pools
388
392
  end
389
393
 
390
- def generate_uuid
391
- @env[:uuid] = UUID.generate
392
- end
393
-
394
394
  def assign_defaults
395
395
  @env[:origin] = @env[:origins_pool].first if @env[:origins_pool]
396
396
  default_values.each do |k, v|
@@ -58,6 +58,7 @@ module Pubnub
58
58
  OPERATION_AUDIT = :audit
59
59
  OPERATION_GRANT = :grant
60
60
  OPERATION_GRANT_TOKEN = :grant_token
61
+ OPERATION_REVOKE_TOKEN = :revoke_token
61
62
  OPERATION_REVOKE = :revoke
62
63
  OPERATION_DELETE = :delete
63
64
  OPERATION_LIST_ALL_CHANNEL_GROUPS = :list_all_channel_groups
data/lib/pubnub/event.rb CHANGED
@@ -112,7 +112,8 @@ module Pubnub
112
112
 
113
113
  def operation_http_method
114
114
  case @event
115
- when Pubnub::Constants::OPERATION_DELETE, Pubnub::Constants::OPERATION_REMOVE_CHANNEL_METADATA, Pubnub::Constants::OPERATION_REMOVE_UUID_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
116
117
  "delete"
117
118
  when Pubnub::Constants::OPERATION_SET_UUID_METADATA, Pubnub::Constants::OPERATION_SET_CHANNEL_METADATA,
118
119
  Pubnub::Constants::OPERATION_SET_CHANNEL_MEMBERS, Pubnub::Constants::OPERATION_SET_MEMBERSHIPS,
@@ -147,7 +148,7 @@ module Pubnub
147
148
  token = @app.env[:token]
148
149
  empty_if_blank = {
149
150
  auth: token ? token : @auth_key,
150
- uuid: @app.env[:uuid],
151
+ uuid: @app.user_id,
151
152
  @telemetry_name => @current_telemetry
152
153
  }
153
154
 
@@ -174,6 +175,7 @@ module Pubnub
174
175
  state channel_group channel_groups compressed meta customs include_token
175
176
  replicate with_presence cipher_key_selector include_meta join update get
176
177
  add remove push_token push_gateway environment topic authorized_uuid
178
+ authorized_user_id token
177
179
  ]
178
180
 
179
181
  options = options.each_with_object({}) { |option, obj| obj[option.first.to_sym] = option.last }
@@ -221,7 +223,7 @@ module Pubnub
221
223
  def get_config
222
224
  {
223
225
  tls: @app.env[:ssl],
224
- uuid: @app.env[:uuid],
226
+ uuid: @app.user_id,
225
227
  auth_key: @app.env[:auth_key],
226
228
  origin: @app.current_origin
227
229
  }
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
15
  @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
 
15
15
  if options[:include]
16
16
  @include = "custom" unless [0, '0', false].include?(options[:include][:custom])
@@ -10,19 +10,28 @@ module Pubnub
10
10
  @uuids = options[:uuids] || {}
11
11
  options[:channels] = options[:channels] || {}
12
12
  options[:channel_groups] = options[:channel_groups] || {}
13
+ @spaces_permissions = options[:spaces_permissions] || {}
14
+ @users_permissions = options[:users_permissions] || {}
13
15
  super
14
16
  end
15
17
 
16
18
  def fire
17
19
  Pubnub.logger.debug('Pubnub::GrantToken') { "Fired event #{self.class}" }
20
+ if @authorized_user_id != nil
21
+ uuid = @authorized_user_id
22
+ elsif @authorized_uuid != nil
23
+ uuid = @authorized_uuid
24
+ else
25
+ uuid = nil
26
+ end
18
27
 
19
28
  raw_body = {
20
29
  ttl: @ttl,
21
30
  permissions: {
22
31
  meta: @meta,
23
- uuid: @authorized_uuid,
24
- resources: prepare_permissions(:resource, @channels, @channel_groups, @uuids),
25
- patterns: prepare_permissions(:pattern, @channels, @channel_groups, @uuids)
32
+ uuid: uuid,
33
+ resources: prepare_permissions(:resource, @channels, @channel_groups, @uuids, @spaces_permissions, @users_permissions),
34
+ patterns: prepare_permissions(:pattern, @channels, @channel_groups, @uuids, @spaces_permissions, @users_permissions)
26
35
  }.select { |_, v| v }
27
36
  }
28
37
  body = Formatter.format_message(raw_body, "", false, false)
@@ -47,11 +56,11 @@ module Pubnub
47
56
  Pubnub::Constants::OPERATION_GRANT_TOKEN
48
57
  end
49
58
 
50
- def prepare_permissions(type, channels, groups, uuids)
59
+ def prepare_permissions(type, channels, groups, uuids, spaces_permissions, users_permissions)
51
60
  {
52
- channels: prepare_single_permissions(type, channels),
61
+ channels: prepare_single_permissions(type, channels).merge!(prepare_single_permissions(type, spaces_permissions)),
53
62
  groups: prepare_single_permissions(type, groups),
54
- uuids: prepare_single_permissions(type, uuids)
63
+ uuids: prepare_single_permissions(type, uuids).merge!(prepare_single_permissions(type, users_permissions))
55
64
  }
56
65
  end
57
66
 
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
15
  @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
  super
15
15
  end
16
16
 
@@ -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
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
  @limit = [options[:limit], 100].min unless options[:limit].nil?
15
15
  @sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
16
16
  @filter = options[:filter] if options[:filter] && !options[:filter].empty?
@@ -34,7 +34,7 @@ module Pubnub
34
34
  'channel',
35
35
  Formatter.channels_for_url(@channel),
36
36
  'uuid',
37
- Formatter.encode(@app.uuid),
37
+ Formatter.encode(@app.user_id),
38
38
  'data'
39
39
  ].join('/')
40
40
  end
@@ -10,7 +10,7 @@ module Pubnub
10
10
  def initialize(options, app)
11
11
  @event = current_operation
12
12
  @telemetry_name = :l_obj
13
- @uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13
+ @uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
14
14
 
15
15
  # Clean up user-provided metadata object from nils.
16
16
  @metadata = options[:metadata].delete_if { |_k, v| v.blank? } unless options[:metadata].nil?
@@ -10,7 +10,7 @@ module Pubnub
10
10
  @telemetry_name = :l_pres
11
11
  @uuid_looking_for = options[:uuid] || options['uuid']
12
12
  super
13
- @uuid = app.uuid
13
+ @uuid = app.user_id
14
14
  end
15
15
 
16
16
  private
@@ -9,7 +9,7 @@ module Pubnub
9
9
  super
10
10
  @telemetry_name = :l_pres
11
11
  @uuid_looking_for = options[:uuid] || options['uuid']
12
- @uuid = app.uuid
12
+ @uuid = app.user_id
13
13
  @event = :where_now
14
14
  end
15
15
 
@@ -290,7 +290,7 @@ module Pubnub
290
290
  def get_config
291
291
  {
292
292
  tls: @app.env[:ssl],
293
- uuid: @app.env[:uuid],
293
+ uuid: @app.user_id,
294
294
  auth_key: @app.env[:auth_key],
295
295
  origin: @app.current_origin
296
296
  }
@@ -11,6 +11,7 @@ module Pubnub
11
11
  validate_origin parameters[:origin], true
12
12
  validate_subscribe_key parameters[:subscribe_key], true
13
13
  validate_publish_key parameters[:publish_key]
14
+ validate_user_id parameters[:user_id]
14
15
  end
15
16
  end
16
17
  end
@@ -52,6 +52,22 @@ module Pubnub
52
52
  )
53
53
  end
54
54
  end
55
+
56
+ def validate_user_id(user_id)
57
+ if !user_id || user_id.blank?
58
+ raise(
59
+ InitializationError.new,
60
+ 'Missing required :user_id parameter.'
61
+ )
62
+ elsif !([String, Symbol].include?(user_id.class) ||
63
+ user_id.blank?)
64
+ raise(
65
+ InitializationError.new,
66
+ 'user_id parameter is not valid. \
67
+ Should be type of String or Symbol.'
68
+ )
69
+ end
70
+ end
55
71
  end
56
72
  end
57
73
  end
@@ -12,6 +12,7 @@ module Pubnub
12
12
  validate_permissions!(@uuids, ":uuids")
13
13
  validate_permissions!(@channels, ":channels")
14
14
  validate_permissions!(@channel_groups, ":uuids")
15
+ validate_objects_entities_separation!
15
16
  end
16
17
 
17
18
  private
@@ -45,6 +46,19 @@ module Pubnub
45
46
  ":#{name} has to be kind of Hash for grant token event."
46
47
  ) unless arg.is_a?(Hash)
47
48
  end
49
+
50
+ def validate_objects_entities_separation!
51
+ entities_set = !@spaces_permissions.empty? ||
52
+ !@users_permissions.empty?
53
+ objects_set = !@channels.empty? ||
54
+ !@channel_groups.empty? ||
55
+ !@uuids.empty?
56
+
57
+ raise(
58
+ ArgumentError.new(object: self, message: "Can't mix entities and objects"),
59
+ "Can't mix entities and objects"
60
+ ) if (entities_set && objects_set)
61
+ end
48
62
  end
49
63
  end
50
64
  end
@@ -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
@@ -1,4 +1,4 @@
1
1
  # Toplevel Pubnub module.
2
2
  module Pubnub
3
- VERSION = '4.7.1'.freeze
3
+ VERSION = '5.1.0'.freeze
4
4
  end
data/lib/pubnub.rb CHANGED
@@ -15,6 +15,7 @@ require 'concurrent-edge'
15
15
 
16
16
  require 'pubnub/version'
17
17
  require 'pubnub/client'
18
+ require 'pubnub/uuid'
18
19
 
19
20
  # Adding blank? and present? methods to Object.
20
21
  class Object
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.7.1
4
+ version: 5.1.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-25 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -151,7 +151,7 @@ files:
151
151
  - VERSION
152
152
  - config/cucumber.yml
153
153
  - docs.md
154
- - features/step_definitions/grant_token_steps.rb
154
+ - features/step_definitions/access_steps.rb
155
155
  - features/support/env.rb
156
156
  - features/support/helper.rb
157
157
  - features/support/hooks.rb
@@ -206,6 +206,7 @@ files:
206
206
  - lib/pubnub/events/remove_memberships.rb
207
207
  - lib/pubnub/events/remove_uuid_metadata.rb
208
208
  - lib/pubnub/events/revoke.rb
209
+ - lib/pubnub/events/revoke_token.rb
209
210
  - lib/pubnub/events/set_channel_members.rb
210
211
  - lib/pubnub/events/set_channel_metadata.rb
211
212
  - lib/pubnub/events/set_memberships.rb
@@ -262,6 +263,7 @@ files:
262
263
  - lib/pubnub/validators/remove_memberships.rb
263
264
  - lib/pubnub/validators/remove_uuid_metadata.rb
264
265
  - lib/pubnub/validators/revoke.rb
266
+ - lib/pubnub/validators/revoke_token.rb
265
267
  - lib/pubnub/validators/set_channel_members.rb
266
268
  - lib/pubnub/validators/set_channel_metadata.rb
267
269
  - lib/pubnub/validators/set_memberships.rb
@@ -298,7 +300,7 @@ signing_key:
298
300
  specification_version: 4
299
301
  summary: PubNub Official Ruby gem.
300
302
  test_files:
301
- - features/step_definitions/grant_token_steps.rb
303
+ - features/step_definitions/access_steps.rb
302
304
  - features/support/env.rb
303
305
  - features/support/helper.rb
304
306
  - features/support/hooks.rb