#NEWLINE# def retrieve_auth_entries( u = None ) : #NEWLINE# #INDENT# '\n\n    :param u: Username to filter for\n    :return: Dictionary that can be slotted into the ``__opts__`` structure for\n        eauth that designates the user associated ACL\n\n    Database records such as:\n\n    ===========  ====================     =========\n    username     minion_or_fn_matcher     minion_fn\n    ===========  ====================     =========\n    fred                                  test.ping\n    fred         server1                  network.interfaces\n    fred         server1                  raid.list\n    fred         server2                  .*\n    guru         .*\n    smartadmin   server1                  .*\n    ===========  ====================     =========\n\n    Should result in an eauth config such as:\n\n    .. code-block:: yaml\n\n        fred:\n          - test.ping\n          - server1:\n              - network.interfaces\n              - raid.list\n          - server2:\n              - .*\n        guru:\n          - .*\n        smartadmin:\n          - server1:\n            - .*\n\n    ' #NEWLINE# django_auth_setup ( ) #NEWLINE# if ( u is None ) : #NEWLINE# #INDENT# db_records = DJANGO_AUTH_CLASS . objects . all ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# db_records = DJANGO_AUTH_CLASS . objects . filter ( user_fk__username = u ) #NEWLINE# #UNINDENT# auth_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for a in db_records : #NEWLINE# #INDENT# if ( a . user_fk . username not in auth_dict ) : #NEWLINE# #INDENT# auth_dict [ a . user_fk . username ] = [ ] #NEWLINE# #UNINDENT# if ( ( not a . minion_or_fn_matcher ) and a . minion_fn ) : #NEWLINE# #INDENT# auth_dict [ a . user_fk . username ] . append ( a . minion_fn ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( a . minion_or_fn_matcher and ( not a . minion_fn ) ) : #NEWLINE# #INDENT# auth_dict [ a . user_fk . username ] . append ( a . minion_or_fn_matcher ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# found = False #NEWLINE# for d in auth_dict [ a . user_fk . username ] : #NEWLINE# #INDENT# if isinstance ( d , dict ) : #NEWLINE# #INDENT# if ( a . minion_or_fn_matcher in six . iterkeys ( d ) ) : #NEWLINE# #INDENT# auth_dict [ a . user_fk . username ] [ a . minion_or_fn_matcher ] . append ( a . minion_fn ) #NEWLINE# found = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not found ) : #NEWLINE# #INDENT# auth_dict [ a . user_fk . username ] . append ( { #NEWLINE# #INDENT# a . minion_or_fn_matcher : [ a . minion_fn ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# log . debug ( 'django auth_dict is {0}' . format ( repr ( auth_dict ) ) ) #NEWLINE# return auth_dict