
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
\¼mex  ã            	   @   sì   U d Z ddlZddlZddlmZ ddl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 d
dddgZdZdZdddeeeedƒgg dœZeeeƒZ ejeƒZeee	eddœdd„Zdd„ Zeeedœdd„Z dS )zSSH Import ID: Import SSH idé    N)Údedent)ÚsubpÚutil)ÚCloud)ÚConfig)Ú
MetaSchemaÚget_meta_doc)Úug_util)ÚPER_INSTANCEZalpineZcosZdebianZubuntuzssh-import-ida2  This module imports SSH keys from either a public keyserver, usually launchpad
or github using ``ssh-import-id``. Keys are referenced by the username they are
associated with on the keyserver. The keyserver can be specified by prepending
either ``lp:`` for launchpad or ``gh:`` for github to the username.
Zcc_ssh_import_idzSSH Import IDzImport SSH idzi            ssh_import_id:
             - user
             - gh:user
             - lp:user
            )ÚidÚnameÚtitleÚdescriptionÚdistrosZ	frequencyZexamplesZactivate_by_schema_keys)r   ÚcfgÚcloudÚargsÚreturnc          "   C   s˜  t |dƒstjdƒ d S tjtƒs0tjdƒ d S t|ƒdkrn|d }g }t|ƒdkr`|dd … }t||ƒ d S t	j
||jƒ\}}g }xü|jƒ D ]ð\}}	g }
|	d r²tj|dg ƒ}
n0y|	d }
W n" tk
rà   tjd|ƒ wŽY nX ytj|
ƒ}
dd	„ |
D ƒ}
W n$ tk
�r"   tjd
|ƒ wŽY nX t|
ƒ�s0qŽyt|
|ƒ W qŽ tk
�r| } z tjtd||
ƒ |j|ƒ W Y d d }~X qŽX qŽW t|ƒ�r”|d ‚d S )NZssh_import_idzISkipping module named ssh_import_id, no 'ssh_import_id' directives found.zXssh-import-id is not installed, but module ssh_import_id is configured. Skipping module.r   é   Údefaultz+User %s is not configured for ssh_import_idc             S   s   g | ]}t |ƒ‘qS © )Ústr)Ú.0Úir   r   ú&/usr/lib/python3.6/cc_ssh_import_id.pyú
<listcomp>a   s    zhandle.<locals>.<listcomp>z5User %s is not correctly configured for ssh_import_idzssh-import-id failed for: %s %s)Úis_key_in_nested_dictÚLOGÚdebugr   ÚwhichÚSSH_IMPORT_ID_BINARYZwarningÚlenÚimport_ssh_idsr	   Znormalize_users_groupsZdistroÚitemsr   Zget_cfg_option_listÚ	ExceptionZ
uniq_mergeÚlogexcÚappend)r   r   r   r   ÚuserÚidsZusersZ_groupsZelistZuser_cfgZ
import_idsÚexcr   r   r   Úhandle8   sV    




 
r*   c             C   sò   |o| st jd|| ƒ d S ytj|ƒ W n& tk
rN } z
|‚W Y d d }~X nX tjdƒrnddd|tg|  }n*tjdƒrŠdd|tg|  }nt jdƒ d S t jd|ƒ ytj|d	d
� W n6 tj	k
rì } zt
jt d|ƒ |‚W Y d d }~X nX d S )Nz(empty user(%s) or ids(%s). not importingZsudoz--preserve-env=https_proxyz-HuZdoasz-uz:Neither sudo nor doas available! Unable to import SSH ids.zImporting SSH ids for user %s.F)Zcapturez*Failed to run command to import %s SSH ids)r   r   ÚpwdÚgetpwnamÚKeyErrorr   r   r    ÚerrorZProcessExecutionErrorr   r%   )r(   r'   r)   Úcmdr   r   r   r"   w   s8    


r"   )ÚconfigÚ
search_keyr   c             C   sz   xt| j ƒ D ]h}||krdS t| | tƒr:t| | |ƒr:dS t| | tƒr
x(| | D ]}t|tƒrRt||ƒrRdS qRW q
W dS )z•Search for key nested in config.

    Note: A dict embedded in a list of lists will not be found walked - but in
    this case we don't need it.
    TF)ÚkeysÚ
isinstanceÚdictr   Úlist)r0   r1   Z
config_keyÚitemr   r   r   r   ¶   s    

r   )!Ú__doc__Zloggingr+   Útextwrapr   Z	cloudinitr   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.distrosr	   Zcloudinit.settingsr
   r   r    ZMODULE_DESCRIPTIONÚmetaZ	getLoggerÚ__name__r   r   r5   r*   r"   r4   Úboolr   r   r   r   r   Ú<module>   s4   
??