<s> """<STR_LIT>""" <EOL> import lxml . etree <EOL> import Bcfg2 . Options <EOL> from Bcfg2 . Server . Plugin import StructFile , PluginExecutionError <EOL> from Bcfg2 . Server . Plugins . Cfg import CfgGenerator , get_cfg <EOL> from Bcfg2 . Server . Plugins . Metadata import ClientMetadata <EOL> class CfgAuthorizedKeysGenerator ( CfgGenerator , StructFile ) : <EOL> """<STR_LIT>""" <EOL> __specific__ = False <EOL> __basenames__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , fname ) : <EOL> CfgGenerator . __init__ ( self , fname , None ) <EOL> StructFile . __init__ ( self , fname ) <EOL> self . cache = dict ( ) <EOL> self . core = get_cfg ( ) . core <EOL> __init__ . __doc__ = CfgGenerator . __init__ . __doc__ <EOL> def handle_event ( self , event ) : <EOL> CfgGenerator . handle_event ( self , event ) <EOL> StructFile . HandleEvent ( self , event ) <EOL> self . cache = dict ( ) <EOL> handle_event . __doc__ = CfgGenerator . handle_event . __doc__ <EOL> def get_data ( self , entry , metadata ) : <EOL> spec = self . XMLMatch ( metadata ) <EOL> rv = [ ] <EOL> for allow in spec . findall ( "<STR_LIT>" ) : <EOL> options = [ ] <EOL> for opt in allow . findall ( "<STR_LIT>" ) : <EOL> if opt . get ( "<STR_LIT:value>" ) : <EOL> options . append ( "<STR_LIT>" % ( opt . get ( "<STR_LIT:name>" ) , <EOL> opt . get ( "<STR_LIT:value>" ) ) ) <EOL> else : <EOL> options . append ( opt . get ( "<STR_LIT:name>" ) ) <EOL> pubkey_name = allow . get ( "<STR_LIT>" ) <EOL> if pubkey_name : <EOL> host = allow . get ( "<STR_LIT:host>" ) <EOL> group = allow . get ( "<STR_LIT>" ) <EOL> category = allow . get ( "<STR_LIT>" , <EOL> Bcfg2 . Options . setup . sshkeys_category ) <EOL> if host : <EOL> key_md = self . core . build_metadata ( host ) <EOL> elif group : <EOL> key_md = ClientMetadata ( "<STR_LIT>" , group , [ group ] , [ ] , <EOL> set ( ) , set ( ) , dict ( ) , None , <EOL> None , None , None ) <EOL> elif category and not metadata . group_in_category ( category ) : <EOL> self . logger . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( metadata . hostname , pubkey_name , <EOL> category ) ) <EOL> continue <EOL> else : <EOL> key_md = metadata <EOL> key_entry = lxml . etree . Element ( "<STR_LIT>" , name = pubkey_name ) <EOL> try : <EOL> self . core . Bind ( key_entry , key_md ) <EOL> except PluginExecutionError : <EOL> self . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( metadata . hostname , <EOL> pubkey_name ) ) <EOL> continue <EOL> if not key_entry . text : <EOL> self . logger . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( metadata . hostname , pubkey_name ) ) <EOL> continue <EOL> pubkey = key_entry . text <EOL> elif allow . text : <EOL> pubkey = allow . text . strip ( ) <EOL> else : <EOL> self . logger . warning ( "<STR_LIT>" % <EOL> ( metadata . hostname , <EOL> lxml . etree . tostring ( allow ) ) ) <EOL> continue <EOL> rv . append ( "<STR_LIT:U+0020>" . join ( [ "<STR_LIT:U+002C>" . join ( options ) , pubkey ] ) . strip ( ) ) <EOL> return "<STR_LIT:\n>" . join ( rv ) <EOL> get_data . __doc__ = CfgGenerator . get_data . __doc__ </s>
