o
    ä›eî  ã                   @   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 )&ÚTaskRouterCapabilityTokenÚv1zhttps://taskrouter.twilio.comz-https://event-bridge.twilio.com/v1/wschannelsÚHS256c              
      sø   t t| ƒj||| j| dtj¡| dd¡| dd¡d |  |||¡ || _|| _	|| _
|| _g | _| dd¡r<|  ¡  | d	d¡rF|  ¡  | d
d¡rP|  ¡  | dd¡rZ|  ¡  | dd¡rd|  ¡  | dd¡rn|  ¡  | dd¡rz|  ¡  dS 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)Ú
secret_keyÚ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   ÚGENERATEÚ_validate_inputsÚaccount_sidÚ
auth_tokenÚworkspace_sidÚ
channel_idÚpoliciesr   r   r   r   r   r   r   )Úselfr   r   r   r   Úkwargs©Ú	__class__© úQ/var/www/html/venv/lib/python3.10/site-packages/twilio/jwt/taskrouter/__init__.pyr   
   s:   


ú	ÿ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   ó   t dƒ‚)Nz,Subclass must set its specific resource_url.©ÚNotImplementedErrorr'   r"   r"   r#   Úresource_urlA   ó   z&TaskRouterCapabilityToken.resource_urlc                 C   r)   )Nz5Subclass must set its specific channel_id sid prefix.r*   r'   r"   r"   r#   Úchannel_prefixE   r-   z(TaskRouterCapabilityToken.channel_prefixc                 C   ó   |   | jdd¡ d S )NÚGETT©Ú_make_policyr,   r'   r"   r"   r#   r   I   ó   z*TaskRouterCapabilityToken.allow_fetch_selfc                 C   r/   )NÚPOSTTr1   r'   r"   r"   r#   r   L   r3   z+TaskRouterCapabilityToken.allow_update_selfc                 C   r/   )NÚDELETETr1   r'   r"   r"   r#   r   O   r3   z+TaskRouterCapabilityToken.allow_delete_selfc                 C   ó   |   | jd dd¡ d S )Nú/**r0   Tr1   r'   r"   r"   r#   r   R   ó   z2TaskRouterCapabilityToken.allow_fetch_subresourcesc                 C   r6   )Nr7   r4   Tr1   r'   r"   r"   r#   r   U   r8   z3TaskRouterCapabilityToken.allow_update_subresourcesc                 C   r6   )Nr7   r5   Tr1   r'   r"   r"   r#   r   X   r8   z3TaskRouterCapabilityToken.allow_delete_subresourcesNc                 C   s<   |p| j }d | j| j|¡}|  |dd¡ |  |dd¡ d S )Nz{}/{}/{}r0   Tr4   )r   r$   ÚEVENTS_BASE_URLr   r2   )r   r   Úweb_socket_urlr"   r"   r#   r   [   s   
z+TaskRouterCapabilityToken.allow_web_socketsc                 C   sR   | j | j| j| j| j| jdœ}| j d¡r| j|d< |S | j d¡r'| j|d< |S )N)r   r   ÚchannelÚversionÚfriendly_namer   ÚWKÚ
worker_sidÚWQÚtaskqueue_sid)r   r   r   r&   r   Ú
startswith)r   Úpayloadr"   r"   r#   Ú_generate_payloada   s   ú	
ý
z+TaskRouterCapabilityToken._generate_payloadc                 C   s(   | j  || ¡ ||pi |pi dœ¡ d S )N)ÚurlÚmethodÚallowÚquery_filterÚpost_filter)r   ÚappendÚupper)r   rE   rF   ÚallowedrH   rI   r"   r"   r#   r2   r   s   ûz&TaskRouterCapabilityToken._make_policyc                 C   sZ   |r|  d¡std |¡ƒ‚|r|  d¡std |¡ƒ‚|r$|  | j¡s+td |¡ƒ‚d S )NÚACzInvalid account sid provided {}ÚWSz!Invalid workspace sid provided {}zInvalid channel id provided {})rB   Ú
ValueErrorr$   r.   )r   r   r   r   r"   r"   r#   r   {   s   ÿz*TaskRouterCapabilityToken._validate_inputsc                 C   s   d  |  ¡ ¡S )Nz<TaskRouterCapabilityToken {}>)r$   Úto_jwtr'   r"   r"   r#   Ú__str__…   s   z!TaskRouterCapabilityToken.__str__)N)NN)Ú__name__Ú
__module__Ú__qualname__r&   r%   r9   r   r   Úpropertyr(   r,   r.   r   r   r   r   r   r   r   rD   r2   r   rQ   Ú__classcell__r"   r"   r    r#   r      s.    3




	
r   N)Ú
twilio.jwtr   r   r"   r"   r"   r#   Ú<module>   s    