#NEWLINE# def handle_put_user( self , req ) : #NEWLINE# #INDENT# "Handles the PUT v2/<account>/<user> call for adding a user to an\n        account.\n\n        X-Auth-User-Key represents the user's key (url encoded),\n        X-Auth-User-Admin may be set to `true` to create an account .admin, and\n        X-Auth-User-Reseller-Admin may be set to `true` to create a\n        .reseller_admin.\n\n        Creating users\n        **************\n        Can only be called by an account .admin unless the user is to be a\n        .reseller_admin, in which case the request must be by .super_admin.\n\n        Changing password/key\n        *********************\n        1) reseller_admin key can be changed by super_admin and by himself.\n        2) admin key can be changed by any admin in same account,\n           reseller_admin, super_admin and himself.\n        3) Regular user key can be changed by any admin in his account,\n           reseller_admin, super_admin and himself.\n\n        :param req: The swob.Request to process.\n        :returns: swob.Response, 2xx on success.\n        " #NEWLINE# account = req . path_info_pop ( ) #NEWLINE# user = req . path_info_pop ( ) #NEWLINE# key = unquote ( req . headers . get ( 'x-auth-user-key' , '' ) ) #NEWLINE# admin = ( req . headers . get ( 'x-auth-user-admin' ) == 'true' ) #NEWLINE# reseller_admin = ( req . headers . get ( 'x-auth-user-reseller-admin' ) == 'true' ) #NEWLINE# if reseller_admin : #NEWLINE# #INDENT# admin = True #NEWLINE# #UNINDENT# if ( req . path_info or ( not account ) or ( account [ 0 ] == '.' ) or ( not user ) or ( user [ 0 ] == '.' ) or ( not key ) ) : #NEWLINE# #INDENT# return HTTPBadRequest ( request = req ) #NEWLINE# #UNINDENT# user_arg = ( ( account + ':' ) + user ) #NEWLINE# if reseller_admin : #NEWLINE# #INDENT# if ( ( not self . is_super_admin ( req ) ) and ( not self . is_user_changing_own_key ( req , user_arg ) ) ) : #NEWLINE# #INDENT# return self . denied_response ( req ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not self . is_account_admin ( req , account ) ) and ( not self . is_user_changing_own_key ( req , user_arg ) ) ) : #NEWLINE# #INDENT# return self . denied_response ( req ) #NEWLINE# #UNINDENT# #UNINDENT# path = quote ( ( '/v1/%s/%s' % ( self . auth_account , account ) ) ) #NEWLINE# resp = self . make_pre_authed_request ( req . environ , 'HEAD' , path ) . get_response ( self . app ) #NEWLINE# if ( ( resp . status_int // 100 ) != 2 ) : #NEWLINE# #INDENT# raise Exception ( ( 'Could not retrieve account id value: %s %s' % ( path , resp . status ) ) ) #NEWLINE# #UNINDENT# headers = { #NEWLINE# #INDENT# 'X-Object-Meta-Account-Id' : resp . headers [ 'x-container-meta-account-id' ] , #NEWLINE# #UNINDENT# } #NEWLINE# path = quote ( ( '/v1/%s/%s/%s' % ( self . auth_account , account , user ) ) ) #NEWLINE# groups = [ ( '%s:%s' % ( account , user ) ) , account ] #NEWLINE# if admin : #NEWLINE# #INDENT# groups . append ( '.admin' ) #NEWLINE# #UNINDENT# if reseller_admin : #NEWLINE# #INDENT# groups . append ( '.reseller_admin' ) #NEWLINE# #UNINDENT# auth_value = self . auth_encoder ( ) . encode ( key ) #NEWLINE# resp = self . make_pre_authed_request ( req . environ , 'PUT' , path , json . dumps ( { #NEWLINE# #INDENT# 'auth' : auth_value , #NEWLINE# 'groups' : [ { #NEWLINE# #INDENT# 'name' : g , #NEWLINE# #UNINDENT# } for g in groups ] , #NEWLINE# #UNINDENT# } ) , headers = headers ) . get_response ( self . app ) #NEWLINE# if ( resp . status_int == 404 ) : #NEWLINE# #INDENT# return HTTPNotFound ( request = req ) #NEWLINE# #UNINDENT# if ( ( resp . status_int // 100 ) != 2 ) : #NEWLINE# #INDENT# raise Exception ( ( 'Could not create user object: %s %s' % ( path , resp . status ) ) ) #NEWLINE# #UNINDENT# return HTTPCreated ( request = req )