Skip to content

Commit

Permalink
Kowshik tokencreation (#206)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: abhishekgupta <[email protected]>
Co-authored-by: Kowshik siva sai Motepalli <[email protected]>
Co-authored-by: abhishekGupta-Plivo <[email protected]>
  • Loading branch information
5 people authored Aug 12, 2022
1 parent ef76f68 commit cc6a319
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [4.25.1](https://github.com/plivo/plivo-python/tree/v4.25.1) (2022-07-29)
**Feature - Token Creation**
- `JWT Token Creation API` added API to create a new JWT token.

## [4.24.1](https://github.com/plivo/plivo-python/tree/v4.24.1) (2022-05-16)
**Bug Fix - Asynchronous Flow Added**
- `callback_url` and `callback_method` added in API's [Asynchronous requests](https://www.plivo.com/docs/voice/api/request#asynchronous-request)
Expand Down
1 change: 1 addition & 0 deletions plivo/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .accounts import Accounts, Subaccounts
from .applications import Applications
from .calls import Calls
from .token import Token
from .conferences import Conferences
from .endpoints import Endpoints
from .messages import Messages
Expand Down
39 changes: 39 additions & 0 deletions plivo/resources/token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import string

from plivo.base import (PlivoResourceInterface)
from plivo.utils.validators import *


class Token(PlivoResourceInterface):
@validate_args(
iss=[required(of_type(six.text_type))],
sub=[optional(of_type(six.text_type))],
nbf=[optional(of_type(six.text_type))],
exp=[optional(of_type(six.text_type))],
incoming_allow=[optional(of_type(bool, string))],
outgoing_allow=[optional(of_type(bool, string))],
app=[optional(of_type(six.text_type))]
)
def create(self, iss, sub=None, nbf=None, exp=None, incoming_allow=None, outgoing_allow=None, app=None):
if incoming_allow is True and sub is None:
raise ValueError('sub is required when incoming_allow is true')
else:
params = {'iss': iss}

if sub:
params['sub'] = sub
if nbf:
params['nbf'] = nbf
if exp:
params['exp'] = exp
if incoming_allow or outgoing_allow:
params['per'] = {}
params['per']['voice'] = {}
if incoming_allow:
params['per']['voice']['incoming_allow'] = incoming_allow
if outgoing_allow:
params['per']['voice']['outgoing_allow'] = outgoing_allow
if app:
params['app'] = app

return self.client.request('POST', ('JWT', 'Token',), params, is_voice_request=True)
3 changes: 2 additions & 1 deletion plivo/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from plivo.exceptions import (AuthenticationError, InvalidRequestError,
PlivoRestError, PlivoServerError,
ResourceNotFoundError, ValidationError)
from plivo.resources import (Accounts, Addresses, Applications, Calls,
from plivo.resources import (Accounts, Addresses, Applications, Calls,Token,
Conferences, Endpoints, Identities,
Messages, Powerpacks, Media, Lookup, Brand,Campaign,
Numbers, Pricings, Recordings, Subaccounts, CallFeedback, MultiPartyCalls)
Expand Down Expand Up @@ -90,6 +90,7 @@ def __init__(self, auth_id=None, auth_token=None, proxies=None, timeout=5):
self.subaccounts = Subaccounts(self)
self.applications = Applications(self)
self.calls = Calls(self)
self.token = Token(self)
self.live_calls = LiveCalls(self)
self.queued_calls = QueuedCalls(self)
self.conferences = Conferences(self)
Expand Down
2 changes: 1 addition & 1 deletion plivo/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
__version__ = '4.24.1'
__version__ = '4.25.1'

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='plivo',
version='4.24.1',
version='4.25.1',
description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML',
long_description=long_description,
url='https://github.com/plivo/plivo-python',
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/fixtures/tokenCreateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"api_id": "5cbad7b4-19f4-11ed-8b03-0242ac110005",
"token": "eyJhbGciOiJIUzI1NiIsImN0eSI6InBsaXZvO3Y9MSIsInR5cCI6IkpXVCJ9.eyJhcHAiOiIiLCJleHAiOjE2NjAzNjM2ODMsImlzcyI6Ik1BTURWTFpKWTJaR1k1TVdVMVpKIiwibmJmIjoxNjYwMjc3MjgzLCJwZXIiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOmZhbHNlLCJvdXRnb2luZ19hbGxvdyI6dHJ1ZX19LCJzdWIiOiIifQ.LAwFEuotTmbZeGWBhfNT4X2KbRapYF23BrkwVfmr5A4"
}
12 changes: 12 additions & 0 deletions tests/resources/test_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
from tests import PlivoResourceTestCase
from tests.decorators import with_response


class TokenTest(PlivoResourceTestCase):
@with_response(200)
def test_create(self):
self.client.token.create("MAXXXXXXXXXXXXXXXXXX")
self.assertEqual(self.client.current_request.method, 'POST')
self.assertUrlEqual(
self.get_voice_url('JWT/Token'), self.client.current_request.url)

0 comments on commit cc6a319

Please sign in to comment.