Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove deprecated grants #644

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions tests/unit/jwt/test_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import (
IpMessagingGrant,
SyncGrant,
VoiceGrant,
VideoGrant,
Expand Down Expand Up @@ -120,20 +119,6 @@ def test_video_grant(self):
'room': 'RM123'
} == decoded_token.payload['grants']['video']

def test_ip_messaging_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(IpMessagingGrant(service_sid='IS123', push_credential_sid='CR123'))

token = scat.to_jwt()
assert token is not None
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert 1 == len(decoded_token.payload['grants'])
assert {
'service_sid': 'IS123',
'push_credential_sid': 'CR123'
} == decoded_token.payload['grants']['ip_messaging']

def test_chat_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(ChatGrant(service_sid='IS123', push_credential_sid='CR123'))
Expand Down Expand Up @@ -167,15 +152,15 @@ def test_sync_grant(self):
def test_grants(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(VideoGrant())
scat.add_grant(IpMessagingGrant())
scat.add_grant(ChatGrant())

token = scat.to_jwt()
assert token is not None
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert 2 == len(decoded_token.payload['grants'])
assert {} == decoded_token.payload['grants']['video']
assert {} == decoded_token.payload['grants']['ip_messaging']
assert {} == decoded_token.payload['grants']['chat']

def test_programmable_voice_grant(self):
grant = VoiceGrant(
Expand Down Expand Up @@ -261,7 +246,7 @@ def test_playback_grant(self):
def test_pass_grants_in_constructor(self):
grants = [
VideoGrant(),
IpMessagingGrant()
ChatGrant()
]
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', grants=grants)

Expand All @@ -272,7 +257,7 @@ def test_pass_grants_in_constructor(self):
self._validate_claims(decoded_token.payload)
assert 2 == len(decoded_token.payload['grants'])
assert {} == decoded_token.payload['grants']['video']
assert {} == decoded_token.payload['grants']['ip_messaging']
assert {} == decoded_token.payload['grants']['chat']

def test_constructor_validates_grants(self):
grants = [VideoGrant, 'GrantMeAccessToEverything']
Expand Down
55 changes: 6 additions & 49 deletions twilio/jwt/access_token/grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def deprecated(func):
@functools.wraps(func)
def new_func(*args, **kwargs):
warnings.simplefilter('always', DeprecationWarning)
warnings.warn("Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, stacklevel=2)
warnings.warn("Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning,
stacklevel=2)
warnings.simplefilter('default', DeprecationWarning)
return func(*args, **kwargs)

Expand Down Expand Up @@ -46,37 +47,9 @@ def to_payload(self):
return grant


class IpMessagingGrant(AccessTokenGrant):
"""Grant to access Twilio IP Messaging"""

@deprecated
def __init__(self, service_sid=None, endpoint_id=None,
deployment_role_sid=None, push_credential_sid=None):
self.service_sid = service_sid
self.endpoint_id = endpoint_id
self.deployment_role_sid = deployment_role_sid
self.push_credential_sid = push_credential_sid

@property
def key(self):
return "ip_messaging"

def to_payload(self):
grant = {}
if self.service_sid:
grant['service_sid'] = self.service_sid
if self.endpoint_id:
grant['endpoint_id'] = self.endpoint_id
if self.deployment_role_sid:
grant['deployment_role_sid'] = self.deployment_role_sid
if self.push_credential_sid:
grant['push_credential_sid'] = self.push_credential_sid

return grant


class SyncGrant(AccessTokenGrant):
"""Grant to access Twilio Sync"""

def __init__(self, service_sid=None, endpoint_id=None):
self.service_sid = service_sid
self.endpoint_id = endpoint_id
Expand All @@ -97,6 +70,7 @@ def to_payload(self):

class VoiceGrant(AccessTokenGrant):
"""Grant to access Twilio Programmable Voice"""

def __init__(self,
incoming_allow=None,
outgoing_application_sid=None,
Expand Down Expand Up @@ -139,27 +113,9 @@ def to_payload(self):

return grant


class ConversationsGrant(AccessTokenGrant):
"""Grant to access Twilio Conversations"""
@deprecated
def __init__(self, configuration_profile_sid=None):
self.configuration_profile_sid = configuration_profile_sid

@property
def key(self):
return "rtc"

def to_payload(self):
grant = {}
if self.configuration_profile_sid:
grant['configuration_profile_sid'] = self.configuration_profile_sid

return grant


class VideoGrant(AccessTokenGrant):
"""Grant to access Twilio Video"""

def __init__(self, room=None):
self.room = room

Expand All @@ -177,6 +133,7 @@ def to_payload(self):

class TaskRouterGrant(AccessTokenGrant):
"""Grant to access Twilio TaskRouter"""

def __init__(self, workspace_sid=None, worker_sid=None, role=None):
self.workspace_sid = workspace_sid
self.worker_sid = worker_sid
Expand Down