
    j                         U d dl Z d dl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  e j                  e      ZdZee   ed<   ddee   dej*                  fdZd	edefd
Zded	edefdZdee   ded	edefdZy)    N)FinalListOptional)ConfigurationErrorg      ?HEALTH_CHECK_TIMEOUTapi_keyreturnc                     t        j                         }t        j                  d | |j                  |j
                        }|S )N)	workspacer   check_tls_certificatecompress_json_requests)config
OpikConfighttpx_clientgetr   enable_json_request_compression)r   config_clients      |/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/configurator/opik_rest_helpers.py_get_httpx_clientr      s?    !G%;;&FF	F M    urlc                     	 t               5 }|j                  t        j                  |       t              }ddd       j
                  dk(  S # 1 sw Y   xY w# t        j                  $ r Y yt        $ r Y yw xY w)z
    Returns True if the given Opik URL responds to an HTTP GET request.

    Args:
        url (str): The base URL of the instance to check.

    Returns:
        bool: True if the instance responds with HTTP status 200, otherwise False.
    )r   timeoutN   F)	r   r   url_helpersget_is_alive_ping_urlr   status_codehttpxConnectTimeout	Exception)r   http_clientresponses      r   is_instance_activer$      sx    	 K"55c:DX ' H ! ##s**	 ! 
   s-   
A +AA AA A:/A:9A:c                    	 t        |       5 }|j                  t        j                  |            }ddd       j                  dk(  ry|j                  dv ryt        d|j                         # 1 sw Y   @xY w# t        j                  $ r}t        dt        |             d}~wt        $ r}t        d	t        |             d}~ww xY w)
aW  
    Validates if the provided Opik API key is correct by sending a request to the cloud API.

    Returns:
        bool: True if the API key is valid (status 200), False if the key is invalid (status 401 or 403).

    Raises:
        ConnectionError: If a network-related error occurs or the response status is neither 200, 401, nor 403.
    r   Nr   T)i  i  FzError while checking API key: zNetwork error occurred: Unexpected error occurred: )r   r   r   get_account_details_urlr   ConnectionErrortextr   RequestErrorstrr!   )r   r   r   r#   es        r   is_api_key_correctr.   2   s    Fw'6zzk&I&I#&NzOH (3&!!Z/!$B8==/"RSS ('  C 8QABB F ;CF8DEEFsE   A> &A2A> A> A> 2A;7A> >CB((C4CCr   c                    | st        d      	 t        |       5 }|j                  t        j                  |            }ddd       j                  dk7  r%t        d|j                   d|j                         |j                         j                  d	g       }||v S # 1 sw Y   axY w# t
        j                  $ r}t        dt        |             d}~wt        $ r}t        dt        |             d}~ww xY w)
a}  
    Verifies whether the provided workspace name exists in the user's cloud Opik account.

    Args:
        workspace (str): The name of the workspace to check.

    Returns:
        bool: True if the workspace is found, False otherwise.

    Raises:
        ConnectionError: Raised if there's an issue with connecting to the Opik service, or the response is not successful.
    z,API key must be set to check workspace name.r&   NzNetwork error: r'   r   zHTTP error: z - workspaceNames)r   r   r   r   get_workspace_list_urlr   r+   r)   r,   r!   r   r*   json)r   r   r   r   r#   r-   
workspacess          r   is_workspace_name_correctr4   L   s      !OPPFw'6zzk&H&H&MzNH ( s"X-A-A,B#hmm_UVV$MMO//0@"EJ
"" (' :Ax899 F ;CF8DEEFs:   B, &B  B,  B)%B, ,C>?CC>"C99C>)N)loggingtypingr   r   r   r   opik.exceptionsr   opik.url_helpersr   opik.configr   opik.httpx_clientr   	getLogger__name__LOGGERr   float__annotations__r,   Clientr   boolr$   r.   r4    r   r   <module>rC      s     ( (  . &  (			8	$%( eEl (	x} 	 	C D ,F F# F$ F4#x} # #3 #SW #r   