o
    Jh*                     @   s  d dl mZmZmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZm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mZ e  Z!dd Z"dd Z#ej$dd Z%ej$dd Z&edej'ej'e#eedej(ddgdgdZ)edej*ej*e%eedej+j,d-ej.ddgdgdZ/edej0ej0e&eedej1j,d-ej.ddd gdgdZ2ed!ej3ej4e"ej5e)e/e2gd"Z6d#S )$    )apt_newsconfigentitlementsevent_logger
exceptionshttpmessages)_is_attached)AptProxyScope)cli_util)ProArgumentProArgumentGroup
ProCommand)HelpCategory)ApplicationStatus)state_files)LXDGuestAttachEnum)configure_livepatch_proxyunconfigure_livepatch_proxy)configure_snap_proxyunconfigure_snap_proxyc                K   s   ddl m} | d dS )Nr   
get_parserr   )uaclient.clir   print_help_for_command)argscfgkwargsr    r   5/usr/lib/python3/dist-packages/uaclient/cli/config.pyaction_config   s   r    c                K   s   | j r)| j tjvrtjd| j dtjdtdj| j t|| j dd dS t	t
dd	 tjD d
 }d| d }tjD ]}t|j|t||dd q@|jsV|jrc|js\|jrettj dS dS dS )zPerform the 'config show' action optionally limit output to a single key

    :return: 0 on success
    :raise UbuntuProError: on invalid keys
    z'{}', argchoicesz{key} {value}Nkeyvaluer   c                 S   s   g | ]}t |qS r   )len).0xr   r   r   
<listcomp>6   s    z&action_config_show.<locals>.<listcomp>   z{key: <z	} {value})r&   r   UA_CONFIGURABLE_KEYSr   InvalidArgChoiceformatjoinprintgetattrstrmaxglobal_apt_http_proxyglobal_apt_https_proxyua_apt_http_proxyua_apt_https_proxyr   CLI_CONFIG_GLOBAL_XOR_UA_PROXY)r   r   r   	col_widthrow_tmplr&   r   r   r   action_config_show#   s.   


r<   c                K   sv  ddl m} | }z
| jd\}}W n ty'   |d tjd| jdw |tj	vr=|d tj
ddtj	d	| sL|d tj|d
tt||dtkri| dvrctj
ddd	| dk}|dv r|dd }|dkr|tj}ntj}t||| ||i}td#i | tj|}	|	 \}
}|
tjkrtd#i | n||jv r|dd }|dkrtj}ntj }t||| t|j!p|j"}|rt#t$j%j&ddd t'(|t)j*|| d|_!d|_"n||j+|j, v rQd|v rdnd}|dkrtj}ntj }||j+v r$t#t$j-j&d&|d&|d d| }t||| t|j.p2|j/}|rAt#t$j%j&ddd t'(|t)j0|| d|_.d|_/nb|dv rzt1|}|dk rgtd&|W nJ ty   |d t#d tj2||dw |d kr|rt34| n$t5j67  n|d!krt8|j9st: t5j;<t5j=t>?| d" t@||| dS )$zMPerform the 'config set' action.

    @return: 0 on success, 1 otherwise
    r   r   =z
config setz<key>=<value>)expectedactual<key>r!   r"   )r#   N)truefalsez<value>ztrue, falserA   
http_proxyhttps_proxy_r      zpro scoped aptz
global apt)current_proxyprevious_proxyhttpsapt_{}_proxyglobal_apt_{}_proxyoldnewglobal_)update_messaging_timermetering_timerzInvalid interval for {} r%   r   lxd_guest_attachguest_attachr   )Ar   r   key_value_pairsplit
ValueErrorr   r   GenericInvalidFormatr   r-   r.   r0   stripEmptyConfigValuetyper2   boollowerr   PROXY_VALIDATION_SNAP_HTTP_URLPROXY_VALIDATION_SNAP_HTTPS_URLvalidate_proxyr   r   	livepatchLivepatchEntitlementapplication_statusr   ENABLEDr   ua_scoped_proxy_optionsPROXY_VALIDATION_APT_HTTP_URLPROXY_VALIDATION_APT_HTTPS_URLr5   r6   r1   r   WARNING_APT_PROXY_OVERWRITEr/   r   configure_apt_proxyr
   UACLIENT&deprecated_global_scoped_proxy_optionsglobal_scoped_proxy_optionsWARNING_CONFIG_FIELD_RENAMEr7   r8   GLOBALintInvalidPosIntConfigValuer   update_apt_newsr   apt_news_contents_filedeleter	   is_attachedUnattachedErrorlxd_pro_config_filewriteLXDProConfigr   
from_valuesetattr)r   r   r   r   parserset_key	set_valueprotocol_typevalidate_urlentitlementlivepatch_statusrF   unset_currentr   r   r   action_config_setB   s   














r   c          	      K   sX  ddl m} | jtjvr| }|d tjddtjd| jdv rH| j	dd }t
|d	 tj|}| \}}|tjkrGt|d	 n[| j|jv rYt|tj| jd
 nJ| j|j|j v r| j|jv rd| jv rodnd}ttjjd|d|d d| j | _t|tj| jd
 n| jdkrtj !tj"t#j$d t%|| jd
 dS )zOPerform the 'config unset' action.

    @return: 0 on success, 1 otherwise
    r   r   zconfig unsetr@   r!   r"   rC   rF   )r   NrJ   r   rK   rL   rM   rP   rT   rU   )&r   r   r&   r   r-   r   r   r.   r0   rX   r   r   rc   rd   re   r   rf   r   rg   r   rk   r
   rl   rm   rn   eventinfor   ro   r/   rp   r   rx   ry   rz   r   OFFr|   )	r   r   r   r   r}   r   r   r   rF   r   r   r   action_config_unset   sP   





r   showr&   ?)helpnargs)	arguments)r   descriptionactionargument_groupssetrW   r!   )options)r   unset)r   metavarr   )r   r   r   help_categorysubcommandsN)7uaclientr   r   r   r   r   r   r   (uaclient.api.u.pro.status.is_attached.v1r	   uaclient.aptr
   r   r   uaclient.cli.commandsr   r   r   uaclient.cli.parserr   (uaclient.entitlements.entitlement_statusr   uaclient.filesr   uaclient.files.user_config_filer   uaclient.livepatchr   r   uaclient.snapr   r   get_event_loggerr   r    r<   assert_rootr   r   CLI_CONFIG_SHOW_DESCCLI_CONFIG_SHOW_KEYshow_subcommandCLI_CONFIG_SET_DESCCLI_CONFIG_SET_KEY_VALUEr/   r0   r-   set_subcommandCLI_CONFIG_UNSET_DESCCLI_CONFIG_UNSET_KEYunset_subcommandCLI_ROOT_CONFIGCLI_CONFIG_DESCOTHERconfig_commandr   r   r   r   <module>   s   $ 	
 
0


