403Webshell
Server IP : 159.223.102.202  /  Your IP : 216.73.216.195
Web Server : nginx/1.26.0
System : Linux Gen1-cloudpanel2ubuntu2404-1vcpu-1gb-nyc1-01 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User : albasshbotta ( 1021)
PHP Version : 8.2.19
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/uaclient/cli/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/uaclient/cli/__pycache__/__init__.cpython-312.pyc
�

|f��
�r�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZmZddlmZmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZm Z ddlm!Z"dd	lm#Z#m$Z$m%Z%dd
l&m'Z'ddl(m)Z)m*Z*ddl+m,Z,dd
l-m.Z.m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8m9Z9ddl:m;Z;m<Z<ddl=m>Z>ddl?m@Z@mAZAddlBmCZCddlDmEZEmFZFmGZGddlHmIZImJZJmKZKmLZLddlMmNZNmOZOddlPmQZQddlRmSZSddlTmUZUmVZVddlWmXZXmYZYdZZgd�Z[dZ\ej��Z^ej�e$j�ea��ZbGd �d!ej��Zddld"�Zed#�Zfd$�Zgdld%�Zhd&�Zid'�Zjd(�Zkd)�Zld*emfd+�Znd*emfd,�Zod*emfd-�Zpd.�Zqd/�Zrd0�Zsd1�Ztd2�Zud3�Zvd4ej�fd5�Zxd4ej�fd6�Zyd4ej�fd7�Zzd8�Z{d9�Z|d:�Z}d4ej�d;emd<emfd=�Z~d>d?�d@�ZdA�Z�dB�Z�efdC��Z�efdD��Z�dE�Z�egefehe��eedF�dG�����Z�egefehe��eedH�dI�����Z�egefeh�eedJ�dKe�fdL�����Z�d4ej�dMe�dKe�fdN�Z�d4ej�dKdfdO�Z�dP�Z�efd4ej�dKe�fdQ��Z�dR�Z�eiefeedS�dT����Z�d4ej�fdU�Z�d4ej�fdV�Z�d4ej�fdW�Z�dX�Z�d4ej�fdY�Z�dmdZ�Z�d4ej�fd[�Z�eh�d4ej�fd\��Z�d4ej�fd]�Z�efeed^�d4ej�fd_���Z�d4ej�d`e8daemdbeemdKdf
dc�Z�dd�Z�dldnde�Z�dndf�Z�dmdg�Z�dh�Z�di�Z�e�dldj��Z�eadkk(re�jDe���yy)oz2Client to manage Ubuntu Pro services on a machine.�N��wraps)�List�Optional�Tuple)�actions�apt�apt_news�config�contract�daemon�defaults�entitlements�event_logger�
exceptions�http�lock)�log)�messages�security_status)�status)�timer�util�version)�call_api)�FullAutoAttachOptions�_full_auto_attach)�	_initiate)�MagicAttachRevokeOptions�_revoke)�MagicAttachWaitOptions�_wait)�_reboot_required)�_is_attached)�
AptProxyScope�setup_apt_proxy)�NAME�
USAGE_TMPL)�set_fix_parser)�AttachActionsConfigFile�IncorrectTypeError)�PRINT_WRAP_WIDTH)�*create_enable_entitlements_not_found_error�entitlements_disable_order�get_valid_entitlement_names)�ApplicationStatus�CanDisableFailure�CanEnableFailure�CanEnableFailureReason)�notices�state_files)�Notice)�JsonArrayFormatter)�refresh_motd�update_motd_messages)�	safe_dump�	safe_loadz$https://auth.contracts.canonical.com)�tabular�json�yamlzua_logs.tar.gzc���eZdZdddejdfdeef�fd�
Zd�Zd�fd�	Z	e
deeeeeffd��Z
�xZS)	�UAArgumentParserN�	base_descc�:��t�|�||||��||_y)N)�prog�usage�epilog�formatter_class)�super�__init__rA)�selfrCrDrErFrA�	__class__s      ��7/usr/lib/python3/dist-packages/uaclient/cli/__init__.pyrHzUAArgumentParser.__init__Ts,���	������+�		�	
�#���c��|jtj�|dk(rtj}|jd|dz�y)Nz&the following arguments are required: ��
)�print_usage�sys�stderrr�CLI_TRY_HELP�exit)rI�messages  rK�errorzUAArgumentParser.errores<��������$��>�>��+�+�G��	�	�!�W�t�^�$rLc�6��|jr|tj�\}}t|�}|rt||z�}dj	|jg|z�|_|xj
dtjzz
c_t�|�%|��y)NrOz

��file)
rAr@�_get_service_descriptions�sorted�join�descriptionr�PRO_HELP_SERVICE_INFOrG�
print_help)rIrY�show_all�non_beta_services_desc�beta_services_desc�service_descriptionsrJs      �rKr_zUAArgumentParser.print_helpus�����>�>�!�:�:�<�
�&�"�#)�*@�#A� ��'-�(�+=�=�(�$� $�y�y���� �#7�7� �D��
�����)G�)G� G�G��
�����%rL�returnc�R�tj�}d}g}g}tjtj��}|D]�}	t	j
||d��}|jd|d�}|jrdj|j�}nd}tj|j||j|��tdd	d	�
�}	|jr|j!|	���|j!|	���||fS#tj$rY��wxYw)Nz - {name}: {description}{url}�name��cfgrf�presentedAsz ({})�)rfr]�urlz   F)�width�subsequent_indent�break_long_words�break_on_hyphens)r�UAConfigr�get_available_resourcesr�entitlement_factoryr�EntitlementNotFoundError�get�help_doc_url�format�textwrap�fillr]r,�is_beta�append)
rh�service_info_tmplrarb�	resources�resource�ent_cls�presentation_namerk�service_infos
          rKrZz*UAArgumentParser._get_service_descriptions�s*���o�o���;��!#�����4�4�V�_�_�5F�G�	�!�	<�H�
�&�:�:��(�6�"2���!)���]�H�V�<L� M���#�#��n�n�W�%9�%9�:����#�=�=�!�(�(�*� '� 3� 3��)��
'�"'�!&�!&�
�L����"�)�)�,�7�&�-�-�l�;�7	<�:'�(:�;�;��1�6�6�
��
�s�D�D&�%D&)NF)�__name__�
__module__�__qualname__�argparse�
HelpFormatterr�strrHrVr_�staticmethodrrrZ�
__classcell__)rJs@rKr@r@Ssd������ �.�.�#'�
#��C�=�
#�"%� &�&�%<�u�T�#�Y��S�	�-A�'B�%<��%<rLr@c����fd�}|S)z1Decorator asserting exclusive access to lock filec�2���t����fd��}|S)Nc�x��tj|�d��5�|d|i|��}ddd�|S#1swYSxYw)N�)rh�lock_holder�
sleep_timerh)r�	RetryLock)rh�args�kwargs�retval�fr�s    ��rK�new_fz0assert_lock_file.<locals>.wrapper.<locals>.new_f�sJ�������[�Q��
5��D�4�c�4�V�4��
5��M�	
5��M�s�/�9r)r�r�r�s` �rK�wrapperz!assert_lock_file.<locals>.wrapper�s ���	�q��	�
�	��rL�)r�r�s` rK�assert_lock_filer��s���	��NrLc�.��t���fd��}|S)zDecorator asserting root userc�d��tj�stj���|i|��S�N)r�we_are_currently_rootr�NonRootUserError)r�r�r�s  �rKr�zassert_root.<locals>.new_f�s.����)�)�+��-�-�/�/��d�%�f�%�%rLr�r�r�s` rK�assert_rootr��s"����1�X�&��&��LrLc�.��t���fd��}|S)z>Decorator to verify if correct params are used for json formatc���|s�|g|��i|��S|jdk(r |jstj���|g|��i|��S)Nr=)rv�
assume_yesr�CLIJSONFormatRequireAssumeYes)�cmd_argsr�r�r�s   �rKr�z&verify_json_format_args.<locals>.new_f�sS�����X�/��/��/�/��?�?�f�$�X�-@�-@��:�:�<�<��X�/��/��/�/rLrr�s` rK�verify_json_format_argsr��s"����1�X�0��0��LrLc����fd�}|S)z�Decorator asserting attached config.
    :param msg_function: Optional function to generate a custom message
    if raising an UnattachedError
    c�2���t����fd��}|S)Nc���t|�js<�r&t|dd�}t|dd�}�|||��ntj���|fd|i|��S)N�commandrj�service)r��
service_namesrhrh)r$�is_attached�getattrr�UnattachedError)r�rhr�r�r�r��raise_custom_error_functions     ��rKr�z/assert_attached.<locals>.wrapper.<locals>.new_f�se�����$�0�0�.�%�d�I�r�:�G�$+�D�)�R�$@�M�/� '�}�#��%�4�4�6�6��T�-�s�-�f�-�-rLr)r�r�r�s` �rKr�z assert_attached.<locals>.wrapper�s ���	�q��
	.�
�
	.��rLr�)r�r�s` rK�assert_attachedr��s���� �NrLc�.��t���fd��}|S)z&Decorator asserting unattached config.c���t|�jr:tj|jj
j
dd�����|fd|i|��S)Nrfrj)�account_namerh)r$r�r�AlreadyAttachedError�machine_token_file�accountrt)r�rhr�r�s   �rKr�z"assert_not_attached.<locals>.new_f�sW������(�(��1�1� �3�3�;�;�?�?���K��
���)�3�)�&�)�)rLrr�s` rK�assert_not_attachedr��s"����1�X�*��*��LrLc��d|_tj|_|j	ddtj
��|j	ddgdtj��|j	d	d
dtj��|S)
z5Build or extend an arg parser for the api subcommand.�api�
endpoint_path�endpoint)�metavar�helpz--args�options�*)�dest�default�nargsr�z--data�datarj)r�r�r�)rCr�CLI_API_DESCr]�add_argument�CLI_API_ENDPOINT�CLI_API_ARGS�CLI_API_DATA��parsers rK�
api_parserr�s����F�K�!�.�.�F��
�����(�2K�2K�������
���
�
"�
"�������v�r��0E�0E����MrLc���d|_tj|_t	j
t|j��|_tj|j_
|S)z9Build or extend an arg parser for auto-attach subcommand.�auto-attach�rfr�)rCr�CLI_AUTO_ATTACH_DESCr]r(rvr'rD�	CLI_FLAGS�
_optionals�titler�s rK�auto_attach_parserr�sH���F�K�!�6�6�F���$�$�$����D�F�L�&�0�0�F�����MrLc���d|_tj|_t	j
t|j��|_|jddtj��|S)z<Build or extend an arg parser for 'collect-logs' subcommand.�collect-logsr�z-oz--output�r�)
rCr�CLI_COLLECT_LOGS_DESCr]r(rvr'rDr��CLI_COLLECT_LOGS_OUTPUTr�s rK�collect_logs_parserr�#sX�� �F�K�!�7�7�F���$�$�$����D�F�L�
�����
�
-�
-���
�MrL�parent_commandc���tjtdj|���|_d|_t
j|_|jddt
j��|S)z;Build or extend an arg parser for 'config show' subcommand.z
{} show [key]r��show�key�?�r�r�)
r(rvr'rDrCr�CLI_CONFIG_SHOW_DESCr]r��CLI_CONFIG_SHOW_KEY�r�r�s  rK�config_show_parserr�0sd���$�$�
�?�1�1�.�A��F�L��F�K�!�6�6�F��
���
��
�
)�
)���
�MrLc�v�tjtdj|���|_d|_t
j|_t
j|j_
|jdt
jjdjtj�����|S)z:Build or extend an arg parser for 'config set' subcommand.z{} set <key>=<value>r��aset�key_value_pair�, �r�r�)r(rvr'rDrCr�CLI_CONFIG_SET_DESCr]r�r�r�r��CLI_CONFIG_SET_KEY_VALUEr\r�UA_CONFIGURABLE_KEYSr�s  rK�config_set_parserr�?s����$�$�
�1�8�8��H��F�L��F�K�!�5�5�F��&�0�0�F����
�����-�-�4�4��	�	�&�"=�"=�>�
5�
����MrLc�x�tjtdj|���|_d|_t
j|_|jdt
jjdjtj���d��t
j|j_|S)z<Build or extend an arg parser for 'config unset' subcommand.z{} unset <key>r��unsetr�r�r�)r�r�)r(rvr'rDrCr�CLI_CONFIG_UNSET_DESCr]r��CLI_CONFIG_UNSET_KEYr\rr�r�r�r�r�s  rK�config_unset_parserr�Rs����$�$�
�+�2�2�>�B��F�L��F�K�!�7�7�F��
���
��)�)�0�0��	�	�&�"=�"=�>�
1�
����'�0�0�F�����MrLc��d}tjtdj|���|_||_t
j|_t
j|j_
|jt
jdd��}|jdt
j��}|jt �	�t#||�
�|jdt
j$��}|jt&�	�t)||�
�|jdt
j*��}|jt,�	�t/||�
�|S)
z4Build or extend an arg parser for config subcommand.rz{} <command>r�r�rj�r�r�r�r�r���action)r��setr�)r(rvr'rDrCr�CLI_CONFIG_DESCr]r�r�r��add_subparsers�CLI_AVAILABLE_COMMANDS�
add_parserr��set_defaults�action_config_showr�r��action_config_setr�r��action_config_unsetr�)r�r��
subparsers�parser_show�
parser_set�parser_unsets      rK�
config_parserrfs7���G��$�$�
�>�0�0��9��F�L��F�K�!�1�1�F��&�0�0�F�����&�&��-�-�I�r�'��J��'�'��X�2�2�(��K����$6��7��{�7�;��&�&�
�H�0�0�'��J����#4��5��j��9��(�(��h�4�4�)��L����%8��9���W�=��MrLc	�F�tjtd��|_tj
|_d|_tj|_
tj|j_
|jddtj��|jddd	tj �
�|jdt	j"d�tj$�
�|jddddgdtj&jd����|S)z4Build or extend an arg parser for attach subcommand.zattach <token>r��attach�tokenr�r�z--no-auto-enable�store_false�auto_enable)r�r�r�z--attach-config�r)�typer��--format�store�clir=�r��r��choicesr�r�)r(rvr'rDr��RawDescriptionHelpFormatterrFrCr�CLI_ATTACH_DESCr]r�r�r�r��CLI_ATTACH_TOKEN�CLI_ATTACH_NO_AUTO_ENABLE�FileType�CLI_ATTACH_ATTACH_CONFIG�CLI_FORMAT_DESCr�s rK�
attach_parserr�s���$�$�$�8H�I�F�L�%�A�A�F���F�K�!�1�1�F��&�0�0�F����
����s��1J�1J��K�
�����
�
�
/�
/�	������
�
�
�s�
#�
�
.�
.���
���������
�
%�
%�
,�
,�U�
,�
;����MrLc��d|_tj|_tj
|_|jdtjjd��dd��|j�}|jdtjd�	�|jd
tjd�	�|jdtjd�	�|jdtjd�	�|S)
z=Build or extend an arg parser for security-status subcommand.�security-statusr
�textr
)r=r>r)r�rr�z--thirdparty�
store_true)r�r�z
--unavailablez--esm-infraz
--esm-apps)rCr�rrFr�CLI_SS_DESCr]r�rrv�add_mutually_exclusive_group�CLI_SS_THIRDPARTY�CLI_SS_UNAVAILABLE�CLI_SS_ESM_INFRA�CLI_SS_ESM_APPS)r��groups  rK�security_status_parserr#�s���#�F�K�%�A�A�F��!�-�-�F��
����
�
%�
%�
,�
,�V�
,�
<�(��	��
�/�/�1�E�	����
�
'�
'����

����
�
(�
(����

����
�
&�
&����

����
�
%�
%����
�MrLc�2�d|_tjtd��|_t
j|j_tj|_t
j|_
|jdgd�ddt
j��|S)	z5Build or extend an arg parser for refresh subcommand.�refreshz"refresh [contract|config|messages]r��target)rrrr�N)rr�r�r�)rCr(rvr'rDrr�r�r�r�rrF�CLI_REFRESH_DESCr]r��CLI_REFRESH_TARGETr�s rK�refresh_parserr)�s����F�K��$�$�
�?��F�L�'�0�0�F����%�A�A�F��!�2�2�F��
����2���
�
(�
(����MrLc�P�|jdk(r�|jrtj�y|jrtj
�y|jrtj|�y|jrtj|�ytj|�y|jdk(rCttjtj|�dtj���ytt!tj|�d���y)Nrr=T)�	sort_keys�clsF)�default_flow_styler)rv�
thirdpartyr�list_third_party_packages�unavailable�list_unavailable_packages�	esm_infra�list_esm_infra_packages�esm_apps�list_esm_apps_packages�printr=�dumps�security_status_dictr�DatetimeAwareJSONEncoderr:�r�rhr�s   rK�action_security_statusr;�s����{�{�f���?�?��5�5�7�0
�/�
�
��5�5�7�,
�+�^�^��3�3�C�8�(
�'�]�]��2�2�3�7�$
�!
�+�+�C�0� 
�
����	�
��J�J��4�4�S�9���1�1�
�	
�
�
	���4�4�S�9�#(�
�	
�
rLc	�t�tjtd��}||_d|_t
j|_d|j_	|jddt
jjd����|jdd	d
dgd
t
jjd
���
�|S)z4Build or extend an arg parser for detach subcommand.�detachr��Flags�--assume-yesr�r��r�r�r
rrr=r
r)
r(rvr'rDrCr�CLI_DETACH_DESCr]r�r�r��CLI_ASSUME_YESr�r�rDs  rK�
detach_parserrE�s������4��:�E��F�L��F�K�!�1�1�F��%�F����
�����
�
$�
$�
+�
+�H�
+�
=���
���������
�
%�
%�
,�
,�U�
,�
;����MrLrhc�<�tjtd��}||_d|_t
j|_t
j|j_
|jdddt
jjdjtj|����	��
�|jddt t dt
j"jt d�
���|jddt
j$��|S)z2Build or extend an arg parser for help subcommand.zhelp [service]r�r�r�rr�r��rhr��r�r�r�r
rr
r�--allrrA)r(rvr'rDrCr�
CLI_HELP_DESCr]�CLI_ARGS�_positionalsr�r��CLI_HELP_SERVICEr\r�valid_services�STATUS_FORMATSr�CLI_HELP_ALL�r�rhrDs   rK�help_parserrRs������4�1A�B�E��F�L��F�K�!�/�/�F�� (� 1� 1�F����
������
�
&�
&�
-�
-��I�I�l�9�9�c�B�C�.�
�	���������q�!��&�&�-�-�n�Q�6G�-�H��������8�+@�+@����MrLc�F�tjtd��}tj|_||_d|_tj|j_
tj|j_
|jdddtjjdjt!j"|����	��
�|jddtj$jd�
���|jddtj&��|jddtj(��|jddddgdtj*jd����|jddtj,��|S)z4Build or extend an arg parser for enable subcommand.zenable <service> [<service>]r��enabler�r�+r�rGr�rHr?rr@rA�
--access-onlyz--betar
rr=r
r�	--variant)r(rvr'r�CLI_ENABLE_DESCr]rDrCrKrLr�r�r�r��CLI_ENABLE_SERVICEr\rrNrC�CLI_ENABLE_ACCESS_ONLY�CLI_ENABLE_BETAr�CLI_ENABLE_VARIANTrQs   rK�
enable_parserr]0s������
�9�
�E�"�1�1�F���F�L��F�K� (� 1� 1�F����&�0�0�F����
�������'�'�.�.��	�	�,�"=�"=�#�"F�G�
/�
��	������
�
$�
$�
+�
+�H�
+�
=���
�����
�
,�
,���
�����H�,D�,D������������
�
%�
%�
,�
,�U�
,�
;�������G�(�*E�*E����MrLc��tjtd��}tj|_||_d|_tj|j_
tj|j_
|jdddtjjdjt!j"|����	��
�|jddtj$jd�
���|jddddgdtj&jd����|jddtj(��|S)z5Build or extend an arg parser for disable subcommand.zdisable <service> [<service>]r��disabler�rrUr�rGr�rHr?rr@rAr
rr=r
r�--purge)r(rvr'r�CLI_DISABLE_DESCr]rDrCrKrLr�r�r�r��CLI_DISABLE_SERVICEr\rrNrCr�	CLI_PURGErQs   rK�disable_parserrd^sC�����
�:�
�E�"�2�2�F���F�L��F�K� (� 1� 1�F����&�0�0�F����
�������(�(�/�/��	�	�,�"=�"=�#�"F�G�
0�
��	������
�
$�
$�
+�
+�I�
+�
>���
���������
�
%�
%�
,�
,�U�
,�
;��������
�
�
���
�MrLc��tjtd��|_tj
|_d|_tj|j_
|jtjdd��}|jdtj��}|jt �	�t#|�|S)
z4Build or extend an arg parser for system subcommand.zsystem <command>r��systemr�rjr��reboot-requiredr�r�)r(rvr'rDr�CLI_SYSTEM_DESCr]rCr�r�r�r�r�r��CLI_SYSTEM_REBOOT_REQUIREDr��action_system_reboot_required�reboot_required_parser)r�r��parser_reboot_requireds   rK�
system_parserrm�s����$�$�$�8J�K�F�L�!�1�1�F���F�K�&�0�0�F�����&�&��-�-�I�r�'��J�(�2�2��� C� C�3����'�'�/L�'�M��1�2��MrLc��tjtd��|_d|_t
j|_tj|_
|S)Nzsystem reboot-requiredr�rg)r(rvr'rD�pror�rrFr�CLI_SYSTEM_REBOOT_REQUIRED_DESCr]r�s rKrkrk�sD���$�$�
�3��F�L�#�F�J�%�A�A�F��!�A�A�F���MrLc
�*�tjtd��}||_d|_t
j|_tj|_
|jdddtj��|jddttd	tjjtd	�
���|jdd
dtj��|jddtj ��d|j"_|S)z4Build or extend an arg parser for status subcommand.rr�z--waitrF)r�r�r�r
rrr
rz--simulate-with-token�TOKEN)r�r�r�rIrAr>)r(rvr'rDrCr�rrFr�CLI_STATUS_DESCr]r��CLI_STATUS_WAITrOr�CLI_STATUS_SIMULATE_WITH_TOKEN�CLI_STATUS_ALLr�r�rDs  rK�
status_parserrw�s�����4��:�E��F�L��F�K�%�A�A�F��!�1�1�F��
������
�
%�
%�	���������q�!��&�&�-�-�n�Q�6G�-�H���������
�
4�
4�	�������8�+B�+B���&�F�����MrL�cmd_name�subcmd_namec�b�t|��}|j�dj|}|j�djj�}||vrT|j�dj|j	�tjddj|����y)NrGr�	<command>r���argr)�
get_parser�_get_positional_actionsr�keysr_r�InvalidArgChoicer\)rhrxryr��	subparser�
valid_choicess      rK�_print_help_for_subcommandr��s����C�
 �F��.�.�0��3�;�;�H�E�I��5�5�7��:�B�B�G�G�I�M��-�'��&�&�(��+�3�3�H�=�H�H�J��)�)��T�Y�Y�}�%=�
�	
�(rLT)�
update_statusc� �|j}|�|}|j�\}}|s�tj|j�|��t|t�r�|j��tj|jj�tj|jj|jj|j��ntj|j�|rtj|��|S)a=Perform the disable action on a named entitlement.

    :param entitlement_name: the name of the entitlement to enable
    :param cfg: the UAConfig to pass to the entitlement
    :param assume_yes:
        Assume a yes response for any prompts during service enable

    @return: True on success, False otherwise
    ��	error_msg�
error_coder�rG)�enabled_variantr_�event�service_failedrf�
isinstancer1rU�info�msgrV�service_processed�	ua_statusr)�entitlementrhr�r��variant�ret�reasons       rK�_perform_disabler��s����)�)�G������%�%�'�K�C���
���[�-�-�.���*�V�5F�"G��~�~�)��
�
�6�>�>�-�-�.����$�n�n�0�0�%�~�~�2�2�'�,�,���	���� 0� 0�1�����S�!��JrLc�4�t|d|j��y)zGPerform the config action.

    :return: 0 on success, 1 otherwise
    r�rxryr�r�r�r:s   rK�
action_configr�����
��h�D�L�L��
rLc��|jr�|jtjvrMtjdj|j�dj
tj����tdj|jt||jd����ytttjD�cgc]
}t|���c}�dz�}d	|zd
z}tjD])}t|j|t||d�����+|js|jr3|js|jrtt j"�yyycc}w)z�Perform the 'config show' action optionally limit output to a single key

    :return: 0 on success
    :raise UbuntuProError: on invalid keys
    z'{}'r�r|z
{key} {value}N�r��valuerr�z{key: <z	} {value})r�rr�rr�rvr\r6r�r��max�len�global_apt_http_proxy�global_apt_https_proxy�ua_apt_http_proxy�ua_apt_https_proxyr�CLI_CONFIG_GLOBAL_XOR_UA_PROXY)r�rhr��x�	col_width�row_tmplr�s       rKr�r�s:���x�x��8�8�6�6�6�6��-�-��M�M�$�(�(�+��	�	�&�"=�"=�>��
�	��"�"��H�H�G�C����4�$@�
#�
�	
�
��C��)D�)D�E�A��Q��E�F��J�K�I��9�$�{�2�H��*�*�G��
�h�o�o�#�W�S�#�t�-D�o�E�F�G�	�!�!�S�%?�%?�����!7�!7�
�h�5�5�6�"8�&@��
Fs�E>c�0	�ddlm}ddlm}t	|��}|j�djd}|j�djd}	|jjd�\}}	|tjvrD|j�tjd
dj!tj����|d
vr�|jd�d}
|
dk(rt"j$}nt"j&}t#j(|
|	|�||	i}|d i|��t*j,j/|�}|j1�\}
}|
t2j4k(�r�|d i|���n�||j6vr�|jd�d}
|
dk(rt"j8}nt"j:}t#j(|
|	|�t=|j>xs|j@�}|r*tCtDjFjIdd���tK|tLjN||	�d|_d|_ �n�||jP|jRzv�rd|vrdnd}
|
dk(rt"j8}nt"j:}||jPvrMtCtDjTjIdjI|
�djI|
����d|z}t#j(|
|	|�t=|jVxs|jX�}|r*tCtDjFjIdd���tK|tLjZ||	�d|_+d|_,n~|dvr,	t]|	�}	|	dkrtdjI|���nN|dk(rI|	ja�dk(}	|	rtcjd|�ntfjhjk�tm|||	�y#t$r2|j�tjd|j�	��wxYw#t$r3|j�tCd�tj^||	���wxYw)!zMPerform the 'config set' action.

    @return: 0 on success, 1 otherwise
    r)�configure_livepatch_proxy)�configure_snap_proxyrGrr��=z
<key>=<value>)�expected�actual�<key>r�r|��
http_proxy�https_proxy�_rrNzpro scoped aptz
global apt)�
current_proxy�previous_proxyN�https�apt_{}_proxy�global_apt_{}_proxy��old�new�global_)�update_messaging_timer�metering_timerzInvalid interval for {}rjr�r
�truer�)7�uaclient.livepatchr��
uaclient.snapr�r~rrr��split�
ValueErrorr_r�GenericInvalidFormatrr�r�r\r�PROXY_VALIDATION_SNAP_HTTP_URL�PROXY_VALIDATION_SNAP_HTTPS_URL�validate_proxyr�	livepatch�LivepatchEntitlement�application_statusr0�ENABLED�ua_scoped_proxy_options�PROXY_VALIDATION_APT_HTTP_URL�PROXY_VALIDATION_APT_HTTPS_URL�boolr�r�r6r�WARNING_APT_PROXY_OVERWRITErv�configure_apt_proxyr%�UACLIENT�&deprecated_global_scoped_proxy_options�global_scoped_proxy_options�WARNING_CONFIG_FIELD_RENAMEr�r��GLOBAL�int�InvalidPosIntConfigValue�lowerr
�update_apt_newsr5�apt_news_contents_file�delete�setattr)r�rhr�r�r�r�rr��set_key�	set_value�
protocol_type�validate_urlr��livepatch_statusr��
unset_currents                rKr�r�#s;��=�2�
�C�
 �F��2�2�4�Q�7�?�?��I�M��5�5�7��:�B�B�5�I�I�
�!�0�0�6�6�s�;�����f�1�1�1������)�)�����6�+F�+F�!G�
�	
��/�/��
�
�c�*�1�-�
��F�"��>�>�L��?�?�L����M�9�l�C��9�%���&�v�&�"�,�,�A�A�#�F��)�<�<�>���!��0�8�8�8�%�/��/�	�C�/�/�	/��
�
�c�*�1�-�
��F�"��=�=�L��>�>�L����M�9�l�C���%�%�C��)C�)C�
�
����4�4�;�;�"2�<�<��
�
	�C��!7�!7��)�L�$(��!�%)��"�	��2�2�

�
)�
)�	*�
�$+�g�#5��6�
��F�"��=�=�L��>�>�L��c�@�@�@���4�4�;�;�&�-�-�m�<�-�4�4�]�C�<��
� �'�)�G����M�9�l�C��S�2�2�L�c�6L�6L�M�
����4�4�;�;�".�?O�<��
�
	�C��!5�!5�w�	�J� $���!%���	��
�
	��I��I��1�}� �!:�!A�!A�'�!J�K�K��
�J�	��O�O�%��/�	���$�$�S�)��.�.�5�5�7��C��)�$��O�
������-�-�$�T�-@�-@�
�	
�
��r�	�� � �"��"�I��5�5��9��
�		�s�P�*Q�;Q�<Rc���ddlm}ddlm}ddlm}|jtjvr�t|��}|j�djd}|j�djd}|j�tjdd	jtj��
��|jdvrx|jj!d�d}	||	�
�t"j$j'|�}
|
j)�\}}|t*j,k(�r||	�
��n|j|j.vr#t1||j2|jd�n�|j|j4|j6zvr�|j|j4vrxd|jvrdnd}	t8j;t<j>jAdjA|	�djA|	����d|jz|_t1||jB|jd�tE||jd�y)zOPerform the 'config unset' action.

    @return: 0 on success, 1 otherwise
    r)r%)�unconfigure_livepatch_proxy)�unconfigure_snap_proxyrGrr�r�r�r|r�r�)r�Nr�rr�r�r�r�)#�uaclient.aptr%r�r�r�r�r�rr�r~rrr_rr�r\r�rr�r�r�r0r�r�r�r�r�r�r�r�rr�rvr�r�)
r�rhr�r%r�r�r�rr�r�r�r�r�s
             rKr�r��s���+�>�4��x�x�v�2�2�2���$���6�6�8��;�C�C�H�M�
�!�9�9�;�A�>�F�F�w�O�	������)�)�����6�+F�+F�!G�
�	
��x�x�0�0������s�+�A�.�
��]�;�"�,�,�A�A�#�F��)�<�<�>���!��0�8�8�8�'�m�D�	
���S�0�0�	0��C��!7�!7����4�H�	
����2�2�

�
)�
)�	*�
��8�8�s�A�A�A�'.�$�(�(�':�G��M��J�J��4�4�;�;�&�-�-�m�<�-�4�4�]�C�<��
�!�4�8�8�+�D�H��C��!5�!5�t�x�x��F��C����4� �rLc�4�t||��\}}|r9|r7tjdj|�|dj|�d���|r%tjdj|����tj
|dj|�d���)z�Raises a custom error for enable/disable commands when unattached.

    Takes into consideration if the services exist or not, and notify the user
    accordingly.)�namesrhr�rj)�
valid_service�	operation�invalid_service�service_msg)r��r�r�r�)r/r�UnattachedMixedServicesErrorr\�UnattachedValidServicesError�UnattachedInvalidServicesError)r�r�rh�entitlements_found�entitlements_not_founds     rK�&_raise_enable_disable_unattached_errorr��s���
4O���4�0��/��4��5�5��)�)�$6�7�� �I�I�&<�=��	
�	
�
��5�5��)�)�$6�7�
�	
��7�7�� �I�I�&<�=��
�	
rLzpro disablec���|jr#|jrtjdd���t	|dg�}t||�\}}d}|D]S}t
j||��}|||j|j��}	|t|	||j��z}�U|r{d	d
jt
j|d���zdz}
d
jtj|
ddd���}tjdd
j|�|���tj|�}|j!�t"j%�|rdSdS)zbPerform the disable action on a list of entitlements.

    @return: 0 on success, 1 otherwise
    r`r?��option1�option2r�Trg)r��purge�r�zTry r��rh�
allow_beta�.rO�PF)rlrnror_r�rr�)r�r�r�InvalidOptionCombinationr�r/rrrr�r\rNrw�wrap�InvalidServiceOpErrorr�UAContractClient�update_activity_tokenr��process_events)
r�rhr�r�r�r�r��ent_namer~�ent�valid_namesr��contract_clients
             rK�action_disabler	�sb���z�z�d�o�o��1�1��~�
�	
�
�D�)�R�(�E�1L�
�s�2�.��.��C�&�F���2�2�s��J���c�d�o�o�T�Z�Z�H�����S�T�_�_�E�E��	F����i�i��3�3���M�N�
O��
�	�
�i�i��M�M���!&�!&�	
�
���.�.�� �I�I�&<�=�#�
�	
��/�/��4�O��)�)�+�	�����1���rLz
pro enablec�>�t|dd�}|j}|r|rtjdd���tjtj�	tj|�t|d
g�}t||�\}}d}|D�]L}		t!j"||	|j$|j&|||j)d���\}
}t+j,|�
�|
s�|��t/|t0�r�|j2�itj|j2j4�tj7|j2j4|j2j8|	��|j:t<j>k(rE|jA|	�n3|
rtjC|	��n|
s|�tjE|	��||
z}��O|r-tjI|�tK|||j&���tjL|�}
|
jO�tjQ�|rdSdS#tjtjf$r?tjdd��tjtj�	�Y��?wxYw#tj$rX}tj|j4�tj7|j4|jF|	��d}Yd}~���d}~wwxYw)z^Perform the enable action on a named entitlement.

    @return: 0 on success, 1 otherwise
    r�rjrVrWr�zFailed to refresh contractT��exc_info)�warning_msgr��
extra_args)r�r��access_onlyr�rrGNr�)r�Fr�rr�))r�rrr�r�r�r�REFRESH_CONTRACT_ENABLErr%�ConnectivityError�UbuntuProError�LOG�warning�E_REFRESH_CONTRACT_FAILUREr/r�enable_entitlement_by_namer��betartr�rr�r2rUr�rVrfr�r3�IS_BETArzr�r��msg_code�services_failedr-rrr)r�rhr�r�rr�r�r�r�r�ent_retr��ers              rK�
action_enablers����d�I�r�*�G��"�"�K��;��1�1�#�[�
�	
�
�J�J�x�/�/�0�G������
�D�)�R�(�E�1L�
�s�2�.��.��C�&�(��'	�%�@�@����?�?��9�9�'��!�:�:�l�3��O�G�V�
����%���&��v�'7�8��>�>�-��J�J�v�~�~�1�1�2��K�K�"(�.�.�"4�"4�#)�>�>�#6�#6� (� ��
�=�=�$:�$B�$B�B�+�1�1�(�;���'�'��'�9�����$�$�X�$�6��7�N�C�E(�T�
���4�5�8�"���	�	�
�	
��/�/��4�O��)�)�+�	�����1�����}
�(�(�*�*C�*C�D�G����0�4��@�
�
�
�(�"E�"E�
�F�G��Z�(�(�	��J�J�q�u�u���K�K��%�%�A�J�J��
�
��C��	�s-�I�EJ1�AJ.�-J.�1L�A
L�Lz
pro detachrdc��t||j��}|dk(r(tj�t	j
�tj�|S)zXPerform the detach action for this machine.

    @return: 0 on success, 1 otherwise
    r�r)�_detachr�r
�startr�stopr�r)r�rhr�r�s    rK�
action_detachr"os>���#�$�/�/�
2�C�
�a�x�����
�
�
��	�����JrLr�c���g}t|�D]M}	tj||��}|||��}|jd��\}}|s�=|j
|��O|rptjtjjt|���|D]0}tjdj|j���2tj |��sy|D]}t#|||d�	��|j%�|j&j)�t+|�tjtj,�y
#tj$rY��^wxYw)a7Detach the machine from the active Ubuntu Pro subscription,

    :param cfg: a ``config.UAConfig`` instance
    :param assume_yes: Assume a yes answer to any prompts requested.
         In this case, it means automatically disable any service during
         detach.

    @return: 0 on success, 1 otherwise
    rg)rhr�T)�ignore_dependent_servicesz    {}r�r�F)r�r�r)r.rrrrrs�can_disablerzr�r�r�DETACH_WILL_DISABLE�	pluralizer�rvrfr�prompt_for_confirmationr��delete_cacher�r�r9�DETACH_SUCCESS)rhr��
to_disablerr~rr�r�s        rKrr�s>���J�.�s�3�#��	�"�6�6�3�X�N�G��#�*�5�����4��@���Q�����c�"�#��
�
�
�8�/�/�9�9�#�j�/�J�K��	2�C��J�J�x���s�x�x�0�1�	2��'�'�:�>���O����c�j��N�O��������!�!�#����	�J�J�x�&�&�'���1�2�2�	��	�s�E�E-�,E-c�l�d}|jr;|jjdi�jdi�jd�}|r4tjtj
j
|���n#tjtj�tj�tj|�tj|�\}}tj|�}tjtj |��tj#�y)N�machineTokenInfo�contractInforf)�
contract_name)�
machine_tokenrtr�r�r�ATTACH_SUCCESS_TMPLrv�ATTACH_SUCCESS_NO_CONTRACT_NAMEr
r!�cleanuprrr��format_tabularr�handle_unicode_charactersr)rhr/r�_ret�outputs     rK�_post_cli_attachr8�s����M�
������!�!�"4�b�9�
�S���
$�
�S��[�	��
�
�
��(�(�/�/�m�/�L�	
�	�
�
�8�;�;�<�
�K�K�M�
�N�N�3���>�>�#�&�L�F�D�
�
%�
%�f�
-�F�	�J�J�t�-�-�f�5�6�	���rLc�
�|jr |jrtj��t	|j
|j|j|�}t
|j��|jdk(rdSdS)N�successrr�)	r�r�r�CLIAPIOptionsXORDatarr�r6�to_json�result�r�rhr�r=s    rK�
action_apir?�sa���|�|��	�	��-�-�/�/�
�d�(�(�$�,�,��	�	�3�
G�F�	�&�.�.�
���
�
��*�1�1��1rLc��	tt�|tjj��t|�y#tj$r0tjtjj�YywxYw)N)rh�moderr�)
rrr�EventLoggerMode�CLIr8rrr�r�r�E_ATTACH_FAILUREr�r:s   rK�action_auto_attachrE�sf����!�#���-�-�1�1�	
�	������'�'��
�
�
�8�,�,�0�0�1���s�.<�AA?�>A?c��|jdk(r!tjd|j���tj	t
j�t|��}tj	dt
jj|j��z�t|j��}	t||��}tj	dt
j"z�|j$S#tj$rM}tj	t
j�t|j��}t!||��|�d}~wwxYw)	Nr=r
)�paramr�rGrO)�	user_code)�magic_token)r�rh)rvr�MagicAttachInvalidParamr�r�r�CLI_MAGIC_ATTACH_INITr�CLI_MAGIC_ATTACH_SIGN_INrHr!rr"�MagicAttachTokenError�CLI_MAGIC_ATTACH_FAILEDrr �CLI_MAGIC_ATTACH_PROCESSING�contract_token)r�rhr��
initiate_resp�wait_options�	wait_respr�revoke_optionss        rK�
_magic_attachrU�s���{�{�f���0�0���+�+�
�	
�

�J�J�x�-�-�.��#�&�M�	�J�J��
�
+�
+�
2�
2�#�-�-�3�
�	
��*�m�6I�6I�J�L�	��,�C�8�	�
�J�J�t�h�:�:�:�;��#�#�#���+�+��
�
�
�8�3�3�4�1�%�+�+�
��	��C�0�����s�7
C6�6E�	AE�Ez
pro attachc��|jr |jrtj��|js|jst	||��}d}n\|jr|j}d}nA	tjt|j��}|j}|j}|jxr|du}	tj|||��d}|��O|j�rBt!||�\}	}
|	D]�}tj"||dd��\}}
|s�d}|
��&t%|
t&�s�7|
j(��Dt*j-|
j(j�t*j/|
j(j|
j(j|����t*j1|���|
rjt3|
|d�	�}t*j-|jt4j6�
�t*j/|j|j8��d}t;j<|�}|j?�tA|�|S#t$r:}tj|jj|j���d}~wwxYw#tjB$rtjD��wxYw)NrG)�config_namerV)r�allow_enablerT)r�r�r�r�r���	file_type�r�r�)#r�
attach_configr�CLIAttachTokenArgXORConfigrUr*�	from_dictr;r+�AttachInvalidConfigFileErrorrfr��enable_servicesrr�attach_with_tokenr/rr�r2rUr�r�rVr�r-rQrRrrrrr8r�AttachError)r�rhr�r�enable_services_overrider\rrXr��found�	not_foundrfrr�rVrs                rK�
action_attachrf�sh���z�z�d�(�(��3�3�5�5�
�Z�Z�� 2� 2��d��,��#'� �	
����
�
��#'� �	�3�=�=��$�,�,�-��M��#�#��#0�#@�#@� ��#�#�H�(@�D�(H�L�*��!�!�#�U��N���#�/�D�4D�4D�:�(�#� ��E�9��
2��")�"D�"D���$�4�#������C��*�&�v�/?�@�"�N�N�6��
�
�6�>�>�#5�#5�6����&,�n�n�&8�&8�'-�~�~�':�':�$(�$���+�+�D�1�%
2�(�B��3�4����
�
�5�9�9��
�
�
�;����e�i�i�E�N�N��K���"�3�3�C�8���-�-�/�����
��i"�	��9�9� �.�.�3�3�1�5�5��
��	���'�'�'��$�$�&�&�'�s$�1(I"�J(�"	J%�+5J � J%�((Kc��|jxst}tj�5}t	j
||�	t
j|d�5}|j|d��ddd�ddd�y#1swY�xYw#t$r'}tj|�Yd}~ddd�yd}~wwxYw#1swYyxYw)Nzw:gzzlogs/)�arcnamer�r)r7�UA_COLLECT_LOGS_FILE�tempfile�TemporaryDirectoryr�collect_logs�tarfile�open�add�PermissionErrorrrV)r�rhr��output_file�
output_dir�resultsrs       rK�action_collect_logsrtEs����+�+�5�!5�K�	�	$�	$�	&��*����S�*�-�	����k�6�2�
9�g����J���8�
9��
�
9�
9���	��I�I�a�L�����
	���
�sG�B;�B�A<�+B�<B	�B�	B8�B3�&B;�3B8�8B;�;Cc	�	�t}tttjtjtd��tjj
td��|��}|jddtj��|jddtj�tjj
t�	��
�tj|j_|j#tj$dd�
�}d|_|j)dtj*��}t-|�|j/t0��|j)dtj2��}t5|�|j/t6��|j)dtj8��}t;|�|j/t<��|j)dtj>��}tA|�|j/tB��|j)dtjD��}tG|�|j/tH��|j)dtjJ��}	tM|	�|	j/tN��|j)dtjP��}
tS|
|��|
j/tT��|j)dtjV��}tY||��|j/tZ��t]|�|j)dtj^��}ta|�|j/tb��|j)dtjd��}
tg|
|��|
j/th��|j)dtjj��}|j/tl��to|�|j)dtjp��}|j/tr��tu|�|j)dtjj
t�	���}|j/tv��|j)dtjx��}|j/tz��t}|�|S)Nr{r�)rCrFrDrErAz--debugrrAz	--versionr)rf)r�rr�r�rjr�Trr�r�r�r�r�rr=r_rGrTrr�r%rrf)?�__doc__r@r'r�rr(rvr�CLI_HELP_EPILOGr��CLI_ROOT_DEBUGr�get_version�CLI_ROOT_VERSIONr�r�r�r�r��requiredr��CLI_ROOT_ATTACHrr�rf�CLI_ROOT_APIr�r?�CLI_ROOT_AUTO_ATTACHr�rE�CLI_ROOT_COLLECT_LOGSr�rt�CLI_ROOT_CONFIGrr��CLI_ROOT_DETACHrEr"�CLI_ROOT_DISABLErdr	�CLI_ROOT_ENABLEr]rr)�CLI_ROOT_SECURITY_STATUSr#r;�
CLI_ROOT_HELPrR�action_help�CLI_ROOT_REFRESH�action_refreshr)�CLI_ROOT_STATUS�
action_statusrw�
print_version�CLI_ROOT_SYSTEM�
action_systemrm)rhrAr�r��
parser_attach�
parser_api�parser_auto_attach�parser_collect_logs�
parser_config�
parser_detach�parser_disable�
parser_enable�parser_security_status�parser_help�parser_refresh�
parser_status�parser_version�
parser_systems                  rKr~r~Rs9���I�
�
� �<�<����T�;�?��'�'�.�.�D�+�.�N���F�����,�X�-D�-D���������#�#�%�
�
&�
&�
-�
-�4�
-�
8�	��'�0�0�F�����&�&��-�-�I�r�'��J��J���)�)��x�/�/�*��M��-� ����m��4��&�&�u�8�3H�3H�&�I�J��z�����:��.�#�.�.��H�9�9�/����)�*��#�#�+=�#�>�$�/�/��X�;�;�0����+�,��$�$�,?�$�@��)�)��x�/�/�*��M��-� ����m��4��)�)��x�/�/�*��M��-� ����m��4��*�*���1�1�+��N��>�s�+����~��6��)�)��x�/�/�*��M��-�S�)����m��4��:��'�2�2��� A� A�3����1�2��'�'�/E�'�F��'�'��X�5K�5K�'�L�K����%����K��0��*�*���1�1�+��N����~��6��>�"��)�)��x�/�/�*��M����m��4��-� ��*�*���1�1�8�8�d�8�C�+��N����}��5��)�)��x�/�/�*��M����m��4��-� ��MrLc���|stj�}|r|jnd}|r|jnd}tj
jj}tj|||��\}}t|d|k(�}|r{|jro|rm|d|k(rPtjdd��tjd�tj|||��\}}|d|k(r�Ptjd�tj!|�t	j"||��}	tjt%j&|	��tj)�|S)	NF)�simulate_with_tokenr`�execution_statusr�rj)�endr��r`)rrp�allr�r��UserFacingConfigStatus�ACTIVEr�rrr��waitr�r��time�sleep�set_output_contentr4rr5r)
r�rhr�r`r�active_valuerr��
config_activer7s
          rKr�r��s(����o�o����t�x�x�U�H�(,�D�$�$�$�E��3�3�:�:�@�@�L��.�.�����K�F�C��� 2�3�|�C�D�M���	�	�m��'�(�L�8��J�J�s��J�#��J�J�q�M�!�.�.��$)�!��K�F�C��'�(�L�8�	�
�
�2��	���V�$�
�
%�
%�f�x�
@�F�	�J�J�t�-�-�f�5�6�	�����JrLc�4�t|d|j��y)zGPerform the system action.

    :return: 0 on success, 1 otherwise
    rfr�rr�r:s   rKr�r��r�rLc�X�t|�}tj|j�y)Nr)r#r�r��reboot_requiredr>s    rKrjrj�s!��
�c�
"�F�	�J�J�v�%�%�&�rLc�>�ttj��yr�)r6rry)�_argsrhr�s   rKr�r��s��	�'�
�
�
� rLc���	|j�t
tj�y#t$r.}tj|�t	j
��d}~wwxYwr�)	�process_config�RuntimeErrorr�	exceptionr�RefreshConfigFailurer6r�REFRESH_CONFIG_SUCCESS)r�rh�excs   rK�_action_refresh_configr��sP��0�����
�(�
)�
)�*���0��
�
�c���-�-�/�/��0�s�,�	A#�)A�A#c��	tj|�ttj�y#tj$rtj��wxYwr�)rr%rr�RefreshContractFailurer6r�REFRESH_CONTRACT_SUCCESS)r�rhs  rK�_action_refresh_contractr��sK��2������
�(�
+�
+�,���'�'�2��/�/�1�1�2�s	�1�(Ac��	t|�t�|jrtj|�t	t
j�y#t$r.}tj|�tj��d}~wwxYwr�)r9r8r
r�r6r�REFRESH_MESSAGES_SUCCESS�	Exceptionrr�r�RefreshMessagesFailure)r�rhr�s   rK�_action_refresh_messagesr�sf��	1��S�!����<�<��$�$�S�)�
	�h�/�/�0��	�2��
�
�c���/�/�1�1��2�s�6A�	B	�)B�B	zpro refreshc�4�|j�|jdk(rt||�|j�|jdk(r/t||�tjt
j�|j�|jdk(rt||�y)Nrrrr)r&r�r�r4�remover6�CONTRACT_REFRESH_WARNINGr�r:s   rKr�r�sv���{�{��d�k�k�X�5��t�S�)��{�{��d�k�k�Z�7� ��s�+����v�6�6�7��{�{��d�k�k�Z�7� ��s�+�rL�scoper�r�c���|tjk(r|j}|j}n+|tjk(r|j
}|j}d|vr|}n|}t|��y)zS
    Handles setting part the apt proxies - global and uaclient scoped proxies
    r�)r�r��proxy_scopeN)r%r�r�r�r�r�r�r&)rhr�r�r�r�r�s      rKr�r�!sm��
�
�$�$�$��.�.�
��0�0��	�-�(�(�	(��*�*�
��,�,���'�����
���;�E�rLc��|j}|j}|st|��j|��y|st	j
�}t
j||�}|jdk(rttj|��y|j�D].\}}tdj|j�|���0y)NrGr�rr=z{}:
{}
)r�r�r~r_rrpr�r�rvr6r=r7�itemsr�)r�rhr�r�r`�
help_responser�r�s        rKr�r�9s����l�l�G��x�x�H���s��&�&��&�9����o�o����N�N�3��0�M��{�{�f��
�d�j�j��'�(�

�(�-�-�/�	:�J�C���+�$�$�S�Y�Y�[�%�8�9�	:�
rLc�&�|r|jdk(st|dd�dvrytj�}|rZtjd|�tjtjj|��tj��yy)Nr�rvrj�r=r>zNew version available: %s)rrY)
r�r�r�check_for_new_versionrrr�r�r�WARN_NEW_VERSION_AVAILABLE_CLIrvrQrR)r��new_versions  rK�_warn_about_new_versionr�Os���
	�����%��8�X�r�*�.>�>���/�/�1�K�����/��=�
�
�
��3�3�:�:�#�
;�
��j�j�		�	
�rLc�Z�|jdvr�tjj�s~t	|d�r|j
dvrytjd�tjtjj|j��tj��yyy)z4Warn users that the user readable output may change.)rrrvr�Nz.Not in a tty and human-readable command calledr@rY)
r�rQ�stdout�isatty�hasattrrvrrr�r�r�WARNING_HUMAN_READABLE_OUTPUTrR�r�s rK�_warn_about_output_redirectionr�es���	���9�9��
�
�!�!�#��8�X�&�8�?�?�>N�+N�����D�E�
�
�
��2�2�9�9� �(�(�
:�
��j�j�		�	
�$�	:rLc���|� tj�}|j}tj�stj�}t|t�r|j�}|stjd�}|j|�g|_
tj|�}|j!�s/|j"j%dd��|j'd��tj(|�}|j+t-��|j|�|j/d�|j1tj2��|j5|�y)z�Setup console logging and debug logging to log_file

    It configures the pro client logger.
    If run as non_root and cfg.log_file is provided, it is replaced
    with another non-root log file.
    N�	ubuntuproT)�parents�exist_oki�)rAz	upro-file)rrp�log_filerr��pro_log�get_user_log_filer�r��upper�logging�	getLogger�setLevel�handlers�pathlib�Path�exists�parent�mkdir�touch�FileHandler�setFormatterr7�set_name�	addFilter�RedactionFilter�
addHandler)�	log_levelr��loggerrh�
log_file_path�file_handlers      rK�
setup_loggingr�vs �����o�o����<�<���%�%�'��,�,�.���)�S�!��O�O�%�	���"�"�;�/��
�O�O�I���F�O��L�L��*�M����!����"�"�4�$�"�?������'��&�&�x�0�L����0�2�3����)�$����+�&����7�2�2�4�5�
���l�#rLc�l�|jdvr�tj|j�t|d�rz|jdk(r-tjtjj�|jdk(r.tjtjj�yyyy)z3Set the right event mode based on the args provided)rr=rTr_rrvr=r>N)
r�r��set_commandr�rv�set_event_moderrB�JSON�YAMLr�s rKr�r��s������N�N�
���(�*�*�+��8�X�&����&�(��$�$�\�%A�%A�%F�%F�G����&�(��$�$�\�%A�%A�%F�%F�G�)�'�OrLc����fd�}|S)Nc
�
��	�|i|��S#t$rjtjd�ttj
tj��tj�t
jd�Yytj$�r�}dt|�vr�tj}tj d�rtj"}|j%|j&��}t(j|j*|j,��t(j/|j*tj��n�tj1d	|j&|�
�tj2j%|j&|j4��}t(j|j*|j,��t(j/|j*tj��tj�t(j7�t9�t
jd�Yd}~yd}~wtj:$r�}tj}tj d�rtj"}|j%|j&��}t(j|j*|j,��t(j/|j*tj��tj�t(j7�t9�t
jd�Yd}~yd}~wtj<$�r}tj|j*�t(j|j*|j>|j@��t(j/d
j%|j*�tj��tC|tjD�stj�t(j7�t9�t
j|jF�Yd}~yd}~wtH$r�}tj1d�tj�t(j/tjJj*tj��t(jtM|dt|��d��t(j7�t9�t
jd�Yd}~yd}~wwxYw)N�KeyboardInterruptrXr��CERTIFICATE_VERIFY_FAILEDzca-certificates)rkr[)�info_msgrZzFailed to access URL: %sr)rk�cause_error)r�r��additional_infoz{}z&Unhandled exception, please file a bugr�r�)r��
error_type)'r�rrVr6r�CLI_INTERRUPT_RECEIVEDrQrRr�clear_lock_file_if_presentrTrrr��&SSL_VERIFICATION_ERROR_CA_CERTIFICATESr	�is_installed�%SSL_VERIFICATION_ERROR_OPENSSL_CONFIGrvrkr�r�rfr�r��E_CONNECTIVITY_ERRORr�rr��PycurlCACertificatesErrorrrr�r��
LockHeldError�	exit_coder��UNEXPECTED_ERRORr�)r�r�r��tmplr�r�funcs      �rKr�z#main_error_handler.<locals>.wrapper�sd���L	���(��(�(�� �	��I�I�)�*��(�1�1��
�
�C��+�+�-��H�H�Q�K��+�+�	�*�c�#�h�6��F�F���#�#�$5�6�#�I�I�D��k�k�c�g�g�k�.�����c�g�g�#�(�(��C��
�
�C�G�G�s�z�z�
�B��
�
�.����#����3�3�:�:���� #���;������c�g�g�#�(�(��C��
�
�C�G�G�s�z�z�
�B��+�+�-�� � �"�#�%��H�H�Q�K�K���3�3�
	��B�B�D���� 1�2��E�E���+�+�#�'�'�+�*�C��K�K�#�'�'�c�h�h�K�?��J�J����3�:�:�J�>��+�+�-�� � �"�#�%��H�H�Q�K�K���(�(�	$��I�I�c�g�g���K�K��'�'��<�<� #� 3� 3�
�
�

�J�J����C�G�G� 4��
�
�J�K��c�:�#;�#;�<��/�/�1�� � �"�#�%��H�H�S�]�]�#�#���
	��M�M�B�C��+�+�-��J�J�!�2�2�6�6�#�*�*�
�
�
�K�K�!�!�U�C��F�3��
�
�
� � �"�#�%��H�H�Q�K�K��
	�sD��A0U�=U�F1I�U�C2M�U�*C>Q-�-U�9CU�Ur�)rr�s` rK�main_error_handlerr�s���M�^�NrLc���ttjdtjd�tj�}t|j
|j�|stj}t|��}|dd}|s>|j�ttj�tjd�d|vr|jd�}|d|}||dzd}n|}g}|j!|��}|j"rft%j&tj(�}|j+t$j,�t%j.d�j1|�t3|�|j4}	|j6}
t9j:|	|
��t<j#d	|z�|j?�tAtCjD�jG��D��cgc]\}}d
jI||���}
}}|
rt<j#d|
z�tK|�|jM|||��}tO|�|Scc}}w)
Nr�r�rGr�z--)r�r�r�zExecuted with sys.argv: %rz{}={}z'Executed with environment variables: %r)rhr)(r�r�CONFIG_DEFAULTSrrpr�r�rQ�argvr~rPr6rrSrT�index�
parse_args�debugr��
StreamHandlerrRr��DEBUGr�r�r�r�r�r�configure_web_proxyr�warn_about_invalid_keysr[r�get_pro_environmentr�rvr�r�r�)�sys_argvrhr��
cli_arguments�double_dash_index�pro_cli_argsrr��console_handlerr�r��k�v�pro_environment�return_values               rK�mainr!�s���� � ��-�� � ��,���/�/�
�C��#�-�-����.���8�8��
�C�
 �F��Q�R�L�M������
�h�#�#�$�������}��)�/�/��5��$�%7�&7�8��"�#4�q�#8�#:�;�
�$���
����,��/�D��z�z�!�/�/��
�
�;��� � ����/����+�&�1�1�/�B��4�����J��/�/�K����
��L��I�I�*�X�5�6����!��4�3�3�5�;�;�=�>���A�q�	���q�!���O����	�	�;�o�M�N�"�4�(��;�;�t���;�D�L��D�!����s�I&�__main__r�)NN)rdN)�rvr�r=r�r�rQrmrjrwr��	functoolsr�typingrrr�uaclientrr	r
rrr
rrrrrrrr�rrrr�rrr�uaclient.api.apir�2uaclient.api.u.pro.attach.auto.full_auto_attach.v1rr�+uaclient.api.u.pro.attach.magic.initiate.v1r�)uaclient.api.u.pro.attach.magic.revoke.v1rr �'uaclient.api.u.pro.attach.magic.wait.v1r!r"�5uaclient.api.u.pro.security.status.reboot_required.v1r#�(uaclient.api.u.pro.status.is_attached.v1r$r�r%r&�uaclient.cli.constantsr'r(�uaclient.cli.fixr)�uaclient.data_typesr*r+�uaclient.defaultsr,�uaclient.entitlementsr-r.r/�(uaclient.entitlements.entitlement_statusr0r1r2r3�uaclient.filesr4r5�uaclient.files.noticesr6�uaclient.logr7�uaclient.timer.update_messagingr8r9�
uaclient.yamlr:r;�UA_AUTH_TOKEN_URLrOri�get_event_loggerr�r��replace_top_level_logger_namer�r�ArgumentParserr@r�r�r�r�r�r�r�r�r�r�r�r�rrr#r)r;rErprRr]rdrmrkrwr�r�r�r�r�r�r�r	rr�r"r�rr8r?rErUrfrtr~r�r�rjr�r�r�r�r�r�r�r�r�r�r�rr!rTr�rLrK�<module>r<s���8�����
������(�(�
�
�
�
�$�.�(�)�)�%��B����B�7�3�+�K�.���
��0�)�+�N�.�:��,��'��%��%�%�'���g���:��:�:�8�D�E��[<�x�.�.�[<�|�"
�
� �2��(�
��s���c��&���(�@�:#�L�(
�<�,�V�_�_��>+�v���+�\%����%�P�$� �F

�	���

�$'�

�69�

�EI�#�L
�7�>
�t%�
�t%�n
�+
�
�+
�\
�6���7�8��-� �.�!�9�
��.�b���7�8��,��N� �9�
��N�b�����,��
�S�
� ��
��
�&
����&
�d�&
�s�&
�R�&�/�/��d��42�
��V�_�_��3��
��$�B���,��B� �
��B�J

�f�o�o�

�h�F�O�O�h�V�����:
�
����
�!�+�f�o�o�+���-����-��-�
1����
1� 
��-� �
����
�!�
�
��	����������}�	�

��0
�,
�,
�""$�JH�P�f�8��8�v�z���C�H�H�T�V��rL

Youez - 2016 - github.com/yon3zu
LinuXploit