o
    (f                     @   s4  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dZdedee de	eeef ee f fddZ	ddedee dededee defddZG dd dZdS )    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.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.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              	   C   s   i }g }| D ];}z	| d\}}W n ty   tj|dw |r#|s)tj|d||vr=|ttj|djtj	i d |||< q||fS )N=argtitlecodemeta)
split
ValueErrorr
   APIBadArgsFormatappendr   r   formatmsgname)r   r   kwargswarningsoptionkv r)   2/usr/lib/python3/dist-packages/uaclient/api/api.py_process_options)   s(   
r+   datac                 C   s   i }g }zt | }W n t jjy   tj| dw | D ]\}}||vr7|tt	j
|djt	ji d |||< q||fS )N)r,   r   r   )jsonloadsdecoderJSONDecodeErrorr
   APIJSONDataFormatErroritemsr    r   r   r!   r"   r#   )r,   r   r$   r%   	json_datar'   r(   r)   r)   r*   _process_dataF   s$   
r4   endpoint_pathcfgprogress_objectc              
   C   s  | t vrttj| dS td|  }|j}g }|jrdd |jjD }z |r/t||\}	}
n|r9t	||\}	}
ni g }	}
|
|
 W n tjy\ } zt|W  Y d }~S d }~ww z|j|	}W n ty } zttj|j| dW  Y d }~S d }~ww z|jr|j|||d}n|||}W nN ty } zt|W  Y d }~S d }~ww |s|rttj| dS z|jr|j||d}n||}W n ty } zt|W  Y d }~S d }~ww t }|r|ttj|djtji d t|j|j| t|j||jd	d
S )N)endpointzuaclient.api.c                 S   s   g | ]}|j qS r)   )key).0fr)   r)   r*   
<listcomp>s   s    zcall_api.<locals>.<listcomp>)r   r8   )r7   )versionr   )type
attributesr   )_schema_versionr%   r,   ) VALID_ENDPOINTSr
   	error_outAPIInvalidEndpointr   r8   options_clsr   r+   r4   extendAPIError	from_dictr   APIMissingArgr9   supports_progressfn	ExceptionAPINoArgsForEndpointr   r    r   r   r!   r"   r#   r   r=   r%   r   r   )r5   r   r,   r6   r7   moduler8   option_warningsr   r$   r%   eresultnew_versionr)   r)   r*   call_api`   s   




rR   c                	   @   s*   e Zd Z	d	dedededefddZdS )
APIEndpointFr=   r#   rJ   rI   c                 C   s"   || _ || _|| _|| _|| _d S N)r=   r#   rJ   rD   rI   )selfr=   r#   rJ   rD   rI   r)   r)   r*   __init__   s
   
zAPIEndpoint.__init__N)F)__name__
__module____qualname__strr   boolrV   r)   r)   r)   r*   rS      s    rS   rT   ) 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   rA   rZ   r+   r4   rR   rS   r)   r)   r)   r*   <module>   sN     


T