U
    Ad1                     @   sH   d dl Z d dlZd dlmZmZ dddZdddZeed	d
dZdS )    N)
url_helperutil      c                 C   s6   t j| |||d}| s&td|  t|j S )Ntimeoutsec_betweenretrieszunable to read metadata at %s)r   readurlokRuntimeErrorr   Z	load_yamlcontentsdecodeZurlr   r   r	   Zresponse r   C/usr/lib/python3/dist-packages/cloudinit/sources/helpers/hetzner.pyread_metadata   s       r   c                 C   s,   t j| |||d}| s&td|  |jS )Nr   zunable to read userdata at %s)r   r
   r   r   r   r   r   r   r   read_userdata   s       r   )datareturnc                 C   sJ   t | tstdt|  ztj| ddW S  tjk
rD   |  Y S X dS )zbase64 decode data

    If data is base64 encoded bytes, return b64decode(data).
    If not, return data unmodified.

    @param data: data as bytes. TypeError is raised if not bytes.
    zdata is '%s', expected bytesT)ZvalidateN)
isinstancebytes	TypeErrortypebase64Z	b64decodebinasciiError)r   r   r   r   maybe_b64decode   s    
r   )r   r   r   )r   r   r   )	r   r   Z	cloudinitr   r   r   r   r   r   r   r   r   r   <module>   s
   
	
	