Sai and Praveena's Changes

This commit is contained in:
Ramana Juvvadi 2011-05-10 17:11:31 -05:00
parent 3b1cdf2ab3
commit f7f36ee979
5 changed files with 99 additions and 59 deletions

49
etc/logging.cnf Normal file
View File

@ -0,0 +1,49 @@
[loggers]
keys=root,keystone,combined
[formatters]
keys=normal,normal_with_name,debug
[handlers]
keys=production,file,devel
[logger_root]
level=NOTSET
handlers=devel
[logger_keystone]
level=DEBUG
handlers=devel
qualname=keystone
[logger_combined]
level=DEBUG
handlers=devel
qualname=keystone-combined
[handler_production]
class=handlers.SysLogHandler
level=ERROR
formatter=normal_with_name
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
[handler_file]
class=FileHandler
level=DEBUG
formatter=normal_with_name
args=('keystone.log', 'w')
[handler_devel]
class=StreamHandler
level=NOTSET
formatter=debug
args=(sys.stdout,)
[formatter_normal]
format=%(asctime)s %(levelname)s %(message)s
[formatter_normal_with_name]
format=(%(name)s): %(asctime)s %(levelname)s %(message)s
[formatter_debug]
format=(%(name)s): %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s

View File

@ -66,6 +66,8 @@ import keystone.logic.types.fault as fault
import keystone.logic.types.user as users
import keystone.common.template as template
# Shall give [app:auth_server paste value from conf file ]
logger = logging.getLogger('keystone.auth_server')
VERSION_STATUS = "ALPHA"
VERSION_DATE = "2011-04-23T00:00:00Z"
@ -93,11 +95,8 @@ def get_auth_token(req):
def wrap_error(func):
@functools.wraps(func)
def check_error(*args, **kwargs):
print '>>>>>>>>>>>>>>>>>>..'
try:
return func(*args, **kwargs)
except Exception as err:
if isinstance(err, fault.IDMFault):
return send_error(err.code, kwargs['req'], err)
@ -109,39 +108,34 @@ def wrap_error(func):
def get_normalized_request_content(model, req):
"""initialize a model from json/xml contents of request body"""
if req.content_type == "application/xml":
ret = model.from_xml(req.body)
elif req.content_type == "application/json":
ret = model.from_json(req.body)
else:
raise fault.IDMFault("I don't understand the content type ", code=415)
return ret
def send_error(code, req, result):
content = None
resp = Response()
resp.headers['content-type'] = None
resp.status = code
if result:
if is_xml_response(req):
content = result.to_xml()
resp.headers['content-type'] = "application/xml"
else:
content = result.to_json()
resp.headers['content-type'] = "application/json"
resp.content_type_params={'charset' : 'UTF-8'}
resp.unicode_body = content.decode('UTF-8')
return resp
@ -152,9 +146,9 @@ def send_result(code, req, result):
resp.status = code
if code > 399:
return resp
if result:
if is_xml_response(req):
content = result.to_xml()
resp.headers['content-type'] = "application/xml"
@ -171,7 +165,7 @@ class StaticFilesController(wsgi.Controller):
def __init__(self, options):
self.options = options
@wrap_error
def get_pdf_contract(self, req):
resp = Response()
@ -204,10 +198,10 @@ class MiscController(wsgi.Controller):
def __init__(self, options):
self.options = options
@wrap_error
def get_version_info(self, req):
resp = Response()
resp.charset = 'UTF-8'
if is_xml_response(req):
@ -234,24 +228,24 @@ class AuthController(wsgi.Controller):
def __init__(self, options):
self.options = options
self.request = None
@wrap_error
def authenticate(self, req):
self.request = req
creds = get_normalized_request_content(auth.PasswordCredentials, req)
return send_result(200, req, service.authenticate(creds))
@wrap_error
def validate_token(self, req, token_id):
belongs_to = None
if "belongsTo" in req.GET:
belongs_to = req.GET["belongsTo"]
rval = service.validate_token(get_auth_token(req), token_id, belongs_to)
return send_result(200, req, rval)
@wrap_error
def delete_token(self, req, token_id):
return send_result(204, req, service.revoke_token(get_auth_token(req), token_id))
@ -261,13 +255,13 @@ class TenantController(wsgi.Controller):
def __init__(self, options):
self.options = options
@wrap_error
def create_tenant(self, req):
tenant = get_normalized_request_content(tenants.Tenant, req)
return send_result(201, req,
service.create_tenant(get_auth_token(req), tenant))
@wrap_error
def get_tenants(self, req):
marker = None
@ -286,13 +280,13 @@ class TenantController(wsgi.Controller):
tenants = service.get_tenants(get_auth_token(req), marker, limit, url)
return send_result(200, req, tenants)
@wrap_error
def get_tenant(self, req, tenant_id):
tenant = service.get_tenant(get_auth_token(req), tenant_id)
return send_result(200, req, tenant)
@wrap_error
def update_tenant(self, req, tenant_id):
tenant = get_normalized_request_content(tenants.Tenant, req)
@ -345,7 +339,7 @@ class TenantController(wsgi.Controller):
rval = service.update_tenant_group(get_auth_token(req),\
tenant_id, group_id, group)
return send_result(200, req, rval)
@wrap_error
def delete_tenant_group(self, req, tenant_id, group_id):
rval = service.delete_tenant_group(get_auth_token(req), tenant_id,
@ -357,19 +351,20 @@ class TenantController(wsgi.Controller):
# TBD
# IDMDevguide clarification needed on this property
return None
@wrap_error
def delete_user_tenant_group(self, req, tenant_id, group_id, user_id):
# TBD
# IDMDevguide clarification needed on this property
return None
@wrap_error
def get_user_tenant_group(self, req, tenant_id, group_id, user_id):
# TBD
# IDMDevguide clarification needed on this property
return None
class UserController(wsgi.Controller):
def __init__(self, options):
@ -396,7 +391,7 @@ class UserController(wsgi.Controller):
req.environ['PATH_INFO'])
users = service.get_tenant_users(get_auth_token(req), tenant_id, marker, limit, url)
return send_result(200, req, users)
@wrap_error
def get_user_groups(self, req, tenant_id, user_id):
marker = None
@ -415,23 +410,23 @@ class UserController(wsgi.Controller):
groups = service.get_user_groups(get_auth_token(),
tenant_id,user_id, marker, limit,url)
return send_result(200, groups)
@wrap_error
def get_user(self, req, tenant_id, user_id):
user = service.get_user(get_auth_token(req), tenant_id, user_id)
return send_result(200, req, user)
@wrap_error
def update_user(self, req, user_id, tenant_id):
user = get_normalized_request_content(users.User_Update, req)
rval = service.update_user(get_auth_token(req), user_id, user, tenant_id)
return send_result(200, req, rval)
@wrap_error
def delete_user(self, req, user_id, tenant_id):
rval = service.delete_user(get_auth_token(req), user_id, tenant_id)
return send_result(204, req, rval)
@wrap_error
def set_user_password(self, req, user_id, tenant_id):
user = get_normalized_request_content(users.User_Update, req)
@ -446,10 +441,9 @@ class UserController(wsgi.Controller):
return send_result(204, req, rval)
class GroupsController(wsgi.Controller):
def __init__(self, options):
self.options = options
@ -477,24 +471,24 @@ class GroupsController(wsgi.Controller):
groups = service.get_global_groups(get_auth_token(req),
marker, limit, url)
return send_result(200, req, groups)
@wrap_error
def get_group(self, req, group_id):
tenant = service.get_global_group(get_auth_token(req), group_id)
return send_result(200, req, tenant)
@wrap_error
def update_group(self, req, group_id):
group = get_normalized_request_content(tenants.Group, req)
rval = service.update_global_group(get_auth_token(req),
group_id, group)
return send_result(200, req, rval)
@wrap_error
def delete_group(self, req, group_id):
rval = service.delete_global_group(get_auth_token(req), group_id)
return send_result(204, req, rval)
@wrap_error
def get_users_group(self, req, group_id):
marker = None
@ -608,25 +602,24 @@ class KeystoneAPI(wsgi.Router):
action="get_users_group", conditions=dict(method=["GET"]))
# Miscellaneous Operations
misc_controller = MiscController(options)
mapper.connect("/v1.0/", controller=misc_controller,
mapper.connect("/v1.0/", controller=misc_controller,
action="get_version_info",conditions=dict(method=["GET"]))
mapper.connect("/v1.0", controller=misc_controller,
mapper.connect("/v1.0", controller=misc_controller,
action="get_version_info",conditions=dict(method=["GET"]))
# Static Files Controller
static_files_controller = StaticFilesController(options)
mapper.connect("/v1.0/idmdevguide.pdf", controller=static_files_controller,
action="get_pdf_contract",conditions=dict(method=["GET"]))
mapper.connect("/v1.0/identity.wadl", controller=static_files_controller,
action="get_identity_wadl",conditions=dict(method=["GET"]))
mapper.connect("/v1.0/xsd/{xsd}", controller=static_files_controller,
action="get_pdf_contract",conditions=dict(method=["GET"]))
mapper.connect("/v1.0/xsd/atom/{xsd}", controller=static_files_controller,
action="get_pdf_contract",conditions=dict(method=["GET"]))
mapper.connect("/v1.0/idmdevguide.pdf", controller=static_files_controller,
action="get_pdf_contract", conditions=dict(method=["GET"]))
mapper.connect("/v1.0/identity.wadl", controller=static_files_controller,
action="get_wadl_contract", conditions=dict(method=["GET"]))
mapper.connect("/v1.0/xsd/{xsd}", controller=static_files_controller,
action="get_xsd_contract", conditions=dict(method=["GET"]))
mapper.connect("/v1.0/xsd/atom/{xsd}", controller=static_files_controller,
action="get_xsd_atom_contract", conditions=dict(method=["GET"]))
super(KeystoneAPI, self).__init__(mapper)
def app_factory(global_conf, **local_conf):

View File

@ -123,7 +123,6 @@ def setup_logging(options, conf):
:param options: Mapping of typed option key/values
:param conf: Mapping of untyped key/values from config file
"""
if options.get('log_config', None):
# Use a logging configuration file for all settings...
if os.path.exists(options['log_config']):

View File

@ -29,7 +29,6 @@ from sqlalchemy.orm import sessionmaker
_ENGINE = None
_MAKER = None
def get_connection_string():
path = os.path.realpath(__file__)
dbpath = os.path.normpath(os.path.join(path,

View File

@ -12,7 +12,7 @@ from lxml import etree
import unittest
from webtest import TestApp
URL = 'http://localhost:8080/v1.0/'
URL = 'http://localhost:8900/v1.0/'
def get_token(user, pswd, kind=''):