#NEWLINE# def AccountDataToDictionary( data ) : #NEWLINE# #INDENT# "Given SSH key data, construct a usermap.\n\n  Args:\n    data: The data returned from the metadata server's SSH key attributes.\n\n  Returns:\n    A map of {'username': ssh_keys_list}.\n  " #NEWLINE# if ( not data ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# lines = [ line for line in data . splitlines ( ) if line ] #NEWLINE# usermap = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for line in lines : #NEWLINE# #INDENT# split_line = line . split ( ':' , 1 ) #NEWLINE# if ( len ( split_line ) != 2 ) : #NEWLINE# #INDENT# logging . warning ( 'SSH key is not a complete entry: %s' , split_line ) #NEWLINE# continue #NEWLINE# #UNINDENT# ( user , key ) = split_line #NEWLINE# if KeyHasExpired ( key ) : #NEWLINE# #INDENT# logging . debug ( 'Skipping expired SSH key for user %s: %s' , user , line ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( user not in usermap ) : #NEWLINE# #INDENT# usermap [ user ] = [ ] #NEWLINE# #UNINDENT# usermap [ user ] . append ( key ) #NEWLINE# #UNINDENT# logging . debug ( 'User accounts: %s' , usermap ) #NEWLINE# return usermap