1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
from twilio.jwt.access_token import AccessTokenGrant
import warnings
import functools
def deprecated(func):
'''This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.'''
@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.simplefilter('default', DeprecationWarning)
return func(*args, **kwargs)
return new_func
class ChatGrant(AccessTokenGrant):
"""Grant to access Twilio Chat"""
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 "chat"
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 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
@property
def key(self):
return "data_sync"
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
return grant
class VoiceGrant(AccessTokenGrant):
"""Grant to access Twilio Programmable Voice"""
def __init__(self,
incoming_allow=None,
outgoing_application_sid=None,
outgoing_application_params=None,
push_credential_sid=None,
endpoint_id=None):
self.incoming_allow = incoming_allow
""" :type : bool """
self.outgoing_application_sid = outgoing_application_sid
""" :type : str """
self.outgoing_application_params = outgoing_application_params
""" :type : dict """
self.push_credential_sid = push_credential_sid
""" :type : str """
self.endpoint_id = endpoint_id
""" :type : str """
@property
def key(self):
return "voice"
def to_payload(self):
grant = {}
if self.incoming_allow is True:
grant['incoming'] = {}
grant['incoming']['allow'] = True
if self.outgoing_application_sid:
grant['outgoing'] = {}
grant['outgoing']['application_sid'] = self.outgoing_application_sid
if self.outgoing_application_params:
grant['outgoing']['params'] = self.outgoing_application_params
if self.push_credential_sid:
grant['push_credential_sid'] = self.push_credential_sid
if self.endpoint_id:
grant['endpoint_id'] = self.endpoint_id
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
@property
def key(self):
return "video"
def to_payload(self):
grant = {}
if self.room:
grant['room'] = self.room
return grant
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
self.role = role
@property
def key(self):
return "task_router"
def to_payload(self):
grant = {}
if self.workspace_sid:
grant['workspace_sid'] = self.workspace_sid
if self.worker_sid:
grant['worker_sid'] = self.worker_sid
if self.role:
grant['role'] = self.role
return grant
|