o
    f                  
   @   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  t |dk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yS   d	}t
td
| Y nw |dkrZt}| | j|jddjd}dddd}	|	 D ]\}
}z	t|||
< W qt ty   t
td| Y qtw i }|D ]}||v r|| ||< qd ||< td| qi }| D ]\}}|d u rd||< qt|||< qd|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)lenr   	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 rH   @/usr/lib/python3/dist-packages/cloudinit/config/cc_phone_home.pyhandle1   s   



rJ   )__doc__logging	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr   cloudinit.settingsr	   r2   r   __annotations__	getLogger__name__r*   r8   listrJ   rH   rH   rH   rI   <module>   s    

"