Skip to content

Commit cc6a319

Browse files
kowshik-plivokowshiksiva5abhishekGupta-Plivo
authored
Kowshik tokencreation (#206)
* VT-4406 * VT-4406 * VT-4406 * Updated to current style * Update token.py Added checking to iss * VT-4406 * made changes in token.py * made changes in token.py * Added unit testing files * w * Added token creation * Updated version * Updated version * Update setup.py * Update version.py * Update version.py * Update setup.py * versioning change * Update CHANGELOG.md * version change * Update setup.py * Update CHANGELOG.md * Added unit tests * Added unit tests * Added unit tests * unit testing changes * Delete test.py Co-authored-by: kowshiksiva5 <kowshik.siva@students.iiit.ac.in> Co-authored-by: abhishekgupta <abhishek.gupta@plivo.com> Co-authored-by: Kowshik siva sai Motepalli <59483656+kowshiksiva5@users.noreply.github.com> Co-authored-by: abhishekGupta-Plivo <84371673+abhishekGupta-Plivo@users.noreply.github.com>
1 parent ef76f68 commit cc6a319

File tree

8 files changed

+63
-3
lines changed

8 files changed

+63
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [4.25.1](https://github.com/plivo/plivo-python/tree/v4.25.1) (2022-07-29)
4+
**Feature - Token Creation**
5+
- `JWT Token Creation API` added API to create a new JWT token.
6+
37
## [4.24.1](https://github.com/plivo/plivo-python/tree/v4.24.1) (2022-05-16)
48
**Bug Fix - Asynchronous Flow Added**
59
- `callback_url` and `callback_method` added in API's [Asynchronous requests](https://www.plivo.com/docs/voice/api/request#asynchronous-request)

plivo/resources/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .accounts import Accounts, Subaccounts
33
from .applications import Applications
44
from .calls import Calls
5+
from .token import Token
56
from .conferences import Conferences
67
from .endpoints import Endpoints
78
from .messages import Messages

plivo/resources/token.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import string
2+
3+
from plivo.base import (PlivoResourceInterface)
4+
from plivo.utils.validators import *
5+
6+
7+
class Token(PlivoResourceInterface):
8+
@validate_args(
9+
iss=[required(of_type(six.text_type))],
10+
sub=[optional(of_type(six.text_type))],
11+
nbf=[optional(of_type(six.text_type))],
12+
exp=[optional(of_type(six.text_type))],
13+
incoming_allow=[optional(of_type(bool, string))],
14+
outgoing_allow=[optional(of_type(bool, string))],
15+
app=[optional(of_type(six.text_type))]
16+
)
17+
def create(self, iss, sub=None, nbf=None, exp=None, incoming_allow=None, outgoing_allow=None, app=None):
18+
if incoming_allow is True and sub is None:
19+
raise ValueError('sub is required when incoming_allow is true')
20+
else:
21+
params = {'iss': iss}
22+
23+
if sub:
24+
params['sub'] = sub
25+
if nbf:
26+
params['nbf'] = nbf
27+
if exp:
28+
params['exp'] = exp
29+
if incoming_allow or outgoing_allow:
30+
params['per'] = {}
31+
params['per']['voice'] = {}
32+
if incoming_allow:
33+
params['per']['voice']['incoming_allow'] = incoming_allow
34+
if outgoing_allow:
35+
params['per']['voice']['outgoing_allow'] = outgoing_allow
36+
if app:
37+
params['app'] = app
38+
39+
return self.client.request('POST', ('JWT', 'Token',), params, is_voice_request=True)

plivo/rest/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from plivo.exceptions import (AuthenticationError, InvalidRequestError,
1212
PlivoRestError, PlivoServerError,
1313
ResourceNotFoundError, ValidationError)
14-
from plivo.resources import (Accounts, Addresses, Applications, Calls,
14+
from plivo.resources import (Accounts, Addresses, Applications, Calls,Token,
1515
Conferences, Endpoints, Identities,
1616
Messages, Powerpacks, Media, Lookup, Brand,Campaign,
1717
Numbers, Pricings, Recordings, Subaccounts, CallFeedback, MultiPartyCalls)
@@ -90,6 +90,7 @@ def __init__(self, auth_id=None, auth_token=None, proxies=None, timeout=5):
9090
self.subaccounts = Subaccounts(self)
9191
self.applications = Applications(self)
9292
self.calls = Calls(self)
93+
self.token = Token(self)
9394
self.live_calls = LiveCalls(self)
9495
self.queued_calls = QueuedCalls(self)
9596
self.conferences = Conferences(self)

plivo/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = '4.24.1'
2+
__version__ = '4.25.1'
33

setup.py

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

1111
setup(
1212
name='plivo',
13-
version='4.24.1',
13+
version='4.25.1',
1414
description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML',
1515
long_description=long_description,
1616
url='https://github.com/plivo/plivo-python',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"api_id": "5cbad7b4-19f4-11ed-8b03-0242ac110005",
2+
"token": "eyJhbGciOiJIUzI1NiIsImN0eSI6InBsaXZvO3Y9MSIsInR5cCI6IkpXVCJ9.eyJhcHAiOiIiLCJleHAiOjE2NjAzNjM2ODMsImlzcyI6Ik1BTURWTFpKWTJaR1k1TVdVMVpKIiwibmJmIjoxNjYwMjc3MjgzLCJwZXIiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOmZhbHNlLCJvdXRnb2luZ19hbGxvdyI6dHJ1ZX19LCJzdWIiOiIifQ.LAwFEuotTmbZeGWBhfNT4X2KbRapYF23BrkwVfmr5A4"
3+
}

tests/resources/test_token.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
from tests import PlivoResourceTestCase
3+
from tests.decorators import with_response
4+
5+
6+
class TokenTest(PlivoResourceTestCase):
7+
@with_response(200)
8+
def test_create(self):
9+
self.client.token.create("MAXXXXXXXXXXXXXXXXXX")
10+
self.assertEqual(self.client.current_request.method, 'POST')
11+
self.assertUrlEqual(
12+
self.get_voice_url('JWT/Token'), self.client.current_request.url)

0 commit comments

Comments
 (0)