
    tni	                         d Z ddlZddlmZ ddlZej                            d          Zdde	de	d	dfd
Z
dde	fdZddZdS )z
runpod | cli | config.py

A collection of functions to set and validate configurations.
Configurations are TOML files located under ~/.runpod/
    N)Pathz~/.runpod/config.tomldefaultFapi_keyprofilereturnc                 <   t          j        t           j                            t                    d           t          t                                        d           |sSt          t          d          5 }|t          j	        |          v rt          d          	 ddd           n# 1 swxY w Y   t          t          dd          5 }|                    d	|z   d
z              |                    d| z   dz              ddd           dS # 1 swxY w Y   dS )aG  
    Sets the user's credentials in ~/.runpod/config.toml
    If profile already exists user must use `update_credentials` instead.

    Args:
        api_key (str): The user's API key.
        profile (str): The profile to set the credentials for.

    --- File Structure ---

    [default]
    api_key = "RUNPOD_API_KEY"
    T)exist_okrbz9Profile already exists. Use `update_credentials` instead.NwzUTF-8)encoding[z]
zapi_key = "z"
)osmakedirspathdirnameCREDENTIAL_FILEr   touchopentomlload
ValueErrorwrite)r   r   	overwrite	cred_files       _/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/runpod/cli/groups/config/functions.pyset_credentialsr      s    K004@@@@... /4(( 	I$)I.... O   /	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
osW	5	5	5 9g-.../%78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s$   8&B++B/2B/7DDDc                 D   t           j                            t                    sdS 	 t	          t          d          5 }t          j        |          }ddd           n# 1 swxY w Y   | |vrdd|  dfS d||          vrdd|  dfS n# t          t          f$ r Y d	S w xY wd
S )z=
    Checks if the credentials file exists and is valid.
    )Fz%~/.runpod/config.toml does not exist.r
   NFz!~/.runpod/config.toml is missing z	 profile.r   z-~/.runpod/config.toml is missing api_key for )Fz/~/.runpod/config.toml is not a valid TOML file.)TN)	r   r   existsr   r   r   r   	TypeErrorr   )r   r   configs      r   check_credentialsr!   -   s     7>>/** >==H/4(( 	*IYy))F	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* &  PgPPPPPF7O++RRRR  , z" H H HGGGH :s:   B AB A""B %A"&B 5B BBc                     t           j                            t                    sdS t	          t          d          5 }t          j        |          }ddd           n# 1 swxY w Y   | |vrdS ||          S )zV
    Returns the credentials for the specified profile from ~/.runpod/config.toml
    Nr
   )r   r   r   r   r   r   r   )r   r   credentialss      r   get_credentialsr$   H   s     7>>/** t	ot	$	$ +	i	**+ + + + + + + + + + + + + + + k!!tws   AA!$A!)r   F)r   )__doc__r   pathlibr   tomlir   r   
expanduserr   strr   r!   r$        r   <module>r,      s     
			          '$$%<==9 9S 93 9PT 9 9 9 9: s    6           r+   