#NEWLINE# def _user_policies_present( name , policies = None , region = None , key = None , keyid = None , profile = None ) : #NEWLINE# #INDENT# ret = { #NEWLINE# #INDENT# 'result' : True , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# policies_to_create = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# policies_to_delete = [ ] #NEWLINE# for ( policy_name , policy ) in six . iteritems ( policies ) : #NEWLINE# #INDENT# if isinstance ( policy , string_types ) : #NEWLINE# #INDENT# dict_policy = json . loads ( policy , object_pairs_hook = odict . OrderedDict ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dict_policy = policy #NEWLINE# #UNINDENT# _policy = __salt__ [ 'boto_iam.get_user_policy' ] ( name , policy_name , region , key , keyid , profile ) #NEWLINE# if ( _policy != dict_policy ) : #NEWLINE# #INDENT# policies_to_create [ policy_name ] = policy #NEWLINE# #UNINDENT# #UNINDENT# _list = __salt__ [ 'boto_iam.get_all_user_policies' ] ( user_name = name , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# for policy_name in _list : #NEWLINE# #INDENT# if ( policy_name not in policies ) : #NEWLINE# #INDENT# policies_to_delete . append ( policy_name ) #NEWLINE# #UNINDENT# #UNINDENT# if ( policies_to_create or policies_to_delete ) : #NEWLINE# #INDENT# _to_modify = list ( policies_to_delete ) #NEWLINE# _to_modify . extend ( policies_to_create ) #NEWLINE# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# msg = '{0} policies to be modified on user {1}.' #NEWLINE# ret [ 'comment' ] = msg . format ( ', ' . join ( _to_modify ) , name ) #NEWLINE# ret [ 'result' ] = None #NEWLINE# return ret #NEWLINE# #UNINDENT# ret [ 'changes' ] [ 'old' ] = { #NEWLINE# #INDENT# 'policies' : _list , #NEWLINE# #UNINDENT# } #NEWLINE# for ( policy_name , policy ) in six . iteritems ( policies_to_create ) : #NEWLINE# #INDENT# policy_set = __salt__ [ 'boto_iam.put_user_policy' ] ( name , policy_name , policy , region , key , keyid , profile ) #NEWLINE# if ( not policy_set ) : #NEWLINE# #INDENT# _list = __salt__ [ 'boto_iam.get_all_user_policies' ] ( user_name = name , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# ret [ 'changes' ] [ 'new' ] = { #NEWLINE# #INDENT# 'policies' : _list , #NEWLINE# #UNINDENT# } #NEWLINE# ret [ 'result' ] = False #NEWLINE# msg = 'Failed to add policy {0} for user {1}' #NEWLINE# ret [ 'comment' ] = msg . format ( policy_name , name ) #NEWLINE# return ret #NEWLINE# #UNINDENT# #UNINDENT# for policy_name in policies_to_delete : #NEWLINE# #INDENT# policy_unset = __salt__ [ 'boto_iam.delete_user_policy' ] ( name , policy_name , region , key , policy_set , profile ) #NEWLINE# if ( not policy_unset ) : #NEWLINE# #INDENT# _list = __salt__ [ 'boto_iam.get_all_user_policies' ] ( user_name = name , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# ret [ 'changes' ] [ 'new' ] = { #NEWLINE# #INDENT# 'policies' : _list , #NEWLINE# #UNINDENT# } #NEWLINE# ret [ 'result' ] = False #NEWLINE# msg = 'Failed to add policy {0} to user {1}' #NEWLINE# ret [ 'comment' ] = msg . format ( policy_name , name ) #NEWLINE# return ret #NEWLINE# #UNINDENT# #UNINDENT# _list = __salt__ [ 'boto_iam.get_all_user_policies' ] ( user_name = name , region = region , key = key , keyid = keyid , profile = profile ) #NEWLINE# ret [ 'changes' ] [ 'new' ] = { #NEWLINE# #INDENT# 'policies' : _list , #NEWLINE# #UNINDENT# } #NEWLINE# msg = '{0} policies modified on user {1}.' #NEWLINE# ret [ 'comment' ] = msg . format ( ', ' . join ( _list ) , name ) #NEWLINE# #UNINDENT# return ret