#NEWLINE# def user_present( name , policies = None , policies_from_pillars = None , managed_policies = None , password = None , path = None , region = None , key = None , keyid = None , profile = None ) : #NEWLINE# #INDENT# "\n\n    .. versionadded:: 2015.8.0\n\n    Ensure the IAM user is present\n\n    name (string)\n        The name of the new user.\n\n    policies (dict)\n        A dict of IAM group policy documents.\n\n    policies_from_pillars (list)\n        A list of pillars that contain role policy dicts. Policies in the\n        pillars will be merged in the order defined in the list and key\n        conflicts will be handled by later defined keys overriding earlier\n        defined keys. The policies defined here will be merged with the\n        policies defined in the policies argument. If keys conflict, the keys\n        in the policies argument will override the keys defined in\n        policies_from_pillars.\n\n    managed_policies (list)\n        A list of managed policy names or ARNs that should be attached to this\n        user.\n\n    password (string)\n        The password for the new user. Must comply with account policy.\n\n    path (string)\n        The path of the user. Default is '/'.\n\n        .. versionadded:: 2015.8.2\n\n    region (string)\n        Region to connect to.\n\n    key (string)\n        Secret key to be used.\n\n    keyid (string)\n        Access key to be used.\n\n    profile (dict)\n        A dict with region, key and keyid, or a pillar key (string)\n        that contains a dict with region, key and keyid.\n    " #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# if ( not policies ) : #NEWLINE# #INDENT# policies = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( not policies_from_pillars ) : #NEWLINE# #INDENT# policies_from_pillars = [ ] #NEWLINE# #UNINDENT# if ( not managed_policies ) : #NEWLINE# #INDENT# managed_policies = [ ] #NEWLINE# #UNINDENT# _policies = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for policy in policies_from_pillars : #NEWLINE# #INDENT# _policy = __salt__ [ 'pillar.get' ] ( policy ) #NEWLINE# _policies . update ( _policy ) #NEWLINE# #UNINDENT# _policies . update ( policies ) #NEWLINE# exists = __salt__ [ 'boto_iam.get_user' ] ( name , region , key , keyid , profile ) #NEWLINE# if ( not exists ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'comment' ] = 'IAM user {0} is set to be created.' . format ( name ) #NEWLINE# ret [ 'result' ] = None #NEWLINE# return ret #NEWLINE# #UNINDENT# created = __salt__ [ 'boto_iam.create_user' ] ( name , path , region , key , keyid , profile ) #NEWLINE# if created : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'user' ] = created #NEWLINE# ret [ 'comment' ] = os . linesep . join ( [ ret [ 'comment' ] , 'User {0} has been created.' . format ( name ) ] ) #NEWLINE# if password : #NEWLINE# #INDENT# ret = _case_password ( ret , name , password , region , key , keyid , profile ) #NEWLINE# #UNINDENT# _ret = _user_policies_present ( name , _policies , region , key , keyid , profile ) #NEWLINE# ret [ 'changes' ] = dictupdate . update ( ret [ 'changes' ] , _ret [ 'changes' ] ) #NEWLINE# ret [ 'comment' ] = ' ' . join ( [ ret [ 'comment' ] , _ret [ 'comment' ] ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] = os . linesep . join ( [ ret [ 'comment' ] , 'User {0} is present.' . format ( name ) ] ) #NEWLINE# if password : #NEWLINE# #INDENT# ret = _case_password ( ret , name , password , region , key , keyid , profile ) #NEWLINE# #UNINDENT# _ret = _user_policies_present ( name , _policies , region , key , keyid , profile ) #NEWLINE# ret [ 'changes' ] = dictupdate . update ( ret [ 'changes' ] , _ret [ 'changes' ] ) #NEWLINE# ret [ 'comment' ] = ' ' . join ( [ ret [ 'comment' ] , _ret [ 'comment' ] ] ) #NEWLINE# #UNINDENT# _ret = _user_policies_attached ( name , managed_policies , region , key , keyid , profile ) #NEWLINE# ret [ 'changes' ] = dictupdate . update ( ret [ 'changes' ] , _ret [ 'changes' ] ) #NEWLINE# ret [ 'comment' ] = ' ' . join ( [ ret [ 'comment' ] , _ret [ 'comment' ] ] ) #NEWLINE# if ( not _ret [ 'result' ] ) : #NEWLINE# #INDENT# ret [ 'result' ] = _ret [ 'result' ] #NEWLINE# return ret #NEWLINE# #UNINDENT# return ret