
    tni.                        d dl Z d dlZd dlmZ d dl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mZ d dlmZmZ  e j        e          Z G d d	e          Z G d
 de          Zdej        defdZdej        dededefdZdefdZdS )    N)Any)	BaseModel)Settings)	APIClient)
AuthConfigIdentitywrite_auth_config)get_rich_toolkithandle_http_errorsc                   F    e Zd ZU eed<   eed<   eed<   eed<   dZeed<   dS )AuthorizationData	user_codedevice_codeverification_uriverification_uri_complete   intervalN)__name__
__module____qualname__str__annotations__r   int     ]/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/fastapi_cloud_cli/commands/login.pyr   r      sO         NNN""""Hcr   r   c                       e Zd ZU eed<   dS )TokenResponseaccess_tokenN)r   r   r   r   r   r   r   r   r   r      s         r   r   clientreturnc                     t          j                    }|                     dd|j        i          }|                                 t
                              |j                  S )Nz/login/device/authorization	client_iddata)r   getpostr#   raise_for_statusr   model_validate_jsontext)r    settingsresponses      r   _start_device_authorizationr-      s^     |~~H{{%[(:L,M   H 00???r   r   r   c                    t          j                    }	 |                     d||j        dd          }|j        dvr|                                 |j        dk    rA|                                }|                    d          d	k    r|                                 |j        d
k    rnt          j        |           t          
                    |j                  }|j        S )NTz/login/device/tokenz,urn:ietf:params:oauth:grant-type:device_code)r   r#   
grant_typer$   )     r1   errorauthorization_pendingr0   )r   r&   r'   r#   status_coder(   jsontimesleepr   r)   r*   r   )r    r   r   r+   r,   r%   response_datas          r   _fetch_access_tokenr9   +   s    |~~H;;!*%/L   
 
 z11%%'''3&&==??Dxx  $;;;))+++3&&
8-0 "55hmDDM%%r   c            
      J   t                      } |                                 rQt          d          5 }|                    d           |                                 ddd           n# 1 swxY w Y   |                                 rTt          d          5 }|                    d           |                    d           ddd           n# 1 swxY w Y   dS t                      5 }t                      5 }|                    dd	           |                                 |                    d
          5 }t          |          5  t          |          }ddd           n# 1 swxY w Y   |j        }|                    d| d| d           ddd           n# 1 swxY w Y   |                                 |                    d          5 }t          j        |           t          |          5  t          ||j        |j                  }ddd           n# 1 swxY w Y   t%          t'          |                     |                    d           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )u&   
    Login to FastAPI Cloud. 🚀
    T)minimalz-Your session has expired. Logging in again...NzYou are already logged in.zKRun [bold]fastapi cloud logout[/bold] first if you want to switch accounts.zLogin to FastAPI CloudFastAPI)tagzStarting authorizationzOpening [link=]z[/link]z Waiting for user to authorize...)r   u   Now you are logged in! 🚀)r   
is_expiredr
   print
print_lineis_logged_inr   print_titleprogressr   r-   r   logtyperlaunchr9   r   r   r	   r   )identitytoolkitr    rD   authorization_dataurlr   s          r   loginrL   K   s    zzH !d+++ 	!wMMIJJJ   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!  d+++ 	wMM6777MM]  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 				 8w	 8v4)DDD677 	>8#H-- I I%@%H%H"I I I I I I I I I I I I I I I %>CLL<#<<<<<===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	@AA 
	8XL#H--  2.:<N<W                 
 jlCCCDDDLL6777
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	88 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   *A))A-0A-+CCC*J9AJ :F 
E&	F &E**F -E*.&F J  F$$J 'F$(,J $I)8H 	I) H$$I)'H$(5I)J )I--J 0I-1J 4J J	JJ	JJJ)loggingr6   typingr   httpxrF   pydanticr   fastapi_cloud_cli.configr   fastapi_cloud_cli.utils.apir   fastapi_cloud_cli.utils.authr   r   r	   fastapi_cloud_cli.utils.clir
   r   	getLoggerr   loggerr   r   Clientr-   r   r   r9   rL   r   r   r   <module>rX      s                   - - - - - - 1 1 1 1 1 1 P P P P P P P P P P L L L L L L L L		8	$	$    	       I   @L@@ @ @ @& &3 &# &RU & & & &@,8s ,8 ,8 ,8 ,8 ,8 ,8r   