def create_user_with_key():
"""
Create a user directory with a keyfile on the shared volume, data
arriving in the payload of the request with a JSON payload.
"""
username = username_from_request(request)
if not username:
response.status = 422
return {'error': "Parameter 'username' not specified"}
elif not username_valid(username):
response.status = 400
return {'error':
"Invalid parameter 'username': '{0}' not allowed.".
format(username)
}
pubkey = request.json.get('pubkey')
if not pubkey:
response.status = 422
return {'error': "Parameter 'pubkey' not specified"}
abs_home_path = normpath(os.path.join(HOME_PATH_PREFIX, username))
username_was_added = check_and_add(username)
# Do the actual creation
store_pubkey(username, abs_home_path, pubkey)
response.status = 201
return {'response':
'Successful creation of user {0} and/or upload of key.'
.format(username)}
评论列表
文章目录