Skip to content

Commit af32f8a

Browse files
PubNub SDK v5.1.2 release.
1 parent 0806ad2 commit af32f8a

File tree

10 files changed

+112
-30
lines changed

10 files changed

+112
-30
lines changed

.pubnub.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
name: python
2-
version: 5.1.1
2+
version: 5.1.2
33
schema: 1
44
scm: github.com/pubnub/python
55
changelog:
6+
- version: v5.1.2
7+
date: Apr 15, 2021
8+
changes:
9+
-
10+
text: "Request headers required by the Grant Token functionality added."
11+
type: bug
612
- version: v5.1.1
713
date: Mar 29, 2021
814
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [v5.1.2](https://github.com/pubnub/python/releases/tag/v5.1.2)
2+
3+
[Full Changelog](https://github.com/pubnub/python/compare/v5.1.1...v5.1.2)
4+
5+
- 🐛 Request headers required by the Grant Token functionality added.
6+
17
## [v5.1.1](https://github.com/pubnub/python/releases/tag/v5.1.1)
28

39
[Full Changelog](https://github.com/pubnub/python/compare/v5.1.0...v5.1.1)

pubnub/endpoints/access/grant_token.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def __init__(self, pubnub):
1919
Endpoint.__init__(self, pubnub)
2020
self._ttl = None
2121
self._meta = None
22-
self._channelList = []
23-
self._groupList = []
24-
self._userList = []
25-
self._spaceList = []
22+
self._channels = []
23+
self._groups = []
24+
self._users = []
25+
self._spaces = []
2626

2727
self._sort_params = True
2828

@@ -34,28 +34,36 @@ def meta(self, meta):
3434
self._meta = meta
3535
return self
3636

37+
def channels(self, channels):
38+
self._channels = channels
39+
return self
40+
41+
def groups(self, groups):
42+
self._groups = groups
43+
return self
44+
3745
def users(self, users):
38-
self._userList = users
46+
self._users = users
3947
return self
4048

4149
def spaces(self, spaces):
42-
self._spaceList = spaces
50+
self._spaces = spaces
4351
return self
4452

4553
def custom_params(self):
4654
return {}
4755

4856
def build_data(self):
49-
params = {'ttl': str(int(self._ttl))}
57+
params = {'ttl': str(self._ttl)}
5058

5159
permissions = {}
5260
resources = {}
5361
patterns = {}
5462

55-
utils.parse_resources(self._channelList, "channels", resources, patterns)
56-
utils.parse_resources(self._groupList, "groups", resources, patterns)
57-
utils.parse_resources(self._userList, "users", resources, patterns)
58-
utils.parse_resources(self._spaceList, "spaces", resources, patterns)
63+
utils.parse_resources(self._channels, "channels", resources, patterns)
64+
utils.parse_resources(self._groups, "groups", resources, patterns)
65+
utils.parse_resources(self._users, "users", resources, patterns)
66+
utils.parse_resources(self._spaces, "spaces", resources, patterns)
5967

6068
permissions['resources'] = resources
6169
permissions['patterns'] = patterns
@@ -90,14 +98,6 @@ def create_response(self, envelope):
9098
def is_auth_required(self):
9199
return False
92100

93-
def affected_channels(self):
94-
# generate a list of channels when they become supported in PAMv3
95-
return None
96-
97-
def affected_channels_groups(self):
98-
# generate a list of groups when they become supported in PAMv3
99-
return None
100-
101101
def request_timeout(self):
102102
return self.pubnub.config.non_subscribe_request_timeout
103103

@@ -111,8 +111,10 @@ def name(self):
111111
return "Grant Token"
112112

113113
def validate_resources(self):
114-
if (self._userList is None or len(self._userList) == 0) and \
115-
(self._spaceList is None or len(self._spaceList) == 0):
114+
if (self._channels is None or len(self._channels) == 0) and \
115+
(self._groups is None or len(self._groups) == 0) and \
116+
(self._users is None or len(self._users) == 0) and \
117+
(self._spaces is None or len(self._spaces) == 0):
116118
raise PubNubException(pn_error=PNERR_RESOURCES_MISSING)
117119

118120
def validate_ttl(self):

pubnub/endpoints/endpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44

55
from pubnub import utils
6-
from pubnub.enums import PNStatusCategory
6+
from pubnub.enums import PNStatusCategory, HttpMethod
77
from pubnub.errors import (
88
PNERR_SUBSCRIBE_KEY_MISSING, PNERR_PUBLISH_KEY_MISSING, PNERR_CHANNEL_OR_GROUP_MISSING,
99
PNERR_SECRET_KEY_MISSING, PNERR_CHANNEL_MISSING, PNERR_FILE_OBJECT_MISSING,
@@ -88,7 +88,7 @@ def use_base_path(self):
8888
return True
8989

9090
def request_headers(self):
91-
if self.http_method() == "POST":
91+
if self.http_method() == HttpMethod.POST:
9292
return {"Content-type": "application/json"}
9393
else:
9494
return {}

pubnub/pubnub_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
class PubNubCore:
6767
"""A base class for PubNub Python API implementations"""
68-
SDK_VERSION = "5.1.1"
68+
SDK_VERSION = "5.1.2"
6969
SDK_NAME = "PubNub-Python"
7070

7171
TIMESTAMP_DIVIDER = 1000

pubnub/request_handlers/requests_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _invoke_request(self, p_options, e_options, base_origin):
230230
url = e_options.path
231231

232232
if e_options.request_headers:
233-
p_options.update(e_options.request_headers)
233+
p_options.headers.update(e_options.request_headers)
234234

235235
args = {
236236
"method": e_options.method_string,

pubnub/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def sign_request(endpoint, pn, custom_params, method, body):
198198

199199

200200
def parse_resources(resource_list, resource_set_name, resources, patterns):
201-
if resource_list is not None:
201+
if resource_list:
202202
for pn_resource in resource_list:
203203
resource_object = {}
204204

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pubnub',
5-
version='5.1.1',
5+
version='5.1.2',
66
description='PubNub Real-time push service in the cloud',
77
author='PubNub',
88
author_email='[email protected]',
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
interactions:
2+
- request:
3+
body: '{"ttl": "15", "permissions": {"resources": {"channels": {"foo": 1, "bar":
4+
1}, "groups": {"foo": 1, "bar": 1}, "users": {}, "spaces": {}}, "patterns":
5+
{"channels": {}, "groups": {}, "users": {}, "spaces": {}}, "meta": {}}}'
6+
headers:
7+
Accept:
8+
- '*/*'
9+
Accept-Encoding:
10+
- gzip, deflate
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '221'
15+
Content-type:
16+
- application/json
17+
User-Agent:
18+
- PubNub-Python/5.1.1
19+
method: POST
20+
uri: https://ps.pndsn.com/v3/pam/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f/grant
21+
response:
22+
body:
23+
string: '{"data":{"message":"Success","token":"p0F2AkF0GmB4Sd9DdHRsD0NyZXOkRGNoYW6iY2ZvbwFjYmFyAUNncnCiY2ZvbwFjYmFyAUN1c3KgQ3NwY6BDcGF0pERjaGFuoENncnCgQ3VzcqBDc3BjoERtZXRhoENzaWdYIBHsbMOeRAHUvsCURvZ3Yehv74QvPT4xqfHY5JPONmyJ"},"service":"Access
24+
Manager","status":200}'
25+
headers:
26+
Access-Control-Allow-Headers:
27+
- Origin, X-Requested-With, Content-Type, Accept
28+
Access-Control-Allow-Methods:
29+
- GET
30+
Access-Control-Allow-Origin:
31+
- '*'
32+
Cache-Control:
33+
- no-cache, no-store, must-revalidate
34+
Connection:
35+
- keep-alive
36+
Content-Length:
37+
- '257'
38+
Content-Type:
39+
- text/javascript; charset=UTF-8
40+
Date:
41+
- Thu, 15 Apr 2021 14:12:47 GMT
42+
status:
43+
code: 200
44+
message: OK
45+
version: 1

tests/integrational/native_sync/test_grant.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
from pubnub.pubnub import PubNub
2+
from pubnub.models.consumer.v3.channel import Channel
3+
from pubnub.models.consumer.v3.group import Group
24
from tests.integrational.vcr_helper import pn_vcr
35
from tests.helper import pnconf_pam_copy
46
from pubnub.models.consumer.access_manager import PNAccessManagerGrantResult
7+
from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult
58

69
pubnub = PubNub(pnconf_pam_copy())
710
pubnub.config.uuid = "test_grant"
811

912

10-
@pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/pam/grant_with_spaces.yaml',
11-
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature'])
13+
@pn_vcr.use_cassette(
14+
'tests/integrational/fixtures/native_sync/pam/grant_with_spaces.yaml',
15+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature']
16+
)
1217
def test_grant_auth_key_with_spaces():
1318
envelope = pubnub.grant()\
1419
.read(True)\
@@ -19,3 +24,21 @@ def test_grant_auth_key_with_spaces():
1924
.sync()
2025

2126
assert isinstance(envelope.result, PNAccessManagerGrantResult)
27+
28+
29+
@pn_vcr.use_cassette(
30+
'tests/integrational/fixtures/native_sync/pam/grant_token.yaml',
31+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature']
32+
)
33+
def test_grant_token():
34+
channels = ("foo", "bar")
35+
groups = ("foo", "bar")
36+
37+
envelope = pubnub.grant_token()\
38+
.channels([Channel.id(channel).read() for channel in channels])\
39+
.groups([Group.id(group).read() for group in groups])\
40+
.ttl(15)\
41+
.sync()
42+
43+
assert isinstance(envelope.result, PNGrantTokenResult)
44+
assert envelope.result.get_token()

0 commit comments

Comments
 (0)