
    x[h              
           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
g deg dZeed<    ej&                  e      Zdede	dededdf
dZd ZdededefdZy)zSSH Import ID: Import SSH id    N)subputil)Cloud)Config)
MetaSchema)ug_util)PER_INSTANCEzssh-import-idcc_ssh_import_id)alpinecosdebianubuntu)iddistros	frequencyactivate_by_schema_keysmetanamecfgcloudargsreturnc                    t        |d      st        j                  d       y t        j                  t
              st        j                  d       y |r'|d   }g }t        |      dkD  r|dd  }t        ||       y t        j                  ||j                        \  }}g }|j                         D ]q  \  }}	g }
|	d   rt        j                  |dg       }
n	 |	d   }
	 t        j                   |
      }
|
D cg c]  }t#        |       }
}t        |
      se	 t        |
|       s t        |      r|d   y # t        $ r t        j                  d|       Y w xY wc c}w # t        $ r t        j                  d|       Y w xY w# t        $ r8}t        j$                  t        d	||
       |j'                  |       Y d }~d }~ww xY w)
N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_idz5User %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_BINARYwarninglenimport_ssh_idsr   normalize_users_groupsdistroitemsr   get_cfg_option_list	Exception
uniq_mergestrlogexcappend)r   r   r   r   useridsusers_groupselistuser_cfg
import_idsiexcs                C/usr/lib/python3/dist-packages/cloudinit/config/cc_ssh_import_id.pyhandler8   "   s    o6		!	
 	ZZ,-+	
 	 Awt9q=qr(CsD! 55c5<<HUGE++- h
I11#KJ%o6

	4J*45Q#a&5J5 :	:t,1> 5zAh 1  		GN 6 	IIG 		  	KK6j LL		sN   D5E5EEF5EEEF F	G-G  Gc                    |r| st         j                  d||        y 	 t        j                  |       t        j                  d      rddd|t        g| z   }n9t        j                  d      rdd|t        g| z   }nt         j                  d       y t         j                  d|       	 t        j
                  |d	
       y # t        $ r}|d }~ww xY w# t
        j                  $ r"}t        j                  t         d|       |d }~ww xY w)Nz(empty user(%s) or ids(%s). not importingsudoz--preserve-env=https_proxyz-Hudoasz-uz:Neither sudo nor doas available! Unable to import SSH ids.zImporting SSH ids for user %s.F)capturez*Failed to run command to import %s SSH ids)r   r   pwdgetpwnamKeyErrorr   r    r!   errorProcessExecutionErrorr   r,   )r/   r.   r6   cmds       r7   r$   r$   a   s    S		<dCHT: zz&( 
  
F	 	

  			NOII.5		#u%c  	d %% CEtL	s/   B? 'C ?	CC

CD%DDconfig
search_keyc                     | j                         D ]k  }||k(  r yt        | |   t              rt        | |   |      r yt        | |   t              sB| |   D ]"  }t        |t              st        ||      s!  y m y)zSearch 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)rC   rD   
config_keyitems       r7   r   r      s     kkm $
#fZ($/$VJ%7DfZ($/ z* $dD),T:>#$$     )__doc__loggingr=   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr   cloudinit.settingsr	   r!   r   __annotations__	getLogger__name__r   r+   rI   r8   r$   rH   boolr    rL   r7   <module>rZ      s    #  
   ! # . % + '  4!	j  g!< <6 <% <t < <~<~$ C D rL   