o
    ;i                     @   sb  d dl Z d dlZd dlmZ d dlmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZ ejd	d
ddZejdddZejdddZejdddZejddejejdddejdddeeefdee dee dee dedef
ddZejddejeeedfdee dededee fddZejddejdd ZdS )     N)datetime)Optional)synchronizer)_Client)OutputManager)
_new_token
_set_token)api_pb2tokenzManage tokens.T)namehelpno_args_is_helpzModal profile to set credentials for. If unspecified (and MODAL_PROFILE environment variable is not set), uses the workspace name associated with the credentials.)r   z:Activate the profile containing this token after creation.z2Make a test request to verify the new credentials.set)r   zAccount token ID.zAccount token secret.token_idtoken_secretprofileactivateverifyc                    sB   | du r
t  d} |du rt  d}t| ||||dI dH  dS )zSet account credentials for connecting to Modal.

    If the credentials are not provided on the command line, you will be prompted to enter them.
    Nz	Token ID:zToken secret:)r   r   r   )getpassr   )r   r   r   r   r    r   C/home/ubuntu/.local/lib/python3.10/site-packages/modal/cli/token.pyr   $   s   

newsourcec                    s   t | |||dI dH  dS )z9Create a new token by using an authenticated web session.r   r   r   r   N)r   r   r   r   r   r   8   s   	infoc            
         s  t  I dH } t }| j|I dH }t }g }tj	dr&|
d tj	dr1|
d |rNd|}t|dkr@dnd}|d| d	| d
 |d|j  |jrc|d|j  |d|j d|j d
 |dr|d|jj d|jj d
 n+|dr|j}|d|j d|j d
 |dr|d|jj d|jj d
 |dr|jjdkrt|jj }|d|d d |dr|j jdkrt|j j }	|d|	d d dS dS dS )z=Display information about the token that is currently in use.NMODAL_TOKEN_IDMODAL_TOKEN_SECRETz and    s z[dim](Using z environment variablez)[/dim]z[bold]Token:[/bold] z[bold]Name:[/bold] z[bold]Workspace:[/bold] z [dim](user_identityz[bold]User:[/bold] service_user_identityz[bold]Service User:[/bold] 
created_byz[bold]Created By:[/bold] 
created_atr   z [bold]Created at:[/bold] [white]z%Y-%m-%d %H:%M:%S %Zz[/white]
expires_atz [bold]Expires at:[/bold] [white])!r   from_envr	   TokenInfoGetRequeststubTokenInfoGetr   getosenvironappendjoinlenprintr   
token_nameworkspace_nameworkspace_idHasFieldr    usernameuser_idr!   service_user_nameservice_user_idr"   r#   secondsr   fromtimestamp
astimezonestrftimer$   )
clientreqrespoutputenv_varsenv_vars_strpluralservice
created_dt
expires_dtr   r   r   r   D   sD   



"

)r   r*   r   typingr   typermodal._utils.async_utilsr   modal.clientr   modal.outputr   modal.token_flowr   r   modal_protor	   Typer	token_cliOptionprofile_optionactivate_optionverify_optioncommandcreate_blockingstrboolr   r   r   r   r   r   r   <module>   sv   



