
    f              
       4   d dl Z d dlmZ d dlmZmZmZmZ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mZ d d	lmZ g d
Zdee   dee   deeeef   ee   f   fdZdedee   deeeef   ee   f   fdZdedee   dededef
dZ G d d      Zy)    N)import_module)AnyCallableDictListTuple)errors)APIDataAPIResponseErrorWarningObject)UAConfig)IncorrectFieldTypeError)API_UNKNOWN_ARGWARN_NEW_VERSION_AVAILABLE)check_for_new_version)z,u.pro.attach.auto.configure_retry_service.v1z%u.pro.attach.auto.full_auto_attach.v1z'u.pro.attach.auto.should_auto_attach.v1zu.pro.attach.magic.initiate.v1zu.pro.attach.magic.revoke.v1zu.pro.attach.magic.wait.v1zu.pro.packages.summary.v1zu.pro.packages.updates.v1z!u.pro.security.fix.cve.execute.v1zu.pro.security.fix.cve.plan.v1z!u.pro.security.fix.usn.execute.v1zu.pro.security.fix.usn.plan.v1z'u.pro.security.status.livepatch_cves.v1z(u.pro.security.status.reboot_required.v1z u.pro.status.enabled_services.v1zu.pro.status.is_attached.v1zu.pro.version.v1zu.security.package_manifest.v1zu.unattended_upgrades.status.v1zu.apt_news.current_news.v1optionsfieldsreturnc                 h   i }g }| D ]  }	 |j                  d      \  }}|r|st        j                  |      ||vrI|j	                  t        t        j                  |      j                  t        j                  i              |||<    ||fS # t        $ r t        j                  |      w xY w)N=argtitlecodemeta)
split
ValueErrorr	   APIBadArgsFormatappendr   r   formatmsgname)r   r   kwargswarningsoptionkvs          2/usr/lib/python3/dist-packages/uaclient/api/api.py_process_optionsr*   $   s     FH 	6<<$DAq ))f55F?OO")00Q7;;(-- q	%( 8#  	6))f55	6s   B B1datac                    i }g }	 t        j                  |       }|j                         D ]  \  }}|r|s&t	        j                  dj                  ||            ||vrI|j                  t        t        j                  |      j                  t        j                  i              |||<    ||fS # t         j                  j                  $ r t	        j
                  |       w xY w)N)r+   z{}:{}r   r   )jsonloadsdecoderJSONDecodeErrorr	   APIJSONDataFormatErroritemsr   r!   r    r   r   r"   r#   )r+   r   r$   r%   	json_datar'   r(   s          r)   _process_datar4   A   s     FH7JJt$	 ! 1))gnnQ.BCCF?OO")00Q7;;(-- q	 8% <<'' 7++667s   B3 34C'endpoint_pathcfgc           	      H   | t         vr)t        j                  t        j                  |             S t	        d| z         }|j
                  }g }|j                  r|j                  j                  D cg c]  }|j                   }}	 |rt        ||      \  }	}
n|rt        ||      \  }	}
ni g }
}	|j                  |
       	 |j                  j                  |	      }	 |j!                  ||      }n?|s|r)t        j                  t        j$                  |             S 	 |j!                  |      }t'               }|rI|j)                  t+        t-        j.                  |      j0                  t,        j2                  i              t5        |j6                  |j8                  |z   t;        |j2                  ||j<                              S c c}w # t        j                  $ r}t        j                  |      cY d }~S d }~ww xY w# t        $ r>}t        j                  t        j                  |j                  |             cY d }~S d }~ww xY w# t"        $ r}t        j                  |      cY d }~S d }~ww xY w# t"        $ r}t        j                  |      cY d }~S d }~ww xY w)N)endpointzuaclient.api.)r   r8   )versionr   )type
attributesr   )_schema_versionr%   r+   )VALID_ENDPOINTSr	   	error_outAPIInvalidEndpointr   r8   options_clsr   keyr*   r4   extendAPIError	from_dictr   APIMissingArgfn	ExceptionAPINoArgsForEndpointr   r    r   r   r!   r"   r#   r   r9   r%   r
   r   )r5   r   r+   r6   moduler8   option_warningsfr   r$   r%   eresultnew_versions                 r)   call_apirO   ^   sR    O+%%}=
 	
 ?]:;FHO!)!5!5!<!<=A!%%==		'#3GV#D #0v#> #%r""8,	**44V<G	'[[#.F
 d##++]C 	'[[%F ()K077'#/44	
  ((?2
 ] >  	'##A&&	'
 ' 	##$$G 	  	'##A&&	'  	'##A&&	's~   2G
9G H I I9 H"G<6H<H	I3I II	I6I1+I61I69	J!JJ!J!c                        e Zd ZdededefdZy)APIEndpointr9   r#   rF   c                 <    || _         || _        || _        || _        y )N)r9   r#   rF   r@   )selfr9   r#   rF   r@   s        r)   __init__zAPIEndpoint.__init__   s!     	&    N)__name__
__module____qualname__strr   rT    rU   r)   rQ   rQ      s#    
'
' 
' 	
'rU   rQ   )r-   	importlibr   typingr   r   r   r   r   uaclient.apir	   uaclient.api.data_typesr
   r   r   uaclient.configr   uaclient.data_typesr   uaclient.messagesr   r   uaclient.versionr   r=   rY   r*   r4   rO   rQ   rZ   rU   r)   <module>rc      s     # 3 3  L L $ 7 I 20#Y $S	
4S>4 2334:
Cy
4S>4 2334:EE!%cE25E<DEEP' 'rU   