%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/uaclient/cli/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/uaclient/cli/__pycache__/__init__.cpython-312.pyc

�

�Hcf���
�<�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$m%Z%ddl&m'Z'ddl(m)Z)m*Z*ddl+m,Z,m-Z-dd	l.m/Z/dd
l0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8ddl9m:Z:m;Z;dd
l<m=Z=m>Z>ddl?m@Z@ddlAmBZBmCZCmDZDddlEmFZFmGZGmHZHddlImJZJmKZKddlLmMZMddlNmOZOddlPmQZQmRZRddlSmTZTmUZUdZVgd�ZWdZXej��ZZej�e!j�e]��Z^Gd�dej��Z`d�Zad�Zbdecfd�Zddecfd�Zedecfd �Zfd!�Zgd"�Zhd#�Zid$�Zjd%�Zkd&�Zld'ej�fd(�Znd)�Zod*�Zpd+�Zqd'ej�d,ecd-ecfd.�Zrd/d0�d1�Zsd2�Ztd3�Zue5j�d4��Zwe5j�d5��Zxe5j�e5j�e5j��e5j�d6�d7e|fd8�����Z}d'ej�d9e~d:e~d7e|fd;�Zd'ej�d7dfd<�Z�e5j�d'ej�d7e|fd=��Z�d>�Z�e5�je5j�e5j�d?�d@����Z�d'ej�fdA�Z�d'ej�fdB�Z�d'ej�fdC�Z�dD�Z�d'ej�fdE�Z�dWdF�Z�d'ej�fdG�Z�e5j��d'ej�fdH��Z�d'ej�fdI�Z�e5j�e5j�dJ�d'ej�fdK���Z�d'ej�dLe1dMecdNeecd7df
dO�Z�dP�Z�dXdYdQ�Z�dYdR�Z�dS�Z�dT�Z�e�dXdU��Z�e]dVk(re�j,e���yy)Zz2Client to manage Ubuntu Pro services on a machine.�N)�List�Optional�Tuple)�actions�api�apt�apt_news�config�contract�daemon�defaults�entitlements�event_logger�
exceptions�http�lock�log�messages�secret_manager�security_status�status�timer�util�version)�FullAutoAttachOptions�_full_auto_attach)�	_initiate)�MagicAttachRevokeOptions�_revoke)�MagicAttachWaitOptions�_wait)�_reboot_required)�
AptProxyScope�setup_apt_proxy)�cli_api�cli_util�disable�enable�fix)�NAME�
USAGE_TMPL)�AttachActionsConfigFile�IncorrectTypeError)�PRINT_WRAP_WIDTH)�*create_enable_entitlements_not_found_error�entitlements_disable_order�get_valid_entitlement_names)�ApplicationStatus�CanDisableFailure�CanEnableFailure)�notices�state_files)�Notice)�get_user_or_root_log_file_path)�refresh_motd�update_motd_messages)�	safe_dump�	safe_loadz$https://auth.contracts.canonical.com)�tabular�json�yamlzpro_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__rB)�selfrDrErFrGrB�	__class__s      ��7/usr/lib/python3/dist-packages/uaclient/cli/__init__.pyrIzUAArgumentParser.__init__Ts,���	������+�		�	
�#���c��|jtj�|dk(rtj}|jd|dz�y)Nz&the following arguments are required: ��
)�print_usage�sys�stderrr�CLI_TRY_HELP�exit)rJ�messages  rL�errorzUAArgumentParser.errores<��������$��>�>��+�+�G��	�	�!�W�t�^�$rMc�6��|jr|tj�\}}t|�}|rt||z�}dj	|jg|z�|_|xj
dtjzz
c_t�|�%|��y)NrPz

��file)
rBrA�_get_service_descriptions�sorted�join�descriptionr�PRO_HELP_SERVICE_INFOrH�
print_help)rJrZ�show_all�non_beta_services_desc�beta_services_desc�service_descriptionsrKs      �rLr`zUAArgumentParser.print_helpus�����>�>�!�:�:�<�
�&�"�#)�*@�#A� ��'-�(�+=�=�(�$� $�y�y���� �#7�7� �D��
�����)G�)G� G�G��
�����%rM�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��cfgrg�presentedAsz ({})�)rgr^�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)
ri�service_info_tmplrbrc�	resources�resource�ent_cls�presentation_namerl�service_infos
          rLr[z*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�strrIrWr`�staticmethodrrr[�
__classcell__)rKs@rLrArASsd������ �.�.�#'�
#��C�=�
#�"%� &�&�%<�u�T�#�Y��S�	�-A�'B�%<��%<rMrAc���d|_tj|_t	j
t|j��|_tj|j_
|S)z9Build or extend an arg parser for auto-attach subcommand.�auto-attach�rg�command)rDr�CLI_AUTO_ATTACH_DESCr^r+rwr*rE�	CLI_FLAGS�
_optionals�title��parsers rL�auto_attach_parserr��sH���F�K�!�6�6�F���$�$�$����D�F�L�&�0�0�F�����MrMc���d|_tj|_t	j
t|j��|_|jddtj��|S)z<Build or extend an arg parser for 'collect-logs' subcommand.�collect-logsr�z-oz--output��help)
rDr�CLI_COLLECT_LOGS_DESCr^r+rwr*rE�add_argument�CLI_COLLECT_LOGS_OUTPUTr�s rL�collect_logs_parserr��sX�� �F�K�!�7�7�F���$�$�$����D�F�L�
�����
�
-�
-���
�MrM�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�?��nargsr�)
r+rwr*rErDr�CLI_CONFIG_SHOW_DESCr^r��CLI_CONFIG_SHOW_KEY�r�r�s  rL�config_show_parserr��sd���$�$�
�?�1�1�.�A��F�L��F�K�!�6�6�F��
���
��
�
)�
)���
�MrMc�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�, ��optionsr�)r+rwr*rErDr�CLI_CONFIG_SET_DESCr^r�r�r�r��CLI_CONFIG_SET_KEY_VALUEr]r
�UA_CONFIGURABLE_KEYSr�s  rL�config_set_parserr��s����$�$�
�1�8�8��H��F�L��F�K�!�5�5�F��&�0�0�F����
�����-�-�4�4��	�	�&�"=�"=�>�
5�
����MrMc�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��metavar)r+rwr*rErDr�CLI_CONFIG_UNSET_DESCr^r��CLI_CONFIG_UNSET_KEYr]r
r�r�r�r�r�s  rL�config_unset_parserr��s����$�$�
�+�2�2�>�B��F�L��F�K�!�7�7�F��
���
��)�)�0�0��	�	�&�"=�"=�>�
1�
����'�0�0�F�����MrMc��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.r
z{} <command>r�r�rk�r��destr�r�r���action)r��setr�)r+rwr*rErDr�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      rL�
config_parserr��s7���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�=��MrMc	�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>��default�r��choicesr�r�)r+rwr*rEr��RawDescriptionHelpFormatterrGrDr�CLI_ATTACH_DESCr^r�r�r�r��CLI_ATTACH_TOKEN�CLI_ATTACH_NO_AUTO_ENABLE�FileType�CLI_ATTACH_ATTACH_CONFIG�CLI_FORMAT_DESCr�s rL�
attach_parserr�s���$�$�$�8H�I�F�L�%�A�A�F���F�K�!�1�1�F��&�0�0�F����
����s��1J�1J��K�
�����
�
�
/�
/�	������
�
�
�s�
#�
�
.�
.���
���������
�
%�
%�
,�
,�U�
,�
;����MrMc��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�r�r�z--thirdparty�
store_true)r�r�z
--unavailablez--esm-infraz
--esm-apps)rDr�r�rGr�CLI_SS_DESCr^r�r�rw�add_mutually_exclusive_group�CLI_SS_THIRDPARTY�CLI_SS_UNAVAILABLE�CLI_SS_ESM_INFRA�CLI_SS_ESM_APPS)r��groups  rL�security_status_parserr�:s���#�F�K�%�A�A�F��!�-�-�F��
����
�
%�
%�
,�
,�V�
,�
<�(��	��
�/�/�1�E�	����
�
'�
'����

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

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

����
�
%�
%����
�MrMc�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)rr
rr�N)r�r�r�r�)rDr+rwr*rErr�r�r�r�r�rG�CLI_REFRESH_DESCr^r��CLI_REFRESH_TARGETr�s rL�refresh_parserr�`s����F�K��$�$�
�?��F�L�'�0�0�F����%�A�A�F��!�2�2�F��
����2���
�
(�
(����MrMc�P�|jdk(r�|jrtj�y|jrtj
�y|jrtj|�y|jrtj|�ytj|�y|jdk(rCttjtj|�dtj���ytt!tj|�d���y)Nr�r>T)�	sort_keys�clsF)�default_flow_styler)rw�
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;��argsri�kwargss   rL�action_security_statusrts����{�{�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�#(�
�	
�
rMc	�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��Flagsz--assume-yesr��r��r�r�r�r�r�r>r�r�)
r+rwr*rErDr�CLI_DETACH_DESCr^r�r�r��CLI_ASSUME_YESr��r�rEs  rL�
detach_parserr�s������4��:�E��F�L��F�K�!�1�1�F��%�F����
�����
�
$�
$�
+�
+�H�
+�
=���
���������
�
%�
%�
,�
,�U�
,�
;����MrMric�<�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��servicer�r�r��rir�)r�r�r�r�rr�r��--allr�r)r+rwr*rErDr�
CLI_HELP_DESCr^�CLI_ARGS�_positionalsr�r��CLI_HELP_SERVICEr]r�valid_services�STATUS_FORMATSr��CLI_HELP_ALL)r�rirEs   rL�help_parserr�s������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�+@�+@����MrMc��tjtd��|_tj
|_d|_tj|j_
|jtjdd��}|jdtj��}|jt �	�t#|�|S)
z4Build or extend an arg parser for system subcommand.zsystem <command>r��systemr�rkr��reboot-requiredr�r�)r+rwr*rEr�CLI_SYSTEM_DESCr^rDr�r�r�r�r�r��CLI_SYSTEM_REBOOT_REQUIREDr��action_system_reboot_required�reboot_required_parser)r�r��parser_reboot_requireds   rL�
system_parserr$�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��MrMc��tjtd��|_d|_t
j|_tj|_
|S)Nzsystem reboot-requiredr�r)r+rwr*rE�pror�r�rGr�CLI_SYSTEM_REBOOT_REQUIRED_DESCr^r�s rLr"r"�sD���$�$�
�3��F�L�#�F�J�%�A�A�F��!�A�A�F���MrMc
�*�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--waitr�F)r�r�r�r�r�rr�r�z--simulate-with-token�TOKEN)r�r�r�rrr	)r+rwr*rErDr�r�rGr�CLI_STATUS_DESCr^r��CLI_STATUS_WAITrr��CLI_STATUS_SIMULATE_WITH_TOKEN�CLI_STATUS_ALLr�r�rs  rL�
status_parserr.�s�����4��:�E��F�L��F�K�%�A�A�F��!�1�1�F��
������
�
%�
%�	���������q�!��&�&�-�-�n�Q�6G�-�H���������
�
4�
4�	�������8�+B�+B���&�F�����MrM�cmd_name�subcmd_namec�b�t|��}|j�dj|}|j�djj�}||vrT|j�dj|j	�tjddj|����y)Nrr�	<command>r���argr�)�
get_parser�_get_positional_actionsr��keysr`r�InvalidArgChoicer])rir/r0r��	subparser�
valid_choicess      rL�_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�}�%=�
�	
�(rMT)�
update_statusc��|j}|�|}|rtj�}n'tjtj��}|j|�\}}|s�tj|j�|��t|t�r�|j��tj|jj�tj|jj|jj|j��ntj|j�|rt!j |��|S)aPerform 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 json_output: output should be json only

    @return: True on success, False otherwise
    ��	error_msg�
error_coderr)�enabled_variantr�ProgressWrapperr&�CLIEnableDisableProgressr'�event�service_failedrg�
isinstancer3rV�info�msgrW�service_processedr)�entitlementri�json_outputr<�variant�progress�ret�reasons        rL�_perform_disablerPs����)�)�G�������&�&�(���&�&�x�'H�'H�'J�K���%�%�h�/�K�C���
���[�-�-�.���*�V�5F�"G��~�~�)��
�
�6�>�>�-�-�.����$�n�n�0�0�%�~�~�2�2�'�,�,���	���� 0� 0�1���
�
�#���JrMc�4�t|d|j��y)zGPerform the config action.

    :return: 0 on success, 1 otherwise
    r
�r/r0r�r;r�rs   rL�
action_configrT>���
��h�D�L�L��
rMc��|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�r3z
{key} {value}N�r��valuer�z{key: <z	} {value})r�r
r�rr8rwr]r��getattrr��max�len�global_apt_http_proxy�global_apt_https_proxy�ua_apt_http_proxy�ua_apt_https_proxyr�CLI_CONFIG_GLOBAL_XOR_UA_PROXY)rrir�x�	col_width�row_tmplr�s       rLr�r�Is:���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�	�ddlm}ddlm}t	|��}|j�djd}|j�djd}	|jjd�\}}	|tjvrD|j�tjd
dj!tj����|	j#�s&|j�tj$|�
��|dvr�|jd�d}
|
dk(rt&j(}nt&j*}t'j,|
|	|�||	i}|d!i|��t.j0j3|�}|j5�\}
}|
t6j8k(�r�|d!i|���n�||j:vr�|jd�d}
|
dk(rt&j<}nt&j>}t'j,|
|	|�tA|jBxs|jD�}|r*tGtHjJjMdd���tO|tPjR||	�d|_!d|_"�n�||jT|jVzv�rd|vrdnd}
|
dk(rt&j<}nt&j>}||jTvrMtGtHjXjMdjM|
�djM|
����d|z}t'j,|
|	|�tA|jZxs|j\�}|r*tGtHjJjMdd���tO|tPj^||	�d|_-d|_.n~|dvr,	ta|	�}	|	dkrtdjM|���nN|dk(rI|	je�d k(}	|	rtgjh|�ntjjljo�tq|||	�y#t$r2|j�tjd|j�	��wxYw#t$r3|j�tGd�tjb||	���wxYw)"zMPerform the 'config set' action.

    @return: 0 on success, 1 otherwise
    r)�configure_livepatch_proxy)�configure_snap_proxyrr
r��=z
<key>=<value>)�expected�actual�<key>r�r3)r4��
http_proxy�https_proxy�_rrOzpro scoped aptz
global apt)�
current_proxy�previous_proxyN�https�apt_{}_proxy�global_apt_{}_proxy��old�new�global_)�update_messaging_timer�metering_timerzInvalid interval for {}rkrWr	�true�)9�uaclient.livepatchrf�
uaclient.snaprgr5r6r�r��split�
ValueErrorr`r�GenericInvalidFormatr
r�r8r]�strip�EmptyConfigValuer�PROXY_VALIDATION_SNAP_HTTP_URL�PROXY_VALIDATION_SNAP_HTTPS_URL�validate_proxyr�	livepatch�LivepatchEntitlement�application_statusr2�ENABLED�ua_scoped_proxy_options�PROXY_VALIDATION_APT_HTTP_URL�PROXY_VALIDATION_APT_HTTPS_URL�boolr]r^r�r�WARNING_APT_PROXY_OVERWRITErw�configure_apt_proxyr#�UACLIENT�&deprecated_global_scoped_proxy_options�global_scoped_proxy_options�WARNING_CONFIG_FIELD_RENAMEr_r`�GLOBAL�int�InvalidPosIntConfigValue�lowerr	�update_apt_newsr6�apt_news_contents_file�delete�setattr)rrirrfrgr�r�r9�set_key�	set_value�
protocol_type�validate_urlrJ�livepatch_statusro�
unset_currents                rLr�r�hsb��=�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�
�	
��?�?�������)�)�g�6�6��/�/��
�
�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��)�$��U�
������-�-�$�T�-@�-@�
�	
�
��x�	�� � �"��"�I��5�5��9��
�		�s�Q�
*R�;R�<Sc���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_proxyrr
r�rkr�r3rlro)r�Nrrrrsrtrurx)#�uaclient.aptr#r}r�r~r�r�r
r�r5r6r�r`rr8r]rrr�r�r�r2r�r�r�r�r�r�rDrGrr�rwr�r�)
rrirr#r�r�r�r�r9r�rJr�ros
             rLr�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� �rMz
pro detachrec���t||j|jdk(��}|dk(r(tj�tj�tj�|S)zXPerform the detach action for this machine.

    @return: 0 on success, 1 otherwise
    r>)�
assume_yesrKr)	�_detachr�rwr�startr�stoprD�process_events)rrirrNs    rL�
action_detachr�sN�������d�k�k�V�6K��C��a�x�����
�
�
��	�����JrMr�rKc���g}t|�D]M}	tj||��}|||��}|jd��\}}|s�=|j
|��O|rptjtjjt|���|D]0}tjdj|j���2tj |��sy|D]}t#|||d�	��|j$j'�t)j*�t-|�tjtj.�y
#tj$rY��bwxYw)ajDetach 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.
    :param json_output: output should be json only

    @return: 0 on success, 1 otherwise
    rh)rir�T)�ignore_dependent_servicesz    {})r�rYF)rKr<r)r0rrsrrt�can_disabler{rDrGr�DETACH_WILL_DISABLE�	pluralizer\rwrgr�prompt_for_confirmationrP�machine_token_filer�r6�delete_state_filesr:�DETACH_SUCCESS)	rir�rK�
to_disable�ent_namer�entrNros	         rLr�r�%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��'�'�:�>���
�����+�U�	
�
�
���!�!�#��"�"�$����	�J�J�x�&�&�'���5�2�2�	��	�s�E�E1�0E1c�l�d}|jr;|jjdi�jdi�jd�}|r4tjtj
j
|���n#tjtj�tj�tj|�tj|�\}}tj|�}tjtj|��tj!�y)N�machineTokenInfo�contractInforg)�
contract_name)�
machine_tokenrurDrGr�ATTACH_SUCCESS_TMPLrw�ATTACH_SUCCESS_NO_CONTRACT_NAMErr��cleanuprr�format_tabularr�handle_unicode_charactersr�)rir��status_dict�_ret�outputs     rL�_post_cli_attachr�Qs����M�
������!�!�"4�b�9�
�S���
$�
�S��[�	��
�
�
��(�(�/�/�m�/�L�	
�	�
�
�8�;�;�<�
�K�K�M�
�N�N�3�����s�+��K��
�
"�
"�;�
/�F�	�J�J�t�-�-�f�5�6�	���rMc��	tt�|tjj��t|�y#tj$r0tjtjj�YywxYw)N)ri�moderrY)
rrr�EventLoggerMode�CLIr�r�ConnectivityErrorrDrGr�E_ATTACH_FAILURErHrs   rL�action_auto_attachr�ksf����!�#���-�-�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�)�paramrXrrP)�	user_code)�magic_token)r�ri)rwr�MagicAttachInvalidParamrDrGr�CLI_MAGIC_ATTACH_INITr�CLI_MAGIC_ATTACH_SIGN_INr�r r�r!�MagicAttachTokenError�CLI_MAGIC_ATTACH_FAILEDrr�CLI_MAGIC_ATTACH_PROCESSING�contract_token)rrir�
initiate_resp�wait_options�	wait_resp�e�revoke_optionss        rL�
_magic_attachr�{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}t
jj|�d}nA	tjt|j��}|j}|j}|j xr|du}	t#j$|||��d}|��O|j �rBt'||�\}	}
|	D]�}t#j(||dd��\}}
|s�d}|
��&t+|
t,�s�7|
j.��Dt0j3|
j.j�t0j5|
j.j|
j.j|����t0j7|���|
rjt9|
|d�	�}t0j3|jt:j<�
�t0j5|j|j>��d}tAjB|�}|jE�tG|�|S#t$r:}tj|jj|j���d}~wwxYw#tjH$rtjJ��wxYw)Nr)�config_namerW)r��allow_enablerT)r��
allow_betarYr>)rir���	file_type�r?r@)&r��
attach_configr�CLIAttachTokenArgXORConfigr�r�secrets�
add_secretr,�	from_dictr<r-�AttachInvalidConfigFileErrorrgrH�enable_servicesr�r�attach_with_tokenr1�enable_entitlement_by_namerFr4rVrDrGrWrIr/rRrS�msg_coder�UAContractClient�update_activity_tokenr�r��AttachError)rrirr��enable_services_overrider�r�r�rN�found�	not_foundrg�ent_retrOrW�contract_clients                rL�
action_attachr��s|���z�z�d�(�(��3�3�5�5�
�Z�Z�� 2� 2��d��,��#'� �	
����
�
�����)�)�%�0�#'� �	�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$�(J�#K�	K�
5J?�?K�(K/c��|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/)�arcnamerYr)r��UA_COLLECT_LOGS_FILE�tempfile�TemporaryDirectoryr�collect_logs�tarfile�open�add�PermissionError�LOGrW)rrir�output_file�
output_dir�resultsr�s       rL�action_collect_logsr�s����+�+�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��t3j(||�|j)dtj4��}t7|�|j/t8��|j)dtj:��}t=|�|j/t>��|j)dtj@��}tC|�|j/tD��|j)dtjF��}tI|�|j/tJ��tMj(||�tOj(||�tQj(|�|j)dtjR��}	tU|	�|	j/tV��|j)dtjX��}
t[|
|��|
j/t\��|j)dtj^��}|j/t`��tc|�|j)dtjd��}|j/tf��ti|�|j)dtjj
t�	���}
|
j/tj��|j)dtjl��}|j/tn��tq|�|S)Nr2r�)rDrGrErFrBz--debugr�rz	--versionr)rg)r�rr�r�rkr�Tr�r�r�r�r�r
rr�r�rr�rr)9�__doc__rAr*r�r�r+rwr�CLI_HELP_EPILOGr��CLI_ROOT_DEBUGr�get_version�CLI_ROOT_VERSIONr�r�r�r�r��requiredr��CLI_ROOT_ATTACHr�r�r�r%�CLI_ROOT_AUTO_ATTACHr�r��CLI_ROOT_COLLECT_LOGSr�r�CLI_ROOT_CONFIGr�rT�CLI_ROOT_DETACHrr�r'r(r)�CLI_ROOT_SECURITY_STATUSr�r�
CLI_ROOT_HELPr�action_help�CLI_ROOT_REFRESH�action_refreshr��CLI_ROOT_STATUS�
action_statusr.�
print_version�CLI_ROOT_SYSTEM�
action_systemr$)rirBr�r��
parser_attach�parser_auto_attach�parser_collect_logs�
parser_config�
parser_detach�parser_security_status�parser_help�parser_refresh�
parser_status�parser_version�
parser_systems               rLr5r5�s����I�
�
� �<�<����T�;�?��'�'�.�.�D�+�.�N���F�����,�X�-D�-D���������#�#�%�
�
&�
&�
-�
-�4�
-�
8�	��'�0�0�F�����&�&��-�-�I�r�'��J��J���)�)��x�/�/�*��M��-� ����m��4����z�3�'�#�.�.��H�9�9�/����)�*��#�#�+=�#�>�$�/�/��X�;�;�0����+�,��$�$�,?�$�@��)�)��x�/�/�*��M��-� ����m��4��)�)��x�/�/�*��M��-� ����m��4����z�3�'�
���j�#�&��N�N�:��'�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��-� ��MrMc���|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_tokenra�execution_status�.rk)�endrY�ra)r
rq�allr+r�UserFacingConfigStatus�ACTIVErXrr��waitrDrG�time�sleep�set_output_contentr�rr�r�)
rrirrar��active_valuer�rN�
config_activer�s
          rLrrQs*����o�o����t�x�x�U�H�(,�D�$�$�$�E��0�0�7�7�=�=�L��~�~������K����%7�8�L�H�I�M���	�	�m��,�-��=��J�J�s��J�#��J�J�q�M�&�~�~��$)�!� ��K���,�-��=�	�
�
�2��	���[�)�
�
"�
"�;��
B�F�	�J�J�t�-�-�f�5�6�	�����JrMc�4�t|d|j��y)zGPerform the system action.

    :return: 0 on success, 1 otherwise
    rrRrrSrs   rLrrnrUrMc�X�t|�}tj|j�y)Nr)r"rDrG�reboot_required)rrir�results    rLr!r!ys!��
�c�
"�F�	�J�J�v�%�%�&�rMc�>�ttj��y�N)r�rr
)�_argsrirs   rLrrs��	�'�
�
�
� rMc���	|j�t
tj�y#t$r.}tj|�t	j
��d}~wwxYwr>)	�process_config�RuntimeErrorr�	exceptionr�RefreshConfigFailurer�r�REFRESH_CONFIG_SUCCESS)rri�excs   rL�_action_refresh_configrG�sP��0�����
�(�
)�
)�*���0��
�
�c���-�-�/�/��0�s�,�	A#�)A�A#c��	tj|�ttj�y#tj$rtj��wxYwr>)rr�rr��RefreshContractFailurer�r�REFRESH_CONTRACT_SUCCESS)r?ris  rL�_action_refresh_contractrK�sK��2������
�(�
+�
+�,���'�'�2��/�/�1�1�2�s	�1�(Ac��	t|�t�|jrtj|�t	t
j�y#t$r.}tj|�tj��d}~wwxYwr>)r:r9r	r�r�r�REFRESH_MESSAGES_SUCCESS�	ExceptionrrCr�RefreshMessagesFailure)r?rirFs   rL�_action_refresh_messagesrP�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)Nr
rrr)r�rGrKr5�remover7�CONTRACT_REFRESH_WARNINGrPrs   rLrr�sv���{�{��d�k�k�X�5��t�S�)��{�{��d�k�k�Z�7� ��s�+����v�6�6�7��{�{��d�k�k�Z�7� ��s�+�rM�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
    rr)rmrn�proxy_scopeN)r#r�r]r^r�r_r`r$)rirTr�r�rmrns      rLr�r��sm��
�
�$�$�$��.�.�
��0�0��	�-�(�(�	(��*�*�
��,�,���'�����
���;�E�rMc��|j}|j}|st|��j|��y|st	j
�}t
j||�}|jdk(rttj|��y|j�D].\}}tdj|j�|���0y)Nrr/rr>z{}:
{}
)rr0r5r`r
rqrr�rwr�r>r�itemsr�)rrirrra�
help_responser�rXs        rLrr�s����l�l�G��x�x�H���s��&�&��&�9����o�o����K�K��W�-�M��{�{�f��
�d�j�j��'�(�

�(�-�-�/�	:�J�C���+�$�$�S�Y�Y�[�%�8�9�	:�
rMc�&�|r|jdk(st|dd�dvrytj�}|rZtjd|�tjtjj|��tj��yy)Nrrwrk�r>r?zNew version available: %s)rr�)
r�rZr�check_for_new_versionr�warningrDrGr�WARN_NEW_VERSION_AVAILABLE_CLIrwrRrS)�cmd_args�new_versions  rL�_warn_about_new_versionra�s���
	�����%��8�X�r�*�.>�>���/�/�1�K�����/��=�
�
�
��3�3�:�:�#�
;�
��j�j�		�	
�rMc�Z�|jdvr�tjj�s~t	|d�r|j
dvrytjd�tjtjj|j��tj��yyy)z4Warn users that the user readable output may change.)rr�rwr[Nz.Not in a tty and human-readable command calledr
r�)
r�rR�stdout�isatty�hasattrrwrr]rDrGr�WARNING_HUMAN_READABLE_OUTPUTrS�r_s rL�_warn_about_output_redirectionrh�s���	���9�9��
�
�!�!�#��8�X�&�8�?�?�>N�+N�����D�E�
�
�
��2�2�9�9� �(�(�
:�
��j�j�		�	
�$�	:rMc�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)r�rr(r'rrwr>r?N)
r�rD�set_commandrerw�set_event_moderr��JSON�YAMLrgs rLrkrk
s������N�N�
���(�*�*�+��8�X�&����&�(��$�$�\�%A�%A�%F�%F�G����&�(��$�$�\�%A�%A�%F�%F�G�)�'�OrMc����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|�tM���j*tj��t(jtO|dt|��d��t(j7�t9�t
jd�Yd}~yd}~wwxYw)N�KeyboardInterruptrYrY�CERTIFICATE_VERIFY_FAILEDzca-certificates)rlr�)�info_msgr�zFailed to access URL: %s)�exc_info)rl�cause_error)r?r@�additional_infoz{}z&Unhandled exception, please file a bug)r?�log_pathrHrC)r?�
error_type)(rprrWr�r�CLI_INTERRUPT_RECEIVEDrRrSr�clear_lock_file_if_presentrUrr�r��&SSL_VERIFICATION_ERROR_CA_CERTIFICATESr�is_installed�%SSL_VERIFICATION_ERROR_OPENSSL_CONFIGrwrlrDrHrgrGrC�E_CONNECTIVITY_ERRORrtr�ra�PycurlCACertificatesError�UbuntuProErrorr�rurF�
LockHeldError�	exit_coderN�UNEXPECTED_ERRORr8rZ)rrrF�tmplrHr��funcs      �rL�wrapperz#main_error_handler.<locals>.wrappers����P	���(��(�(�� �	��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�9�9�!�!�f�;�=�:���#��*�*�
�
�
�K�K�!�!�U�C��F�3��
�
�
� � �"�#�%��H�H�Q�K�K��#	�sD��A0U)�=U)�F1I�U)�C2M�U)�*C>Q-�-U)�9C&U$�$U)r|)r�r�s` rL�main_error_handlerr�s���Q�f�NrMc��tjtjdtjd�t	j
�}tj|j|j�|stj}t|��}|dd}|s>|j�ttj�tjd�d|vr|j!d�}|d|}||dzd}n|}g}|j#|��}|j$rft'j(tj*�}|j-t&j.�t'j0d�j3|�t5|�|j6}	|j8}
t;j<|	|
��t>j%d	|z�|jA�tCtEjF�jI��D��cgc]\}}d
jK||���}
}}|
rt>j%d|
z�tM|�|jO|||��}tQ|�|Scc}}w)
N�	log_level�log_filerrYz--)r�	ubuntuprorlzExecuted with sys.argv: %rz{}={}z'Executed with environment variables: %r)ri�
extra_args))r�setup_cli_loggingr
�CONFIG_DEFAULTSr
rqr�r�rR�argvr5rQr�rrTrU�index�
parse_args�debug�logging�
StreamHandlerrS�setLevel�DEBUG�	getLogger�
addHandlerrkrmrnr�configure_web_proxyr�warn_about_invalid_keysr\r�get_pro_environmentrXrwrhr�ra)�sys_argvrir��
cli_arguments�double_dash_index�pro_cli_argsr�r�console_handlerrmrn�k�v�pro_environment�return_values               rL�mainr�ls
������ � ��-�� � ��,���/�/�
�C����#�-�-����6���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__)NNr>)reN)�r
r�r>r�rRrr�rxr4�typingrrr�uaclientrrrr	r
rrr
rrrrrrrrrrrrr�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"r�r#r$�uaclient.clir%r&r'r(r)�uaclient.cli.constantsr*r+�uaclient.data_typesr,r-�uaclient.defaultsr.�uaclient.entitlementsr/r0r1�(uaclient.entitlements.entitlement_statusr2r3r4�uaclient.filesr5r6�uaclient.files.noticesr7�uaclient.logr8�uaclient.timer.update_messagingr9r:�
uaclient.yamlr;r<�UA_AUTH_TOKEN_URLrr��get_event_loggerrDr��replace_top_level_logger_namer�r�ArgumentParserrAr�r�r�r�r�r�r�r�r�r�rrrqrr$r"r.r;rPrTr��assert_rootr�r��verify_json_format_args�assert_attached�assert_lock_filer�r�r�r�r�r�r��assert_not_attachedr�rr5rrr!rrGrKrPrr�rrarhrkr�r�rUr|rMrL�<module>r�s-��8����
�����(�(�������.�B����8�@�@�3�K�.���
��
0�)�7�N�.�:��,��(��%��%�%�'���g���:��:�:�8�D�E��[<�x�.�.�[<�|�
��s���c��&���(�@�:#�L�(
�<�,�V�_�_��>�$� �F

�	���

�$'�

�69�

�FJ�'�T
�7�>
���w%��w%�t
���+
��+
�\
�!�!�	������������<�(��S��)���"��)
����)
�d�)
��)
�#�)
�X�&�/�/��d��4
����V�_�_��3����$�B
���	�������<�(�C�)���C�L

�f�o�o�

�\�F�O�O�\�~�����:
�
����
�!�+�f�o�o�+������-����-��-�
1����
1� 
�������=�)�
����
�*��
��	����������}�	�

��0
�,
�,
�"H�T�n�8��8�v�z���C�H�H�T�V��rM

Zerion Mini Shell 1.0