a
    ù!f^  ã                   @   s    d dl mZ G dd„ deƒZdS )é    )ÚJwtc                       s¬   e Zd ZdZdZdZdZ‡ fdd„Zedd„ ƒZ	ed	d
„ ƒZ
edd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd$dd„Zdd„ Zd%dd„Zd d!„ Zd"d#„ Z‡  ZS )&ÚTaskRouterCapabilityTokenZv1zhttps://taskrouter.twilio.comz-https://event-bridge.twilio.com/v1/wschannelsZHS256c              
      sô   t t| ƒj||| j| dtj¡| dd¡| dd¡d |  |||¡ || _|| _	|| _
|| _g | _| dd¡rx|  ¡  | d	d¡rŒ|  ¡  | d
d¡r |  ¡  | dd¡r´|  ¡  | dd¡rÈ|  ¡  | dd¡rÜ|  ¡  | dd¡rð|  ¡  dS )aä  
        :param str account_sid: Twilio account sid
        :param str auth_token: Twilio auth token used to sign the JWT
        :param str workspace_sid: TaskRouter workspace sid
        :param str channel_id: TaskRouter channel sid
        :param kwargs:
            :param bool allow_web_sockets: shortcut to calling allow_web_sockets, defaults to True
            :param bool allow_fetch_self: shortcut to calling allow_fetch_self, defaults to True
            :param bool allow_update_self: shortcut to calling allow_update_self, defaults to False
            :param bool allow_delete_self: shortcut to calling allow_delete_self, defaults to False
            :param bool allow_fetch_subresources: shortcut to calling allow_fetch_subresources,
                                                  defaults to False
            :param bool allow_update_subresources: shortcut to calling allow_update_subresources,
                                                   defaults to False
            :param bool allow_delete_subresources: shortcut to calling allow_delete_subresources,
                                                   defaults to False
        :returns a new TaskRouterCapabilityToken with capabilities set depending on kwargs.
        ÚnbfÚttli  Úvalid_untilN)Z
secret_keyZissuerÚ	algorithmr   r   r   Úallow_web_socketsTÚallow_fetch_selfÚallow_update_selfFÚallow_delete_selfÚallow_fetch_subresourcesÚallow_delete_subresourcesÚallow_update_subresources)Úsuperr   Ú__init__Ú	ALGORITHMÚgetr   ZGENERATEÚ_validate_inputsÚaccount_sidÚ
auth_tokenÚworkspace_sidÚ
channel_idÚpoliciesr   r	   r
   r   r   r   r   )Úselfr   r   r   r   Úkwargs©Ú	__class__© ú_/var/www/html/python-backend/venv/lib/python3.9/site-packages/twilio/jwt/taskrouter/__init__.pyr   
   s8    


ú	z"TaskRouterCapabilityToken.__init__c                 C   s   d  | j| j| j¡S )Nz{}/{}/Workspaces/{})ÚformatÚDOMAINÚVERSIONr   ©r   r   r   r   Úworkspace_url=   s    ÿz'TaskRouterCapabilityToken.workspace_urlc                 C   s   t dƒ‚d S )Nz,Subclass must set its specific resource_url.©ÚNotImplementedErrorr"   r   r   r   Úresource_urlC   s    z&TaskRouterCapabilityToken.resource_urlc                 C   s   t dƒ‚d S )Nz5Subclass must set its specific channel_id sid prefix.r$   r"   r   r   r   Úchannel_prefixG   s    ÿz(TaskRouterCapabilityToken.channel_prefixc                 C   s   |   | jdd¡ d S )NÚGETT©Ú_make_policyr&   r"   r   r   r   r	   M   s    z*TaskRouterCapabilityToken.allow_fetch_selfc                 C   s   |   | jdd¡ d S )NÚPOSTTr)   r"   r   r   r   r
   P   s    z+TaskRouterCapabilityToken.allow_update_selfc                 C   s   |   | jdd¡ d S )NÚDELETETr)   r"   r   r   r   r   S   s    z+TaskRouterCapabilityToken.allow_delete_selfc                 C   s   |   | jd dd¡ d S )Nú/**r(   Tr)   r"   r   r   r   r   V   s    z2TaskRouterCapabilityToken.allow_fetch_subresourcesc                 C   s   |   | jd dd¡ d S )Nr-   r+   Tr)   r"   r   r   r   r   Y   s    z3TaskRouterCapabilityToken.allow_update_subresourcesc                 C   s   |   | jd dd¡ d S )Nr-   r,   Tr)   r"   r   r   r   r   \   s    z3TaskRouterCapabilityToken.allow_delete_subresourcesNc                 C   s<   |p| j }d | j| j|¡}|  |dd¡ |  |dd¡ d S )Nz{}/{}/{}r(   Tr+   )r   r   ÚEVENTS_BASE_URLr   r*   )r   r   Zweb_socket_urlr   r   r   r   _   s    

ÿz+TaskRouterCapabilityToken.allow_web_socketsc                 C   sP   | j | j| j| j| j| jdœ}| j d¡r6| j|d< n| j d¡rL| j|d< |S )N)r   r   ZchannelÚversionZfriendly_namer   ZWKZ
worker_sidZWQZtaskqueue_sid)r   r   r   r!   r   Ú
startswith)r   Úpayloadr   r   r   Ú_generate_payloadg   s    ú	
z+TaskRouterCapabilityToken._generate_payloadc                 C   s(   | j  || ¡ ||pi |pi dœ¡ d S )N)ÚurlÚmethodZallowÚquery_filterÚpost_filter)r   ÚappendÚupper)r   r3   r4   Úallowedr5   r6   r   r   r   r*   x   s    ûÿz&TaskRouterCapabilityToken._make_policyc                 C   sZ   |r|  d¡std |¡ƒ‚|r*|  d¡s8td |¡ƒ‚|rH|  | j¡sVtd |¡ƒ‚d S )NZACzInvalid account sid provided {}ZWSz!Invalid workspace sid provided {}zInvalid channel id provided {})r0   Ú
ValueErrorr   r'   )r   r   r   r   r   r   r   r   ƒ   s    z*TaskRouterCapabilityToken._validate_inputsc                 C   s   d  |  ¡ ¡S )Nz<TaskRouterCapabilityToken {}>)r   Zto_jwtr"   r   r   r   Ú__str__   s    z!TaskRouterCapabilityToken.__str__)N)NN)Ú__name__Ú
__module__Ú__qualname__r!   r    r.   r   r   Úpropertyr#   r&   r'   r	   r
   r   r   r   r   r   r2   r*   r   r;   Ú__classcell__r   r   r   r   r      s,   3





r   N)Z
twilio.jwtr   r   r   r   r   r   Ú<module>   s   