
    g<                     J   d dl Z d dlmZ d dlmZmZmZmZmZm	Z	 d dl
mZ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dedee   dededee   defdZ G d d      Zy)    N)import_module)AnyCallableDictListOptionalTuple)AbstractProgresserrors)APIDataAPIResponseErrorWarningObject)UAConfig)IncorrectFieldTypeError)API_UNKNOWN_ARGWARN_NEW_VERSION_AVAILABLE)check_for_new_version)zu.pro.version.v1z,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.guest.get_guest_token.v1zu.pro.attach.magic.initiate.v1zu.pro.attach.magic.revoke.v1zu.pro.attach.magic.wait.v1z'u.pro.attach.token.full_token_attach.v1zu.pro.detach.v1zu.pro.packages.summary.v1zu.pro.packages.updates.v1zu.pro.security.cves.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.services.dependencies.v1zu.pro.services.disable.v1zu.pro.services.enable.v1z u.pro.status.enabled_services.v1zu.pro.status.is_attached.v1zu.apt_news.current_news.v1zu.security.package_manifest.v1zu.unattended_upgrades.status.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 ]W  \  }}||vrI|j                  t        t        j                  |      j                  t        j                  i              |||<   Y ||fS # t         j                  j                  $ r t	        j
                  |       w xY w)N)r-   r   r   )jsonloadsdecoderJSONDecodeErrorr   APIJSONDataFormatErroritemsr"   r   r   r#   r$   r%   )r-   r   r&   r'   	json_datar)   r*   s          r+   _process_datar6   H   s     FH7JJt$	 ! 
1F?OO")00Q7;;(-- q	
 8 <<'' 7++667s   B	 	4B=endpoint_pathcfgprogress_objectc           	         | 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                   r|j#                  |||      }n|j#                  ||      }n_|s|r)t        j                  t        j&                  |             S 	 |j                   r|j#                  ||      }n|j#                  |      }t)               }|rI|j+                  t-        t/        j0                  |      j2                  t.        j4                  i              t7        |j8                  |j:                  |z   t=        |j4                  ||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   r;   )r9   )versionr   )type
attributesr   )_schema_versionr'   r-   ) VALID_ENDPOINTSr   	error_outAPIInvalidEndpointr   r;   options_clsr   keyr,   r6   extendAPIError	from_dictr   APIMissingArgsupports_progressfn	ExceptionAPINoArgsForEndpointr   r"   r   r   r#   r$   r%   r   r<   r'   r   r   )r7   r   r-   r8   r9   moduler;   option_warningsfr   r&   r'   eresultnew_versions                  r+   call_apirS   b   s    O+%%}=
 	
 ?]:;FHO!)!5!5!<!<=A!%%==		'#3GV#D #0v#> #%r""8,	**44V<G	'))!S/ %  "Wc2
 d##++]C 	'))!S/J!S) ()K077'#/44	
  ((?2
 m >  	'##A&&	'
 ' 	##$$G 	  	'##A&&	'  	'##A&&	's~   2H9H I 3J  1J: I#H=7I=I	J3JJJ	J7J2,J72J7:	K"KK"K"c            	       (    e Zd Z	 ddedededefdZy)APIEndpointr<   r%   rJ   rI   c                 J    || _         || _        || _        || _        || _        y N)r<   r%   rJ   rC   rI   )selfr<   r%   rJ   rC   rI   s         r+   __init__zAPIEndpoint.__init__   s)     	&!2    N)F)__name__
__module____qualname__strr   boolrY    rZ   r+   rU   rU      s2     #(33 3 	3  3rZ   rU   rW   ) r/   	importlibr   typingr   r   r   r   r   r	   uaclient.apir
   r   uaclient.api.data_typesr   r   r   uaclient.configr   uaclient.data_typesr   uaclient.messagesr   r   uaclient.versionr   r@   r^   r,   r6   rS   rU   r`   rZ   r+   <module>ri      s    # = = 1 L L $ 7 I 2>#Y $S	
4S>4 2334:
Cy
4S>4 2334> 37QQ#YQ Q 
	Q
 ./Q Qh3 3rZ   