o
    Á¿i»  ã                   @   s`   d dl mZ d dlZd dlZd dlmZmZmZmZ dd„ Z	dd„ Z
dd	„ ZG d
d„ deƒZdS )é    )Úprint_functionN)Úis_p3kÚconfigparserÚIterableUserDictÚ	get_inputc                 C   s8   t ƒ rt| d tjd ntj | d ¡ tj ¡  d S )NÚ
)Úfile)r   ÚprintÚsysÚstderrÚwriteÚflush)Úmsg© r   úK/home/ubuntu/.local/lib/python3.10/site-packages/datadog/dogshell/common.pyÚ	print_err   s   r   c                 C   sP   d| v r&| d }t |tƒr|D ]	}td |¡ƒ qntd |¡ƒ t d¡ dS )NÚerrorsz	ERROR: {}é   F)Ú
isinstanceÚlistr   Úformatr
   Úexit)Úresr   Úerrorr   r   r   Úreport_errors   s   
ÿ
r   c                 C   sL   d| v r$| d }t |tƒr|D ]	}td |¡ƒ qdS td |¡ƒ dS dS )NÚwarningszWARNING: {}TF)r   r   r   r   )r   r   Úwarningr   r   r   Úreport_warnings!   s   
ÿr   c                   @   s   e Zd Zdd„ ZdS )ÚDogshellConfigc              	   C   s¨  t  ¡ }|d urB|dv rd| d< n1|dv rd| d< n(|dv r#d| d< n|dv r,d	| d< n|d
v r5d| d< n|dv r>d| d< n|| d< |d urS|d urS|| d< || d< nït |tj¡rn| |¡ | d¡smtdd| giƒ n—zd }|d u s}| ¡  	¡ dvrît
d| ƒ}| ¡  	¡ dv rÑ	 t
dƒ}| ¡ r•ntdƒ qŒ	 t
dƒ}| ¡ r¤ntdƒ q›| d¡ | dd|¡ | dd|¡ t|dƒ}| |¡ | ¡  td| ƒ n| ¡  	¡ dkrâtd ƒ t d!¡ |d u s}| ¡  	¡ dvs}W n ttfy   td"ƒ t d!¡ Y nw | dd¡| d< | dd¡| d< | d#¡r$t| d#¡ƒ| d$< | dd%¡r3| dd%¡| d%< | dd¡rB| dd¡| d< | d d urP| d d usRJ ‚d S )&N)zdatadoghq.comÚuszhttps://api.datadoghq.comÚapi_host)zdatadoghq.euÚeuzhttps://api.datadoghq.eu)zus3.datadoghq.comÚus3zhttps://api.us3.datadoghq.com)zus5.datadoghq.comÚus5zhttps://api.us5.datadoghq.com)zap1.datadoghq.comÚap1zhttps://api.ap1.datadoghq.com)zddog-gov.comÚgovzhttps://api.ddog-gov.comÚapi_keyÚapp_keyÚ
Connectionr   z%s has no [Connection] section)Ú ÚyÚnz6%s does not exist. Would you like to create it? [Y/n] )r)   r*   TzTWhat is your api key? (Get it here: https://app.datadoghq.com/account/settings#api) z:Datadog api keys can only contain alphanumeric characters.zTWhat is your app key? (Get it here: https://app.datadoghq.com/account/settings#api) z:Datadog app keys can only contain alphanumeric characters.ÚapikeyÚappkeyÚwzWrote %sr+   zExiting
r   z
ExitingÚProxyÚproxiesÚ	host_name)r   ÚConfigParserÚosÚaccessÚF_OKÚreadÚhas_sectionr   ÚstripÚlowerr   Úisalnumr	   Úadd_sectionÚsetÚopenr   Úcloser   r
   r   ÚKeyboardInterruptÚEOFErrorÚgetÚdictÚitemsÚ
has_option)ÚselfÚconfig_filer&   r'   r    ÚconfigÚresponseÚfr   r   r   Úload.   sŠ   








€ÿùÿù




ß€"ý$zDogshellConfig.loadN)Ú__name__Ú
__module__Ú__qualname__rJ   r   r   r   r   r   -   s    r   )Ú
__future__r   r3   r
   Údatadog.util.compatr   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   