o
    ÙKÕiT  ã                   @   sÒ   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZ G dd	„ d	eeƒZd
efdd„Zde	d
efdd„Zeddedd�ZdddeejdfejdfejdfgdddœZdS )é    )Úsecret_manager)Ú
exceptions)ÚAPIEndpoint)ÚAdditionalInfo)ÚUAConfig)ÚUAContractClient)Ú
DataObjectÚFieldÚIntDataValueÚStringDataValuec                   @   sZ   e Zd Zededd�ededd�ededd�eded	d�gZdedededefd
d„Z	dS )ÚMagicAttachInitiateResultÚ	user_codezACode the user will see in the UI when confirming the Magic Attach)ÚdocÚtokenzgMagic Token that can be used in either `u.pro.attach.magic.revoke.v1`_ or `u.pro.attach.magic.wait.v1`_Úexpiresz0Timestamp of the Magic Attach process expirationÚ
expires_inz/Seconds before the Magic Attach process expiresc                 C   s   || _ || _|| _|| _d S ©N©r   r   r   r   )Úselfr   r   r   r   © r   úM/usr/lib/python3/dist-packages/uaclient/api/u/pro/attach/magic/initiate/v1.pyÚ__init__.   s   
z"MagicAttachInitiateResult.__init__N)
Ú__name__Ú
__module__Ú__qualname__r	   r   r
   ÚfieldsÚstrÚintr   r   r   r   r   r      s>    üü	ýýéþýüûr   Úreturnc                   C   s
   t tƒ ƒS r   )Ú	_initiater   r   r   r   r   Úinitiate;   s   
r    Úcfgc                 C   sT   t | ƒ}| ¡ }tj |d ¡ tj |d ¡ t|d |d |d t|d ƒd�S )z�
    This endpoint initiates the Magic Attach flow, retrieving the User Code to
    confirm the operation and the Token used to proceed.
    r   ÚuserCoder   Ú	expiresInr   )r   Únew_magic_attach_tokenr   ÚsecretsÚ
add_secretr   r   )r!   ÚcontractÚinitiate_respr   r   r   r   ?   s   
ür   Úv1ÚMagicAttachInitiateN)ÚversionÚnameÚfnÚoptions_clsz27.11TzW
from uaclient.api.u.pro.attach.magic.initiate.v1 import initiate

result = initiate()
zARaised if it is not possible to connect to the contracts service.zLRaised if there is an unexpected error in the contracts service interaction.zHRaised if the Magic Attach service is busy or unavailable at the moment.z&pro api u.pro.attach.magic.initiate.v1z„
{
    "user_code":"<UI_code>",
    "token":"<magic_token>",
    "expires": "<yyyy-MM-dd>T<HH:mm:ss>.<TZ>",
    "expires_in": 600
}
)Úintroduced_inÚrequires_networkÚexample_pythonÚresult_classr   Úexample_cliÚexample_json)Úuaclientr   Úuaclient.apir   Úuaclient.api.apir   Úuaclient.api.data_typesr   Úuaclient.configr   Úuaclient.contractr   Úuaclient.data_typesr   r	   r
   r   r   r    r   ÚendpointÚConnectivityErrorÚContractAPIErrorÚMagicAttachUnavailableÚ_docr   r   r   r   Ú<module>   sB    ,üýýýñ
ß