From 74802c85b66df0b5cb7f82b87c46b7f44bdc0fe3 Mon Sep 17 00:00:00 2001 From: Jennifer Mah Date: Wed, 25 Jan 2023 16:10:42 -0800 Subject: [PATCH] chore: remove deprecated grants --- tests/unit/jwt/test_access_token.py | 23 +++--------- twilio/jwt/access_token/grants.py | 55 ++++------------------------- 2 files changed, 10 insertions(+), 68 deletions(-) diff --git a/tests/unit/jwt/test_access_token.py b/tests/unit/jwt/test_access_token.py index d5d9d04ead..2d010862e7 100644 --- a/tests/unit/jwt/test_access_token.py +++ b/tests/unit/jwt/test_access_token.py @@ -4,7 +4,6 @@ from twilio.jwt.access_token import AccessToken from twilio.jwt.access_token.grants import ( - IpMessagingGrant, SyncGrant, VoiceGrant, VideoGrant, @@ -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')) @@ -167,7 +152,7 @@ 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 @@ -175,7 +160,7 @@ def test_grants(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_programmable_voice_grant(self): grant = VoiceGrant( @@ -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) @@ -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'] diff --git a/twilio/jwt/access_token/grants.py b/twilio/jwt/access_token/grants.py index e59b2ac768..911f8e1b44 100644 --- a/twilio/jwt/access_token/grants.py +++ b/twilio/jwt/access_token/grants.py @@ -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) @@ -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 @@ -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, @@ -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 @@ -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