o
    x[hõ  ã                
   @   s¬   U d Z ddl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 ddlmZ ddlmZ g d	¢Zd
egedgdœZeed< e e¡Zdede	dededdf
dd„ZdS )zPhone Home: Post data to urlé    N)Ú	templaterÚ
url_helperÚutil)ÚCloud)ÚConfig)Ú
MetaSchema)ÚALL_DISTROS)ÚPER_INSTANCE)Úpub_key_rsaÚpub_key_ecdsaÚpub_key_ed25519Úinstance_idÚhostnameÚfqdnÚcc_phone_homeÚ
phone_home)ÚidÚdistrosÚ	frequencyÚactivate_by_schema_keysÚmetaÚnameÚcfgÚcloudÚargsÚreturnc              	   C   sì  |r
t  |d ¡}nd|vrt d| ¡ d S |d }d|vr&t d| ¡ d S |d }| dd¡}| d¡}zt|ƒ}W n ttfyO   d	}t  	td
|¡ Y nw |dkrVt
}| ¡ | ¡ j|jdd�jdœ}ddddœ}	|	 ¡ D ]\}
}z	t  |¡||
< W qp ty�   t  	td|¡ Y qpw i }|D ]}||v rŸ|| ||< q’d ||< t d|¡ q’i }| ¡ D ]\}}|d u r½d||< q°t|ƒ||< q°d|d i}t ||¡}ztj|||d dt  |j¡d� W d S  tyõ   t  	td||¡ Y d S w )Nr   r   z=Skipping module named %s, no 'phone_home' configuration foundÚurlzFSkipping module named %s, no 'url' found in 'phone_home' configurationÚpostÚallÚtriesé
   z?Configuration entry 'tries' is not an integer, using %s insteadT)r   )r   r   r   z/etc/ssh/ssh_host_rsa_key.pubz/etc/ssh/ssh_host_ecdsa_key.pubz!/etc/ssh/ssh_host_ed25519_key.pub)r
   r   r   z1%s: failed to open, can not phone home that data!z=Requested key %s from 'post' configuration list not availablezN/AÚINSTANCE_IDr   é   é   )ÚdataÚretriesÚsec_betweenÚssl_detailsz0Failed to post phone home data to %s in %s tries)r   Ú	read_confÚLOGÚdebugÚwarningÚgetÚintÚ
ValueErrorÚ	TypeErrorÚlogexcÚPOST_LIST_ALLÚget_instance_idÚget_hostnamer   ÚitemsÚload_text_fileÚ	ExceptionÚstrr   Úrender_stringr   Úread_file_or_urlÚfetch_ssl_detailsÚpaths)r   r   r   r   Úph_cfgr   Ú	post_listr   Úall_keysÚpubkeysÚnÚpathÚsubmit_keysÚkÚreal_submit_keysÚvÚ
url_params© rG   ú@/usr/lib/python3/dist-packages/cloudinit/config/cc_phone_home.pyÚhandle1   s˜   ýý
ýþýýÿÿý
ÿ
û
ÿÿrI   )Ú__doc__ÚloggingÚ	cloudinitr   r   r   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   Úcloudinit.distrosr   Úcloudinit.settingsr	   r1   r   Ú__annotations__Ú	getLoggerÚ__name__r)   r7   ÚlistrI   rG   rG   rG   rH   Ú<module>   s    
ü
"