
    tniL                        d dl Z d dlmZ d dlmZmZmZ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 d dlmZmZ d d	lmZ  e j        e          Z G d
 de
          Z G d de
          ZdedefdZdededefdZ	 d#dededededdf
dZ ej                     Z!e!"                                	 d$deeedf          ej#        d          f         defd            Z$e!"                                 ej#        dd          dfdeedf         deeedf          ej#        d          f         defd            Z%e!"                                 ej#        dd           ej#        dd          ddfdeedf         deedf         deeedf          ej#        d          f         dee ej&        d d!          f         def
d"            Z'dS )%    N)Path)	AnnotatedAnyOptionalUnion)	BaseModel)	APIClient)get_app_config)Identity)get_rich_toolkithandle_http_errors)"validate_environment_variable_namec                   4    e Zd ZU eed<   dZee         ed<   dS )EnvironmentVariablenameNvalue)__name__
__module____qualname__str__annotations__r   r        [/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/fastapi_cloud_cli/commands/env.pyr   r      s/         
IIIE8C=r   r   c                   &    e Zd ZU ee         ed<   dS )EnvironmentVariableResponsedataN)r   r   r   listr   r   r   r   r   r   r      s$         
"
######r   r   app_idreturnc                    t                      5 }|                    d|  d          }|                                 t                              |                                          cd d d            S # 1 swxY w Y   d S )N/apps//environment-variables/)r	   getraise_for_statusr   model_validatejson)r   clientresponses      r   _get_environment_variablesr*      s    	 K::FvFFFGG!!###*99(--//JJ	K K K K K K K K K K K K K K K K K Ks   AA55A9<A9r   c                     t                      5 }|                    d|  d|           }d d d            n# 1 swxY w Y   |j        dk    rdS |                                 dS )Nr"   r#   i  FT)r	   deletestatus_coder%   )r   r   r(   r)   s       r   _delete_environment_variabler.   "   s    	 Q==!O&!O!O!O!OPPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q s""u4s   7;;Fr   	is_secretc                     t                      5 }|                    d|  d|||d          }|                                 d d d            d S # 1 swxY w Y   d S )Nr"   r#   )r   r   r/   )r'   )r	   postr%   )r   r   r   r/   r(   r)   s         r   _set_environment_variabler2   .   s     
 $;;4V444YGG  
 
 	!!###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   4AAApathz:A path to the folder containing the app you want to deploy)helpc                 d   t                      }t          d          5 }|                                s+|                    dd           t	          j        d          | pt          j                    }t          |          }|s-|                    d| d           t	          j        d          |	                    d	d
          5 }t          |          5  t          |j                  }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |j        s#|                    d           	 ddd           dS |                    d           |                                 |j        D ] }|                    d|j         d           !	 ddd           dS # 1 swxY w Y   dS )z5
    List the environment variables for the app.
    Tminimal<No credentials found. Use [blue]`fastapi login`[/] to login.authtag   !No app found in the folder [bold][/].!Fetching environment variables...	transientNNo environment variables found.zEnvironment variables:z[bold]z[/])r   r   is_logged_inprinttyperExitr   cwdr
   progressr   r*   r   r   
print_liner   )r3   identitytoolkitapp_path
app_configrH   environment_variablesenv_vars           r   r   r   <   s    zzH	$	'	'	' !67$$&& 	 MMN    
 *Q--%48::#H--
 	 MMBHBBB   *Q--/4  
 
 	V#H-- V V(B:CT(U(U%V V V V V V V V V V V V V V V	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V %) 	MM;<<<7!6 !6 !6 !6 !6 !6 !6 !6: 	.///,1 	6 	6GMM47<4445555	6A!6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6 !6sa   B*F%	DC:.D:C>>DC>DF%D	F%D	 F%AF%%F),F)z.The name of the environment variable to deletec                    t                      }t          d          5 }|                                s+|                    dd           t	          j        d          |pt          j                    }t          |          }|s-|                    d| d           t	          j        d          | s|	                    d	d
          5 }t          |          5  t          |j                  }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |j        s#|                    d           	 ddd           dS |                    dd |j        D                       } | sJ nPt          |           s-|                    d|  d           t	          j        d          |                                 |	                    dd
          5 }t          |          5  t#          |j        |           }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |s)|                    d           t	          j        d          |                    d|  d           ddd           dS # 1 swxY w Y   dS )z6
    Delete an environment variable from the app.
    Tr6   r8   r9   r:   r<   r=   r>   r?   r@   NrB   z*Select the environment variable to delete:c                 ,    g | ]}|j         |j         d S ))r   r   )r   ).0rO   s     r   
<listcomp>zdelete.<locals>.<listcomp>   s4        %\GLAA  r   )optionsz$The environment variable name [bold]z[/] is invalid.zDeleting environment variablezEnvironment variable not found.Environment variable [bold]z[/] deleted.)r   r   rC   rD   rE   rF   r   rG   r
   rH   r   r*   r   r   askr   rI   r.   )	r   r3   rJ   rK   path_to_deployrM   rH   rN   deleteds	            r   r,   r,   o   sj   " zzH	$	'	'	' <H7$$&& 	 MMN    
 *Q--+#N33
 	 MMHNHHH   *Q-- 	!!!3t "   '11  ,F")- -)                             )- ?@@@=<H <H <H <H <H <H <H <H@ ;;< #8#=     D KKKK5d;; $P4PPP   jmm#   +t  
 
 	P#H-- P P6z7H$OOP P P P P P P P P P P P P P P	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P  	 MM;<<<*Q--FDFFFGGGy<H <H <H <H <H <H <H <H <H <H <H <H <H <H <H <H <H <Hs   B,I?DC<0D<D  DD DI?D	I?D	 I?BI?H#*H H#HH#HH#I?#H'	'I?*H'	+AI??JJz+The name of the environment variable to setz,The value of the environment variable to setsecretz--secretz'Mark the environment variable as secretc           	         t                      }t          d          5 }|                                s+|                    dd           t	          j        d          |pt          j                    }t          |          }|s-|                    d| d           t	          j        d          | s-|r|	                    d	          } n|	                    d
          } |s/|r|	                    dd          }n|	                    d          }|
                    dd          5 }| J |J t          |          5  t          |j        | ||           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |r|                    d|  d           n|                    d|  d           ddd           dS # 1 swxY w Y   dS )z2
    Set an environment variable for the app.
    Tr6   r8   r9   r:   r<   r=   r>   z$Enter the name of the secret to set:z2Enter the name of the environment variable to set:zEnter the secret value:)passwordz,Enter the value of the environment variable:zSetting environment variabler@   Nz"Secret environment variable [bold]z[/] set.rU   )r   r   rC   rD   rE   rF   r   rG   r
   inputrH   r   r2   r   )	r   r   r3   rY   rJ   rK   rW   rM   rH   s	            r   setr]      s   8 zzH	$	'	'	' -H7$$&& 	 MMN    
 *Q--+#N33
 	 MMHNHHH   *Q-- 	 }}%KLL}}H   	V V&?$OO&TUU*d  
 
 	R###$$$#H-- R R)**;T5&QQQR R R R R R R R R R R R R R R	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R  	HMMMtMMMNNNNMMFFFFGGG[-H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -HsZ   D
G	)E<E%E<%E))E<,E)-E<0G	<F 	 G	F 	8G		GG)F)N)(loggingpathlibr   typingr   r   r   r   rE   pydanticr   fastapi_cloud_cli.utils.apir	   fastapi_cloud_cli.utils.appsr
   fastapi_cloud_cli.utils.authr   fastapi_cloud_cli.utils.clir   r   fastapi_cloud_cli.utils.envr   	getLoggerr   loggerr   r   r   r*   boolr.   r2   Typerenv_appcommandArgumentr   r,   Optionr]   r   r   r   <module>ro      s*          2 2 2 2 2 2 2 2 2 2 2 2        1 1 1 1 1 1 7 7 7 7 7 7 1 1 1 1 1 1 L L L L L L L L J J J J J J		8	$	$         )      
$ $ $ $ $) $ $ $Ks K/J K K K K	 	C 	D 	 	 	 	 ;@$ $$$#&$37$	$ $ $ $ %+-- 	 	/6 /6
dDjM	
 	
 	
	/6 	/6 /6 /6 /6d 	+U^=   	NH NH
T	
NH
 dDjM	
 	
 	
	NH 	NH NH NH NHb 	+U^:   -en;   	 	+JH JH
T	
JH
 dJH dDjM	
 	
 	
	JH :	
 	
 	
	JH, 	-JH JH JH JH JH JHr   