Skip to content

Commit 1636a7b

Browse files
seba-alnClient Engineering Bot
andauthored
Grant Token with SUM (#129)
* Grant Token with SUM * Add tests * PubNub SDK v6.5.0 release. Co-authored-by: Client Engineering Bot <60980775+Client Engineering [email protected]>
1 parent e10426f commit 1636a7b

File tree

8 files changed

+166
-7
lines changed

8 files changed

+166
-7
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: python
2-
version: 6.4.1
2+
version: 6.5.0
33
schema: 1
44
scm: github.com/pubnub/python
55
sdks:
@@ -18,7 +18,7 @@ sdks:
1818
distributions:
1919
- distribution-type: library
2020
distribution-repository: package
21-
package-name: pubnub-6.4.1
21+
package-name: pubnub-6.5.0
2222
location: https://pypi.org/project/pubnub/
2323
supported-platforms:
2424
supported-operating-systems:
@@ -97,8 +97,8 @@ sdks:
9797
-
9898
distribution-type: library
9999
distribution-repository: git release
100-
package-name: pubnub-6.4.1
101-
location: https://github.com/pubnub/python/releases/download/v6.4.1/pubnub-6.4.1.tar.gz
100+
package-name: pubnub-6.5.0
101+
location: https://github.com/pubnub/python/releases/download/v6.5.0/pubnub-6.5.0.tar.gz
102102
supported-platforms:
103103
supported-operating-systems:
104104
Linux:
@@ -169,6 +169,11 @@ sdks:
169169
license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt
170170
is-required: Required
171171
changelog:
172+
- date: 2022-07-27
173+
version: v6.5.0
174+
changes:
175+
- type: feature
176+
text: "Grant token now supports Users and Spaces."
172177
- date: 2022-07-14
173178
version: v6.4.1
174179
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v6.5.0
2+
July 27 2022
3+
4+
#### Added
5+
- Grant token now supports Users and Spaces.
6+
17
## v6.4.1
28
July 14 2022
39

pubnub/endpoints/access/grant_token.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ def authorized_uuid(self, uuid):
3232
self._authorized_uuid = uuid
3333
return self
3434

35+
def authorized_user(self, user):
36+
self._authorized_uuid = user
37+
return self
38+
39+
def spaces(self, spaces):
40+
self._channels = spaces
41+
return self
42+
43+
def users(self, users):
44+
self._uuids = users
45+
return self
46+
3547
def channels(self, channels):
3648
self._channels = channels
3749
return self
@@ -58,7 +70,7 @@ def build_data(self):
5870
utils.parse_resources(self._groups, "groups", resources, patterns)
5971
utils.parse_resources(self._uuids, "uuids", resources, patterns)
6072
utils.parse_resources(self._uuids, "users", resources, patterns)
61-
utils.parse_resources(self._uuids, "spaces", resources, patterns)
73+
utils.parse_resources(self._channels, "spaces", resources, patterns)
6274

6375
permissions['resources'] = resources
6476
permissions['patterns'] = patterns

pubnub/pubnub_core.py

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

8484
class PubNubCore:
8585
"""A base class for PubNub Python API implementations"""
86-
SDK_VERSION = "6.4.1"
86+
SDK_VERSION = "6.5.0"
8787
SDK_NAME = "PubNub-Python"
8888

8989
TIMESTAMP_DIVIDER = 1000

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='6.4.1',
5+
version='6.5.0',
66
description='PubNub Real-time push service in the cloud',
77
author='PubNub',
88
author_email='[email protected]',
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interactions:
2+
- request:
3+
body: '{"ttl": 60, "permissions": {"resources": {"channels": {"some_space_id":
4+
3}, "groups": {}, "uuids": {}, "users": {}, "spaces": {"some_space_id": 3}},
5+
"patterns": {"channels": {"some_*": 3}, "groups": {}, "uuids": {}, "users":
6+
{}, "spaces": {"some_*": 3}}, "meta": {}, "uuid": "some_user_id"}}'
7+
headers:
8+
Accept:
9+
- '*/*'
10+
Accept-Encoding:
11+
- gzip, deflate
12+
Connection:
13+
- keep-alive
14+
Content-Length:
15+
- '291'
16+
Content-type:
17+
- application/json
18+
User-Agent:
19+
- PubNub-Python/6.4.1
20+
method: POST
21+
uri: https://ps.pndsn.com/v3/pam/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f/grant
22+
response:
23+
body:
24+
string: !!binary |
25+
H4sIAAAAAAAA/1WQzW6DMBCEX6XyOUj8VChwQwGcpq1pjYqBS2UMgQQDaWySQpR3r9Oqh5xWMzuz
26+
K30XUFJJgXsBXSUErSvggnhkTAmwAHJoq145X0Foem2ow+5lKzvkl2ssoP/tsy6ZDx94T2E4DsSY
27+
C9PgqYXOGUE8NXnr6ahn/ap+v3l2KJnpyDxxZgbDvZqH3FO3UjQNATZKwtshULk05hiiISN2k/fo
28+
VJBk+1wjP7c2Z7VX3ejOv+9jmae4+dfF+i+nMpxx9U/1KSmzJ2+KlqRZ6sxsZ2gHO+qgjRbE2rQi
29+
kkf6G88ePy2NYhgV4LoAojqeduzGxvtF8/BKe8XqqBAJSeUogGvq+vUH2oM+x00BAAA=
30+
headers:
31+
Connection:
32+
- keep-alive
33+
Content-Type:
34+
- text/javascript; charset=UTF-8
35+
Date:
36+
- Tue, 26 Jul 2022 09:39:47 GMT
37+
Transfer-Encoding:
38+
- chunked
39+
cache-control:
40+
- no-cache, no-store, must-revalidate
41+
content-encoding:
42+
- gzip
43+
status:
44+
code: 200
45+
message: OK
46+
version: 1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interactions:
2+
- request:
3+
body: '{"ttl": 60, "permissions": {"resources": {"channels": {"some_channel_id":
4+
3}, "groups": {}, "uuids": {}, "users": {}, "spaces": {"some_channel_id": 3}},
5+
"patterns": {"channels": {"some_*": 3}, "groups": {}, "uuids": {}, "users":
6+
{}, "spaces": {"some_*": 3}}, "meta": {}, "uuid": "some_uuid"}}'
7+
headers:
8+
Accept:
9+
- '*/*'
10+
Accept-Encoding:
11+
- gzip, deflate
12+
Connection:
13+
- keep-alive
14+
Content-Length:
15+
- '292'
16+
Content-type:
17+
- application/json
18+
User-Agent:
19+
- PubNub-Python/6.4.1
20+
method: POST
21+
uri: https://ps.pndsn.com/v3/pam/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f/grant
22+
response:
23+
body:
24+
string: !!binary |
25+
H4sIAAAAAAAA/3WQT2+CMADFv8rSs4dS1GwkHmSFurGRwDKqXJZa/gQEKrSgYvzuw7lk08Tje/m9
26+
d/gdQcQUA8YRlLGULI2BAT5azocARkCJTVwNTW3ZaL6xISnfElW6OFr4kuA95mXQbz/9nBG7FfSp
27+
XyOtWCJXrOikDek+YdTDHooO3DEx1838LqMHPa9NK1oG2/DMEhv+/YaXzUHcfP3rr/fWmgZwxX4z
28+
KS6cHmiM+pijoqLPuOF5NyV44nTOzsvqafmyyPjj+FX7onnq5K7ujlOhhbBLdrMZOI2AjJsu42c/
29+
8x89D++sGnw1gyapmGolMBCEp28eF9ZaUQEAAA==
30+
headers:
31+
Connection:
32+
- keep-alive
33+
Content-Type:
34+
- text/javascript; charset=UTF-8
35+
Date:
36+
- Tue, 26 Jul 2022 09:39:47 GMT
37+
Transfer-Encoding:
38+
- chunked
39+
cache-control:
40+
- no-cache, no-store, must-revalidate
41+
content-encoding:
42+
- gzip
43+
status:
44+
code: 200
45+
message: OK
46+
version: 1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
from pubnub.pubnub import PubNub
3+
from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult
4+
from pubnub.models.consumer.v3.channel import Channel
5+
from pubnub.models.consumer.v3.space import Space
6+
from tests.helper import pnconf_pam_copy
7+
from tests.integrational.vcr_helper import pn_vcr
8+
9+
pubnub = PubNub(pnconf_pam_copy())
10+
pubnub.config.uuid = "test_grant"
11+
12+
13+
@pn_vcr.use_cassette(
14+
'tests/integrational/fixtures/native_sync/pam/grant_token_with_uuid_and_channels.yaml',
15+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature']
16+
)
17+
def test_grant_auth_key_with_uuid_and_channels():
18+
envelope = pubnub.grant_token()\
19+
.ttl(60)\
20+
.authorized_uuid('some_uuid')\
21+
.channels([
22+
Channel().id('some_channel_id').read().write(),
23+
Channel().pattern('some_*').read().write()
24+
])\
25+
.sync()
26+
assert isinstance(envelope.result, PNGrantTokenResult)
27+
assert envelope.result.token
28+
29+
30+
@pn_vcr.use_cassette(
31+
'tests/integrational/fixtures/native_sync/pam/grant_token_user_space.yaml',
32+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature']
33+
)
34+
def test_grant_auth_key_with_user_id_and_spaces():
35+
envelope = pubnub.grant_token()\
36+
.ttl(60)\
37+
.authorized_user('some_user_id')\
38+
.spaces([
39+
Space().id('some_space_id').read().write(),
40+
Space().pattern('some_*').read().write()
41+
])\
42+
.sync()
43+
assert isinstance(envelope.result, PNGrantTokenResult)
44+
assert envelope.result.token

0 commit comments

Comments
 (0)