o
    i
                     @  sb   d dl mZ d dlZd dlZd dlZd dlmZ ddlmZm	Z	m
Z
mZ ddlmZ dddZdS )    )annotationsN)urlparse   )DEFAULT_FILEUserTokenCollectionpoll_for_tokenrequest_device_code)REGIONSargsargparse.NamespacereturnNonec              
   C  s  | j }t }||}|rtjdt dddf dS tjd |sd}d|  kr2ttksn tj	d	 t
t dd
D ]\}\}}tj	| d|  d|d  d qAzttdddd tdttd D  d}W n ty   d}Y nw d|  krttkr3n q3tt |d  d }t| j|\}}	t|	j}
tj	d|
 d t  z	tj|	dd W n
 tjy   Y nw tjd|	 ddf ||t| j|| tj	d tj	dt d dS )zpAuthenticate with Logfire.

    This will authenticate your machine with Logfire and store the credentials.
    z;You are already logged in. (Your credentials are stored in z)
zRIf you would like to log in using a different account, use the --region argument:
zlogfire --region <region> auth
N)
u   Welcome to Logfire! 🔥
zBBefore you can send data to Logfire, we need to authenticate you.
r      zBLogfire is available in multiple data regions. Please select one:
)startz. z (GCP region: 
gcp_regionzSelected region [/c                 s  s    | ]}t |V  qd S )N)str).0i r   `/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/_internal/cli/auth.py	<genexpr>1   s    zparse_auth.<locals>.<genexpr>z]: base_urlzPress Enter to open z in your browser...
r   )newzPlease open z7 in your browser to authenticate if it hasn't already.
z0Waiting for you to authenticate with Logfire...
zSuccessfully authenticated!
z(
Your Logfire credentials are stored in r   )logfire_urlr   is_logged_insysstderr
writelinesr   lenr	   write	enumerateitemsupperintinputjoinrange
ValueErrorlistvaluesr   _sessionr   netloc
webbrowseropenError	add_tokenr   )r
   r   tokens_collection	logged_inselected_regionr   	region_idregion_datadevice_codefrontend_auth_urlfrontend_hostr   r   r   
parse_auth   s\   

(,

r;   )r
   r   r   r   )
__future__r   argparser   r/   urllib.parser   authr   r   r   r   configr	   r;   r   r   r   r   <module>   s    