Ë
    îÏjò.  ã                   ó  — d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZ d dlmZmZ d dlmZ d dlmZ  ej&                  e«      Z G d„ d	«      Z G d
„ d«      Z G d„ d«      Z G d„ d«      Zd„ Zde j6                  fd„Zy)é    N)ÚdatetimeÚtimezone)Úsleep)ÚAnyÚ	AwaitableÚCallableÚUnion)ÚRequestTokenErrÚTokenRenewalErr)ÚIdentityProviderInterface)ÚTokenResponsec                   óö   — e Zd ZdZd„ Zedeeegdf   e	f   fd„«       Z
e
j                  deeegdf   e	f   ddfd„«       Z
edeeegdf   e	f   fd„«       Zej                  deeegdf   e	f   ddfd	„«       Zy)
ÚCredentialsListenerzz
    Listeners that will be notified on events related to credentials.
    Accepts callbacks and awaitable callbacks.
    c                 ó    — d | _         d | _        y ©N)Ú_on_nextÚ	_on_error©Úselfs    úU/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/redis/auth/token_manager.pyÚ__init__zCredentialsListener.__init__   s   € ØˆŒØˆ�ó    ÚreturnNc                 ó   — | j                   S r   ©r   r   s    r   Úon_nextzCredentialsListener.on_next   s   € à�}‰}Ðr   Úcallbackc                 ó   — || _         y r   r   ©r   r   s     r   r   zCredentialsListener.on_next   s	   € à ˆ�r   c                 ó   — | j                   S r   ©r   r   s    r   Úon_errorzCredentialsListener.on_error!   s   € à�~‰~Ðr   c                 ó   — || _         y r   r!   r   s     r   r"   zCredentialsListener.on_error%   s	   € à!ˆ�r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr	   r   r   r   r   ÚsetterÚ	Exceptionr"   © r   r   r   r      så   „ ñò
ð ð˜˜x¨¨¨t¨Ñ4°iÐ?Ñ@ò ó ðð ‡^�^ð!  h°¨u°d¨{Ñ&;¸YÐ&FÑ Gð !ÈDò !ó ð!ð ð˜% ¨)¨°dÐ):Ñ ;¸YÐ FÑGò ó ðð ‡_�_ð"  x°°¸TÐ0AÑ'BÀIÐ'MÑ!Nð "ÐSWò "ó ñ"r   r   c                   ó4   — e Zd Zdedefd„Zdefd„Zdefd„Zy)ÚRetryPolicyÚmax_attemptsÚdelay_in_msc                 ó    — || _         || _        y r   )r.   r/   )r   r.   r/   s      r   r   zRetryPolicy.__init__+   s   € Ø(ˆÔØ&ˆÕr   r   c                 ó   — | j                   S )zW
        Retry attempts before exception will be thrown.

        :return: int
        )r.   r   s    r   Úget_max_attemptszRetryPolicy.get_max_attempts/   s   € ð × Ñ Ð r   c                 ó   — | j                   S )zI
        Delay between retries in seconds.

        :return: int
        )r/   r   s    r   Úget_delay_in_mszRetryPolicy.get_delay_in_ms7   s   € ð ×ÑÐr   N)r$   r%   r&   ÚintÚfloatr   r2   r4   r+   r   r   r-   r-   *   s-   „ ð' Sð '°uó 'ð! #ó !ð  ô  r   r-   c                   óT   — e Zd Zdedededefd„Zdefd„Zdefd„Zdefd	„Z	defd
„Z
y)ÚTokenManagerConfigÚexpiration_refresh_ratioÚlower_refresh_bound_millisÚ%token_request_execution_timeout_in_msÚretry_policyc                 ó<   — || _         || _        || _        || _        y r   )Ú_expiration_refresh_ratioÚ_lower_refresh_bound_millisÚ&_token_request_execution_timeout_in_msÚ_retry_policy)r   r9   r:   r;   r<   s        r   r   zTokenManagerConfig.__init__A   s*   € ð *BˆÔ&Ø+EˆÔ(à1ð 	Ô3ð *ˆÕr   r   c                 ó   — | j                   S )a&  
        Represents the ratio of a token's lifetime at which a refresh should be triggered. # noqa: E501
        For example, a value of 0.75 means the token should be refreshed
        when 75% of its lifetime has elapsed (or when 25% of its lifetime remains).

        :return: float
        )r>   r   s    r   Úget_expiration_refresh_ratioz/TokenManagerConfig.get_expiration_refresh_ratioO   s   € ð ×-Ñ-Ð-r   c                 ó   — | j                   S )a¤  
        Represents the minimum time in milliseconds before token expiration
        to trigger a refresh, in milliseconds.
        This value sets a fixed lower bound for when a token refresh should occur,
        regardless of the token's total lifetime.
        If set to 0 there will be no lower bound and the refresh will be triggered
        based on the expirationRefreshRatio only.

        :return: int
        )r?   r   s    r   Úget_lower_refresh_bound_millisz1TokenManagerConfig.get_lower_refresh_bound_millisZ   s   € ð ×/Ñ/Ð/r   c                 ó   — | j                   S )z„
        Represents the maximum time in milliseconds to wait
        for a token request to complete.

        :return: int
        )r@   r   s    r   Ú)get_token_request_execution_timeout_in_msz<TokenManagerConfig.get_token_request_execution_timeout_in_msg   s   € ð ×:Ñ:Ð:r   c                 ó   — | j                   S )z_
        Represents the retry policy for token requests.

        :return: RetryPolicy
        )rA   r   s    r   Úget_retry_policyz#TokenManagerConfig.get_retry_policyp   s   € ð ×!Ñ!Ð!r   N)r$   r%   r&   r6   r5   r-   r   rC   rE   rG   rI   r+   r   r   r8   r8   @   s]   „ ð*à"'ð*ð %(ð*ð 03ð	*ð
 "ó*ð	.¨eó 	.ð0°ó 0ð;¸3ó ;ð" +ô "r   r8   c                   ó  — e Zd Zdedefd„Zd„ Z	 ddedede	g df   fd	„Z
	 	 	 dded
ededede	g df   f
d„Zd„ Zddefd„Zddefd„Zdededefd„Zdefd„Zdedefd„Z	 ddedej*                  fd„Z	 ddedej*                  fd„Zy)ÚTokenManagerÚidentity_providerÚconfigc                 óX   — || _         || _        d | _        d | _        d | _        d| _        y )Nr   )Ú_idpÚ_configÚ_next_timerÚ	_listenerÚ_init_timerÚ_retries)r   rL   rM   s      r   r   zTokenManager.__init__z   s0   € ð &ˆŒ	ØˆŒØˆÔØˆŒØˆÔØˆ�r   c                 óN   — t         j                  d«       | j                  «        y )NzToken manager are disposed)ÚloggerÚinfoÚstopr   s    r   Ú__del__zTokenManager.__del__„   s   € Ü�‰Ð0Ô1Ø�	‰	�r   ÚlistenerÚskip_initialr   Nc                 óî  — || _         	 t        j                  «       }t        j                  «       }|j                  d| j                  ||«      | _        t        j                  d«       t        j                  |j!                  «       |«      j#                  «        | j$                  S # t        $ rD t        j                  «       }t        j                  t        |fd¬«      }|j                  «        Y ŒÖw xY w)NT)ÚtargetÚargsÚdaemonr   úToken manager started)rR   ÚasyncioÚget_running_loopÚRuntimeErrorÚnew_event_loopÚ	threadingÚThreadÚ_start_event_loop_in_threadÚstartÚEventÚ
call_laterÚ_renew_tokenrS   rV   rW   Úrun_coroutine_threadsafeÚwaitÚresultrX   )r   rZ   r[   ÚloopÚthreadÚ
init_events         r   rh   zTokenManager.startˆ   sÉ   € ð
 "ˆŒð	Ü×+Ñ+Ó-ˆDô —]‘]“_ˆ
ØŸ?™?Øˆt× Ñ  ,°
ó
ˆÔô 	�‰Ð+Ô,ô 	×(Ñ(¨¯©Ó):¸DÓA×HÑHÔJØ�y‰yÐøô# ò 	ä×)Ñ)Ó+ˆDÜ×%Ñ%Ü2¸$¸ÈôˆFð �L‰LŽNð	ús   ‰B' Â'A
C4Ã3C4Úblock_for_initialÚinitial_delay_in_msc              ƒ   óF  K  — || _         t        j                  «       }t        j                  «       }t	        || j
                  ||«      }|j                  |dz  |«      | _        t        j                  d«       |r|j                  «       ƒ d {  –—†  | j                  S 7 Œ­w)Néè  r`   )rR   ra   rb   ri   Ú_async_to_sync_wrapperÚ_renew_token_asyncrj   rS   rV   rW   rm   rX   )r   rZ   rr   rs   r[   ro   rq   Úwrappeds           r   Ústart_asynczTokenManager.start_async¤   s�   è ø€ ð "ˆŒä×'Ñ'Ó)ˆÜ—]‘]“_ˆ
ô )Ø�$×)Ñ)¨<¸ó
ˆð  Ÿ?™?Ð+>ÀÑ+EÀwÓOˆÔÜ�‰Ð+Ô,áØ—/‘/Ó#×#Ð#à�y‰yÐð $ús   ‚BB!ÂBÂB!c                 óž   — | j                   �| j                   j                  «        | j                  �| j                  j                  «        y y r   )rS   ÚcancelrQ   r   s    r   rX   zTokenManager.stop¼   sC   € Ø×ÑÐ'Ø×Ñ×#Ñ#Ô%Ø×ÑÐ'Ø×Ñ×#Ñ#Õ%ð (r   c                 ó¬  — 	 | j                   j                  |«      }d| _        t        |«      S # t        $ r›}| j                  | j                  j                  «       j                  «       k  r_| xj                  dz  c_        t        | j                  j                  «       j                  «       dz  «       | j                  |«      cY d }~S |‚d }~ww xY w©Né   ru   r   )rO   Úrequest_tokenr
   rT   rP   rI   r2   r   r4   Úacquire_tokenr   ©r   Úforce_refreshÚtokenÚes       r   r€   zTokenManager.acquire_tokenÂ   sª   € ð	Ø—I‘I×+Ñ+¨MÓ:ˆEð ˆŒÜ˜UÓ#Ð#øô ò 	Ø�}‰}˜tŸ|™|×<Ñ<Ó>×OÑOÓQÒQØ—’ Ñ"•Ü�d—l‘l×3Ñ3Ó5×EÑEÓGÈ$ÑNÔOØ×)Ñ)¨-Ó8Õ8à�ûð	ús!   ‚/ ¯	C¸BCÃCÃCÃCc              ƒ   óì  K  — 	 | j                   j                  |«      }d| _        t        |«      S # t        $ r·}| j                  | j                  j                  «       j                  «       k  r{| xj                  dz  c_        t        j                  | j                  j                  «       j                  «       dz  «      ƒ d {  –—†7   | j                  |«      ƒ d {  –—†7  cY d }~S |‚d }~ww xY w­wr}   )rO   r   r
   rT   rP   rI   r2   ra   r   r4   Úacquire_token_asyncr   r�   s       r   r†   z TokenManager.acquire_token_asyncÐ   sÆ   è ø€ ð
	Ø—I‘I×+Ñ+¨MÓ:ˆEð ˆŒÜ˜UÓ#Ð#øô ò 	Ø�}‰}˜tŸ|™|×<Ñ<Ó>×OÑOÓQÒQØ—’ Ñ"•Ü—m‘mØ—L‘L×1Ñ1Ó3×CÑCÓEÈÑLó÷ ñ ð "×5Ñ5°mÓD×DÐDÕDà�ûð	üsO   ‚C4„1 ŸC4±	C1ºBC,ÃCÃC,ÃC"Ã C,Ã$C1Ã%C4Ã*C,Ã,C1Ã1C4Úexpire_dateÚ
issue_datec                 óx   — | j                  |«      }| j                  ||«      }t        ||«      }|dk  rdS |dz  S )Nr   ru   )Ú_delay_for_lower_refreshÚ_delay_for_ratio_refreshÚmin)r   r‡   rˆ   Údelay_for_lower_refreshÚdelay_for_ratio_refreshÚdelays         r   Ú_calculate_renewal_delayz%TokenManager._calculate_renewal_delayà   sI   € Ø"&×"?Ñ"?ÀÓ"LÐØ"&×"?Ñ"?ÀÈZÓ"XÐÜÐ+Ð-DÓEˆà˜A’IˆqÐ/ 5¨4¡<Ð/r   c                 ó¦   — || j                   j                  «       z
  t        j                  t        j
                  «      j                  «       dz  z
  S ©Nru   )rP   rE   r   Únowr   ÚutcÚ	timestamp)r   r‡   s     r   rŠ   z%TokenManager._delay_for_lower_refreshç   sB   € àØ�l‰l×9Ñ9Ó;ñ<ä�|‰|œHŸL™LÓ)×3Ñ3Ó5¸Ñ<ñ>ð	
r   c                 óÀ   — ||z
  }||| j                   j                  «       z  z
  }||z
  t        j                  t        j
                  «      j                  «       dz  z
  S r’   )rP   rC   r   r“   r   r”   r•   )r   r‡   rˆ   Ú	token_ttlÚrefresh_befores        r   r‹   z%TokenManager._delay_for_ratio_refreshî   s`   € Ø *Ñ,ˆ	Ø"Ø˜Ÿ™×AÑAÓCÑCñ
ˆð
 Øñä�|‰|œHŸL™LÓ)×3Ñ3Ó5¸Ñ<ñ>ð	
r   rq   c                 ó  — 	 | j                  d¬«      }| j                  |j                  «       j                  «       |j                  «       j	                  «       «      }|j                  «       j                  «       rt        d«      ‚| j                  j                  €*t        j                  d«       	 |r|j                  «        yy|s*	 | j                  j                  |j                  «       «       |dk  r	 |r|j                  «        yyt        j                  «       }|j                  || j                   «      | _        t        j%                  d|› d�«       ||r|j                  «        S S # t        $ r}t        |«      ‚d}~ww xY w# t        $ r=}| j                  j&                  €|‚| j                  j'                  |«       Y d}~nd}~ww xY w	 |r|j                  «        yy# |r|j                  «        w w xY w)	zq
        Task to renew token from identity provider.
        Schedules renewal tasks based on token TTL.
        T©r‚   úRequested token is expiredNú@No registered callback for token renewal task. Renewal cancelledr   ú Next token renewal scheduled in ú seconds)r€   r�   Ú	get_tokenÚget_expires_at_msÚget_received_at_msÚ
is_expiredr   rR   r   rV   ÚwarningÚsetr*   ra   rb   rj   rk   rQ   rW   r"   )r   r[   rq   Ú	token_resr�   r„   ro   s          r   rk   zTokenManager._renew_tokenú   sÌ  € ð$	!Ø×*Ñ*¸Ð*Ó>ˆIØ×1Ñ1Ø×#Ñ#Ó%×7Ñ7Ó9Ø×#Ñ#Ó%×8Ñ8Ó:óˆEð
 ×"Ñ"Ó$×/Ñ/Ô1Ü%Ð&BÓCÐCà�~‰~×%Ñ%Ð-Ü—‘ØVôð ñ* Ø—‘Õ ð ñ'  ð-Ø—N‘N×*Ñ*¨9×+>Ñ+>Ó+@ÔAð ˜ŠzØñ Ø—‘Õ ð ô ×+Ñ+Ó-ˆDØ#Ÿ™¨u°d×6GÑ6GÓHˆDÔÜ�K‰KÐ:¸5¸'ÀÐJÔKØñ Ø—‘Õ ð øô! !ò -Ü)¨!Ó,Ð,ûð-ûô ò 	'Ø�~‰~×&Ñ&Ð.Ø�à�N‰N×#Ñ# A×&Ñ&ûð		'úð 'áØ—‘Õ ð ø‰zØ—‘Õ ð ús[   ‚B0F ÃF Ã
)E0 Ã3F ÄAF Å0	F	Å9FÆF	Æ	F Æ	GÆ3GÇG* ÇGÇG* Ç*G?c              ƒ   ó*  K  — 	 | j                  d¬«      ƒ d{  –—† }| j                  |j                  «       j                  «       |j                  «       j	                  «       «      }|j                  «       j                  «       rt        d«      ‚| j                  j                  €*t        j                  d«       	 |r|j                  «        yy|s2	 | j                  j                  |j                  «       «      ƒ d{  –—†  |dk  r	 |r|j                  «        yyt        j                  «       }t        || j                   «      }t        j#                  d|› d�«       |j%                  ||«       |r|j                  «        yy7 �Œo7 ŒŠ# t        $ r}t        |«      ‚d}~ww xY w# t        $ rF}| j                  j&                  €|‚| j                  j'                  |«      ƒ d{  –—†7   Y d}~Œd}~ww xY w# |r|j                  «        w w xY w­w)	zx
        Async task to renew tokens from identity provider.
        Schedules renewal tasks based on token TTL.
        Trš   Nr›   rœ   r   r�   rž   )r†   r�   rŸ   r    r¡   r¢   r   rR   r   rV   r£   r¤   r*   ra   rb   rv   rw   rW   rj   r"   )r   r[   rq   r¥   r�   r„   ro   rx   s           r   rw   zTokenManager._renew_token_async(  sÖ  è ø€ ð$	!Ø"×6Ñ6ÀTÐ6ÓJ×JˆIØ×1Ñ1Ø×#Ñ#Ó%×7Ñ7Ó9Ø×#Ñ#Ó%×8Ñ8Ó:óˆEð
 ×"Ñ"Ó$×/Ñ/Ô1Ü%Ð&BÓCÐCà�~‰~×%Ñ%Ð-Ü—‘ØVôð ñ* Ø—‘Õ ð ñ'  ð-ØŸ.™.×0Ñ0°×1DÑ1DÓ1FÓG×GÐGð ˜ŠzØñ Ø—‘Õ ð ô ×+Ñ+Ó-ˆDÜ,¨T°4×3JÑ3JÓKˆGÜ�K‰KÐ:¸5¸'ÀÐJÔKØ�O‰O˜E 7Ô+ñ Ø—‘Õ ð ðE Kùð" HùÜ ò -Ü)¨!Ó,Ð,ûð-ûô ò 	-Ø�~‰~×&Ñ&Ð.Ø�à—.‘.×)Ñ)¨!Ó,×,Ö,ûð		-ûñ Ø—‘Õ ð üs¦   ‚H„F) ™FšB"F) Â=HÃF) Ã,F Ä FÄF ÄF) ÄHÄAF) Å4HÆF) ÆF Æ	F&ÆF!Æ!F&Æ&F) Æ)	G8Æ26G3Ç(G+Ç)G3Ç.G; Ç3G8Ç8G; Ç;HÈH)F)Fr   F)FN)r$   r%   r&   r   r8   r   rY   r   Úboolr   rh   r6   ry   rX   r   r€   r†   r�   rŠ   r‹   ra   ri   rk   rw   r+   r   r   rK   rK   y   s,  „ ðØ!:ðØDVóòð #ñà%ðð ðð 
�"�d�(Ñ	ó	ð> #(Ø%&Ø"ñà%ðð  ðð #ð	ð
 ðð 
�"�d�(Ñ	óò0&ñ$°Mó $ñ$Àó $ð 0°Eð 0Àuð 0ÐQVó 0ð
°Eó 
ð

°Eð 

Àuó 

ð GKñ,!Ø ð,!Ø6=·m±mó,!ð^ GKñ,!Ø ð,!Ø6=·m±mô,!r   rK   c                 ó   ‡ ‡‡‡— ˆˆˆˆ fd„}|S )aŸ  
    Wraps an asynchronous function so it can be used with loop.call_later.

    :param loop: The event loop in which the coroutine will be executed.
    :param coro_func: The coroutine function to wrap.
    :param args: Positional arguments to pass to the coroutine function.
    :param kwargs: Keyword arguments to pass to the coroutine function.
    :return: A regular function suitable for loop.call_later.
    c                  ó@   •— t        j                   ‰‰ i ‰¤Ž‰¬«       y )N)ro   )ra   Úensure_future)r^   Ú	coro_funcÚkwargsro   s   €€€€r   rx   z'_async_to_sync_wrapper.<locals>.wrappedb  s   ø€ ä×Ñ™i¨Ð8°Ñ8¸tÖDr   r+   )ro   r«   r^   r¬   rx   s   ```` r   rv   rv   W  s   û€ ÷Eð €Nr   Ú
event_loopc                 óN   — t        j                  | «       | j                  «        y)zŠ
    Starts event loop in a thread.
    Used to be able to schedule tasks using loop.call_later.

    :param event_loop:
    :return:
    N)ra   Úset_event_loopÚrun_forever)r­   s    r   rg   rg   i  s   € ô ×Ñ˜:Ô&Ø×ÑÕr   )ra   Úloggingre   r   r   Útimer   Útypingr   r   r   r	   Úredis.auth.errr
   r   Úredis.auth.idpr   Úredis.auth.tokenr   Ú	getLoggerr$   rV   r   r-   r8   rK   rv   ÚAbstractEventLooprg   r+   r   r   Ú<module>r¹      sx   ðÛ Û Û ß 'Ý ß 2Ó 2ç ;Ý 4Ý *à	ˆ×	Ñ	˜8Ó	$€÷"ñ "÷6 ñ  ÷,6"ñ 6"÷r[!ñ [!ò|ð$	¨G×,EÑ,Eô 	r   