
    %i"                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZm	Z	 d dl
mZmZ d dlmZ  ej                  d      Z ej                  d      Zej$                   G d	 d
             Zej$                   G d d             Zej$                   G d d             Zej$                   G d d             Z G d d      Z G d d      ZdefdZdefdZy)    N)OptionalListLiteral)MessageToDict	ParseDict)RoomConfiguration   )hours   )minutesc                   <   e Zd ZU dZee   ed<   dZee   ed<   dZee   ed<   dZ	ee   ed<   dZ
ee   ed<   dZeed<   dZee   ed	<   d
Zeed<   d
Zeed<   d
Zeed<   dZeee      ed<   dZee   ed<   dZee   ed<   dZee   ed<   dZee   ed<   dZee   ed<   y)VideoGrantsNroom_create	room_listroom_record
room_admin	room_join roomdestination_roomTcan_publishcan_subscribecan_publish_datacan_publish_sourcescan_update_own_metadataingress_adminhiddenrecorderagent)__name__
__module____qualname__r   r   bool__annotations__r   r   r   r   r   strr   r   r   r   r   r   r   r   r   r   r        R/var/www/html/engine/venv/lib/python3.12/site-packages/livekit/api/access_token.pyr   r      s     #'K$& $Ix~$"&K$& "&J% $Ix~$D#N '+hsm* KM4!d!
 04$s),3 /3Xd^2 %)M8D>( "FHTN!  $Hhtn# !E8D> r'   r   c                   *    e Zd ZU dZeed<   dZeed<   y)	SIPGrantsFadmincallN)r    r!   r"   r+   r#   r$   r,   r&   r'   r(   r*   r*   G   s     E4D$r'   r*   c                       e Zd ZU dZeed<   y)InferenceGrantsFperformN)r    r!   r"   r/   r#   r$   r&   r'   r(   r.   r.   O   s     GTr'   r.   c                       e Zd ZU dZeed<   dZeed<   dZeed<   dZeed<   dZ	e
e   ed<   dZe
e   ed<   dZe
e   ed	<   dZe
eeef      ed
<   dZe
e   ed<   dZe
e   ed<   dZe
e   ed<   defdZy)Claimsr   identitynamekindmetadataNvideosip	inference
attributessha256room_presetroom_configreturnc                 ~    t        j                  | d       }| j                  rt        | j                        |d<   |S )Nc                 ^    | D ci c]  \  }}|	|dk7  st        |      | c}}S c c}}w )Nr   )snake_to_lower_camel)itemskvs      r(   <lambda>zClaims.asdict.<locals>.<lambda>g   s8    7<(/3q!RSWYRY$Q'*(  (s   
))))dict_factory
roomConfig)dataclassesasdictr<   r   )selfclaimss     r(   rH   zClaims.asdictc   s?    ##
 #01A1A#BF< r'   )r    r!   r"   r2   r%   r$   r3   r4   r5   r6   r   r   r7   r*   r8   r.   r9   dictr:   r;   r<   r   rH   r&   r'   r(   r1   r1   U   s    HcD#ND#NHc#'E8K '#C)	#+/Ix(/+/Jc3h(/ FHSM !%K#%/3K+,3
 
r'   r1   c                   &   e Zd Zed   Z	 	 ddee   dee   ddfdZdej                  dd fdZ
d	edd fd
Zd	edd fdZd	edd fdZdedd fdZdedd fdZdedd fdZdedd fdZdeeef   dd fdZdedd fdZdedd fdZdedd fdZdefdZy)AccessToken)standardegressingressr7   r   Napi_key
api_secretr=   c                     |xs t        j                  d      }|xs t        j                  d      }|r|st        d      || _        || _        t               | _        d| _        t        | _	        y )NLIVEKIT_API_KEYLIVEKIT_API_SECRET"api_key and api_secret must be setr   )
osgetenv
ValueErrorrQ   rR   r1   rJ   r2   DEFAULT_TTLttl)rI   rQ   rR   s      r(   __init__zAccessToken.__init__s   sd    
 9RYY'89B299-A#B
jABB$h r'   r[   c                     || _         | S N)r[   )rI   r[   s     r(   with_ttlzAccessToken.with_ttl   s    r'   grantsc                 (    || j                   _        | S r^   )rJ   r6   rI   r`   s     r(   with_grantszAccessToken.with_grants   s    "r'   c                 (    || j                   _        | S r^   )rJ   r7   rb   s     r(   with_sip_grantszAccessToken.with_sip_grants   s     r'   c                 (    || j                   _        | S r^   )rJ   r8   rb   s     r(   with_inference_grantsz!AccessToken.with_inference_grants   s     &r'   r2   c                     || _         | S r^   )r2   )rI   r2   s     r(   with_identityzAccessToken.with_identity   s     r'   r4   c                 (    || j                   _        | S r^   )rJ   r4   )rI   r4   s     r(   	with_kindzAccessToken.with_kind       r'   r3   c                 (    || j                   _        | S r^   )rJ   r3   )rI   r3   s     r(   	with_namezAccessToken.with_name   rl   r'   r5   c                 (    || j                   _        | S r^   )rJ   r5   )rI   r5   s     r(   with_metadatazAccessToken.with_metadata   s    'r'   r9   c                 (    || j                   _        | S r^   )rJ   r9   )rI   r9   s     r(   with_attributeszAccessToken.with_attributes   s    !+r'   r:   c                 (    || j                   _        | S r^   )rJ   r:   )rI   r:   s     r(   with_sha256zAccessToken.with_sha256   s    #r'   presetc                 (    || j                   _        | S r^   )rJ   r;   )rI   ru   s     r(   with_room_presetzAccessToken.with_room_preset       "(r'   configc                 (    || j                   _        | S r^   )rJ   r<   )rI   ry   s     r(   with_room_configzAccessToken.with_room_config   rx   r'   c           
         | j                   j                  }|r/|j                  r#| j                  r|j                  st        d      | j                   j                         }|j                  | j                  | j                  t        j                  t        j                  j                  t        j                  j                        j                               t        j                  t        j                  j                  t        j                  j                        | j                   z   j                               d       t#        j$                  || j&                  d      S )Nz1identity and room must be set when joining a room)subissnbfexpHS256)	algorithm)rJ   r6   r   r2   r   rY   rH   updaterQ   calendartimegmdatetimenowtimezoneutcutctimetupler[   jwtencoderR   )rI   r6   
jwt_claimss      r(   to_jwtzAccessToken.to_jwt   s    !!U__dmm5::PQQ [['')
}}||x'8'8'<'<X=N=N=R=R'S'`'`'bc&&**8+<+<+@+@ADHHLZZ\			
 zz*dooIIr'   NN)r    r!   r"   r   ParticipantKindr   r%   r\   r   	timedeltar_   r   rc   r*   re   r.   rg   ri   rk   rn   rp   rK   rr   rt   rw   r   r{   r   r&   r'   r(   rM   rM   p   s?   MNO "&$(# SM 
	&H.. = + - i M O  c m o - c m c m $sCx. ] # - s } '8 ] J Jr'   rM   c            
       j    e Zd Z	 	 deddee   dee   dej                  ddfdZdd	d
ede	de
fdZy)TokenVerifierN)leewayrQ   rR   r   r=   c                    |xs t        j                  d      }|xs t        j                  d      }|| _        || _        || _        y )NrT   rU   )rW   rX   rQ   rR   _leeway)rI   rQ   rR   r   s       r(   r\   zTokenVerifier.__init__   sA     9RYY'89B299-A#B
$r'   T)verify_signaturetokenr   c                   |r#| j                   r| j                  st        d      t        j                  || j                  xs d| j                   xs ddg| j
                  j                         d|i      }|j                  dt                     }|j                         D ci c]  \  }}t        |      | }}}|j                         D ci c]  \  }}|t        j                  v s|| }}}t        di |}|j                  dt                     }|j                         D ci c]  \  }}t        |      | }}}|j                         D ci c]  \  }}|t        j                  v s|| }}}t        di |}	|j                  dt                     }
|
j                         D ci c]  \  }}t        |      | }
}}|
j                         D ci c]  \  }}|t        j                  v s|| }
}}t        di |
}t        |j                  d	d      |j                  d
d      ||	||j                  di       |j                  dd      |j                  dd            }|j                  d      r|j                  d      |_        |j                  d      r*t#        |j                  d      t%               d      |_        |S c c}}w c c}}w c c}}w c c}}w c c}}w c c}}w )NrV   r   r   r   )keyissuer
algorithmsr   optionsr6   r7   r8   r}   r3   r9   r5   r:   )r2   r3   r6   r7   r8   r9   r5   r:   
roomPresetrF   T)ignore_unknown_fieldsr&   )rQ   rR   rY   r   decoder   total_secondsgetrK   rA   camel_to_snaker   __dataclass_fields__r*   r.   r1   r;   r   r   r<   )rI   r   r   rJ   
video_dictrB   rC   r6   sip_dictr7   inference_dictr8   grant_claimss                r(   verifyzTokenVerifier.verify   s   T\\ABB%2<<%2y<<--/')9:
 ZZ0
7A7G7G7IJtq!nQ'*J
J'1'7'7'9ctq!Q+BbBb=badc
c)j)::eTV,5=^^5EFTQN1%q(FF%-^^%5]TQi>\>\9\AqD]]#(#K8;I;O;O;QR41a.+Q.RR+113
QqO<`<`7`AqD
 
 $5n5	ZZr*FB'zz,3ZZ
B/::h+	
 ::l#'-zz,'?L$::l#'0

<(!#&*(L$ I Kc G] S
s6   %KK,K,K K&3K&3K,K2:K2r   )r    r!   r"   DEFAULT_LEEWAYr   r%   r   r   r\   r#   r1   r   r&   r'   r(   r   r      sm     "&$(
 &4# SM
 "" 
 >B 1C 1d 1f 1r'   r   tc                 L    t        j                  dd|       j                         S )Nz(?<!^)(?=[A-Z])_)rer}   lowerr   s    r(   r   r     s    66$c1-3355r'   c                 b    dj                  d t        | j                  d            D              S )Nr   c              3   J   K   | ]  \  }}|r|j                         n|  y wr^   )
capitalize).0iwords      r(   	<genexpr>z'snake_to_lower_camel.<locals>.<genexpr>  s"     [44??$t3[s   !#r   )join	enumeratesplitr   s    r(   r@   r@     s%    77[9QWWUX\CZ[[[r'   )r   rG   r   r   rW   r   typingr   r   r   google.protobuf.json_formatr   r   livekit.protocol.roomr   r   rZ   r   	dataclassr   r*   r.   r1   rM   r   r%   r   r@   r&   r'   r(   <module>r      s      	  	 
 * * @ 3 h  q)###A. %! %! %!P      
   4WJ WJt@ @F6c 6\C \r'   