distil/artifice/api/keystone_api.py
Aurynn Shaw bf671c0210 Moves the artifice web API into the artifice package. Updates the build
system to create a working .deb, based on the makefile.
Adds a new script to start up the web daemon.
Adds a new script to test if the database is provisioned
Adds a new script used by Puppet to provision the database
Adds puppet manifests (mirrored in main puppet)
Moves api/ to artifice/api
Alters some of the relative imports
Moves artifice.py to why_is_this_called_artifice.py, as it was causing
import issues.

Change-Id: Id8a909f7ffcc64a5c4e3281c6b5ba83cef73b596
2014-04-01 16:08:49 +13:00

33 lines
1.0 KiB
Python

from keystoneclient.v2_0 import client
from flask import request
import flask_restful
def validate_user_in_tenancy(tenant_id):
headers = request.headers
if 'user_id' in headers:
user_id = headers['user_id']
endpoint = "http://0.0.0.0:35357/v2.0" # MAJOR TODO
admin_token = "bob" # MAJOR TODO
keystone = client.Client(token=admin_token, endpoint=endpoint)
tenant = keystone.tenants.get(tenant_id)
for user in tenant.list_users():
if user.id == user_id:
return True
return False
else:
flask_restful.abort(403, message=("'user_id' and 'tenant_id' are" +
"required values."))
def keystone_auth_decorator(func):
def wrapper(*args, **kwargs):
if validate_user_in_tenancy(kwargs['id']):
return func(*args, **kwargs)
else:
flask_restful.abort(403, message=("User does not have access" +
"to this tenant."))
return wrapper