
    fK              
          U d Z ddlZddl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 dd	lmZ eZg d
ZdZdddeege ed       ed      gdgdZeed<    ee      Z  ej0                  e      Zdedede	deddf
dZy)zPhone Home: Post data to url    N)dedent)	templater
url_helperutil)Cloud)Config)
MetaSchemaget_meta_doc)ALL_DISTROS)PER_INSTANCE)pub_key_rsapub_key_ecdsapub_key_ed25519instance_idhostnamefqdna;  This module can be used to post data to a remote host after boot is complete.
If the post url contains the string ``$INSTANCE_ID`` it will be replaced with
the id of the current instance. Either all data can be posted or a list of
keys to post. Available keys are:

    - ``pub_key_rsa``
    - ``pub_key_ecdsa``
    - ``pub_key_ed25519``
    - ``instance_id``
    - ``hostname``
    - ``fdqn``

Data is sent as ``x-www-form-urlencoded`` arguments.

**Example HTTP POST**:

.. code-block:: http

    POST / HTTP/1.1
    Content-Length: 1337
    User-Agent: Cloud-Init/21.4
    Accept-Encoding: gzip, deflate
    Accept: */*
    Content-Type: application/x-www-form-urlencoded

    pub_key_rsa=rsa_contents&pub_key_ecdsa=ecdsa_contents&pub_key_ed25519=ed25519_contents&instance_id=i-87018aed&hostname=myhost&fqdn=myhost.internal
cc_phone_homez
Phone HomezPost data to urlzt            phone_home:
                url: http://example.com/$INSTANCE_ID/
                post: all
            aQ              phone_home:
                url: http://example.com/$INSTANCE_ID/
                post:
                    - pub_key_rsa
                    - pub_key_ecdsa
                    - pub_key_ed25519
                    - instance_id
                    - hostname
                    - fqdn
                tries: 5
            
phone_home)idnametitledescriptiondistros	frequencyexamplesactivate_by_schema_keysmetar   cfgcloudargsreturnc           	         t        |      dk7  rt        j                  |d         }n d|vrt        j	                  d|        y |d   }d|vrt        j                  d|        y |d   }|j                  dd      }|j                  d      }	 t        |      }|dk(  rt        }|j                         |j                         j                  |j                  d      j                  d}dddd}	|	j                         D ]  \  }
}	 t        j                   |      ||
<     i }|D ]*  }||v r	||   ||<   d ||<   t        j                  d|       , i }|j                         D ]  \  }}|d||<   t%        |      ||<    d|d   i}t'        j(                  ||      }	 t+        j,                  |||dz
  dt        j.                  |j0                               y # t        t        f$ r! d	}t        j                  t        d
|       Y qw xY w# t"        $ r t        j                  t        d|       Y 5w xY w# t"        $ r t        j                  t        d||       Y y w xY 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_paramss                    @/usr/lib/python3/dist-packages/cloudinit/config/cc_phone_home.pyhandlerP   l   s   
4yA~Q(s"II6
 \"F;	

 	
-C

65)IJJwE
E
 E!	 ,,.&&(11"""-66H 7:>G ]]_ 	D	--d3HQK K 	=%a[KN!KNKK4	 ##% )A9"'Q"%a&Q	) 	x.J 
!
!#z
2C
##!AI..u{{;	
s 	" 
M	

4  	KKH$	L  
CS%	

s6   G H:H7 ,H	H	$H43H47%II)__doc__loggingtextwrapr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar	   r
   cloudinit.distrosr   cloudinit.settingsr   r   r9   MODULE_DESCRIPTIONr   __annotations__	getLogger__name__r1   r?   listrP        rO   <module>ra      s    #   1 1 ! # < ) +	 < %}	
 		
. !-~=j B t
g!]
 ]
6 ]
% ]
t ]
 ]
r`   