o
    iZ                  
   @   s   U d Z ddlZddlZddl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 d	Zd
dgeg dZeed< eeZdd Zdede	dededdf
ddZdS )zFKeys to Console: Control which SSH host keys may be written to console    N)subputil)Cloud)Config)
MetaSchema)log_util)PER_INSTANCEz(%s/cloud-init/write-ssh-key-fingerprintscc_keys_to_consoleall)iddistros	frequencyactivate_by_schema_keysmetac                 C   s.   z| j }W t| S  ty   d}Y t| S w )Nz/usr/lib)usr_lib_execAttributeErrorHELPER_TOOL_TPL)distrobase_lib r   E/usr/lib/python3/dist-packages/cloudinit/config/cc_keys_to_console.py_get_helper_tool_path"   s   r   namecfgcloudargsreturnc           
      C   s   t |di ddrtd|  d S t|j}tj	|s)t
d| | d S t |dg }t |dg }z!|d|d|g}t|\}}	tjd	|  d
dd W d S  tye   t
d  w )Nsshemit_keys_to_consoleTz;Skipping module named %s, logging of SSH host keys disabledz9Unable to activate module %s, helper tool not found at %sssh_fp_console_blacklistssh_key_console_blacklist,z%s
F)stderrconsolez*Writing keys to the system console failed!)r   is_falsegetLOGdebugr   r   ospathexistswarningget_cfg_option_listjoinr   r   	multi_logstrip	Exception)
r   r   r   r   helper_pathfp_blacklistkey_blacklistcmdstdout_stderrr   r   r   handle*   s:   

r7   )__doc__loggingr(   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.logr   cloudinit.settingsr   r   r   __annotations__	getLogger__name__r&   r   strlistr7   r   r   r   r   <module>   s$   
"