summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYogeshwar Srikrishnan <yoga80@yahoo.com>2011-06-09 00:16:58 -0500
committerYogeshwar Srikrishnan <yoga80@yahoo.com>2011-06-09 00:16:58 -0500
commit38c2f72090e71e2376996fb3f5cf8b30aa59508f (patch)
tree0d0811dafbdf2c97b309c5508fc84f12bcd9fd09
parentce24b59f91370e1eae2729bacd13a99a3fd343d7 (diff)
downloadkeystone-38c2f72090e71e2376996fb3f5cf8b30aa59508f.tar.gz
keystone-38c2f72090e71e2376996fb3f5cf8b30aa59508f.tar.xz
keystone-38c2f72090e71e2376996fb3f5cf8b30aa59508f.zip
PEP8 changes.
-rwxr-xr-xbin/keystone14
-rwxr-xr-xbin/keystone-auth7
-rwxr-xr-xkeystone/common/config.py12
-rwxr-xr-xkeystone/db/sqlalchemy/api.py8
-rwxr-xr-x[-rw-r--r--]keystone/frontends/legacy_auth_frontend.py27
-rwxr-xr-xkeystone/logic/types/auth.py29
-rwxr-xr-xtest/unit/test_authentication.py15
7 files changed, 59 insertions, 53 deletions
diff --git a/bin/keystone b/bin/keystone
index ef4dfefc..f120bbed 100755
--- a/bin/keystone
+++ b/bin/keystone
@@ -33,8 +33,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')):
sys.path.insert(0, possible_topdir)
-
-import tools.tracer #load this first
+#load this first
+import tools.tracer
import keystone
from keystone.common import config
from keystone.common import wsgi
@@ -49,12 +49,12 @@ if __name__ == '__main__':
# Handle a special argument to support starting two endpoints
common_group.add_option('-a', '--admin-port', default=8081,
dest="admin_port", metavar="PORT",
- help = "specifies port for Admin API to listen"
+ help="specifies port for Admin API to listen"
"on (default is 8081)")
common_group.add_option('-r', '--rackspace-legacy-port', default=8082,
dest="rackspace_legacy_port", metavar="PORT",
- help = "specifies port for Rackspace Legacy API to listen"
+ help="specifies port for Rackspace Legacy API to listen"
"on (default is 8082)")
# Parse arguments and load config
@@ -63,7 +63,8 @@ if __name__ == '__main__':
# Start services
try:
# Load Service API server
- conf, app = config.load_paste_app('keystone-legacy-auth', options, args)
+ conf, app = config.load_paste_app(
+ 'keystone-legacy-auth', options, args)
debug = options.get('debug') or conf.get('debug', False)
debug = debug in [True, "True", "1"]
@@ -74,7 +75,8 @@ if __name__ == '__main__':
print "Using config file:", config_file
server = wsgi.Server()
- server.start(app, int(conf['server_bind_port']), conf['server_bind_host'])
+ server.start(app, int(conf['server_bind_port']),
+ conf['server_bind_host'])
print "Service API listening on %s:%s" % (conf['server_bind_host'],
conf['server_bind_port'])
diff --git a/bin/keystone-auth b/bin/keystone-auth
index ea81c769..6159d3ab 100755
--- a/bin/keystone-auth
+++ b/bin/keystone-auth
@@ -33,8 +33,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')):
sys.path.insert(0, possible_topdir)
-
-import tools.tracer #load this first
+#load this first
+import tools.tracer
import keystone
from keystone.common import config
from keystone.common import wsgi
@@ -62,7 +62,8 @@ if __name__ == '__main__':
# Load Service API server
conf, app = config.load_paste_app('server', options, args)
server = wsgi.Server()
- server.start(app, int(conf['server_bind_port']), conf['server_bind_host'])
+ server.start(app, int(conf['server_bind_port']),
+ conf['server_bind_host'])
print "Service API listening on %s:%s" % (conf['bind_host'],
conf['bind_port'])
server.wait()
diff --git a/keystone/common/config.py b/keystone/common/config.py
index ed8cb228..34281192 100755
--- a/keystone/common/config.py
+++ b/keystone/common/config.py
@@ -227,7 +227,7 @@ def find_config_file(options, args):
We search for the paste config file in the following order:
* If --config-file option is used, use that
* If args[0] is a file, use that
- * Search for config file in standard directories:
+ * Search for keystone.conf in standard directories:
* .
* ~.keystone/
* ~
@@ -242,16 +242,14 @@ def find_config_file(options, args):
os.pardir,
os.pardir))
fix_path = lambda p: os.path.abspath(os.path.expanduser(p))
- file_name = 'keystone.conf'
if options.get('config_file'):
- file_name = options.get('config_file')
if os.path.exists(options['config_file']):
return fix_path(options['config_file'])
elif args:
if os.path.exists(args[0]):
return fix_path(args[0])
- # Handle standard directory search for keystone.conf or passed conf file.
+ # Handle standard directory search for keystone.conf
config_file_dirs = [fix_path(os.getcwd()),
fix_path(os.path.join('~', '.keystone')),
fix_path('~'),
@@ -259,15 +257,15 @@ def find_config_file(options, args):
'/etc']
for cfg_dir in config_file_dirs:
- cfg_file = os.path.join(cfg_dir, file_name)
+ cfg_file = os.path.join(cfg_dir, 'keystone.conf')
if os.path.exists(cfg_file):
return cfg_file
else:
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'etc', \
- file_name)):
+ 'keystone.conf')):
# For debug only
config_file = os.path.join(POSSIBLE_TOPDIR, 'etc', \
- file_name)
+ 'keystone.conf')
return config_file
diff --git a/keystone/db/sqlalchemy/api.py b/keystone/db/sqlalchemy/api.py
index 70094f4b..df1d4d4e 100755
--- a/keystone/db/sqlalchemy/api.py
+++ b/keystone/db/sqlalchemy/api.py
@@ -1213,12 +1213,12 @@ def baseurls_ref_delete(id, session=None):
baseurls_ref = baseurls_ref_get(id, session)
session.delete(baseurls_ref)
+
def tenant_baseurls_get_all(tenant_id, session=None):
if not session:
session = get_session()
tba = aliased(models.TenantBaseURLAssociation)
baseUrls = aliased(models.BaseUrls)
- return session.query(baseUrls).join((tba, tba.baseURLs_id == baseUrls.id)).\
- filter(tba.tenant_id == tenant_id).all()
-
-
+ return session.query(baseUrls).join((tba,
+ tba.baseURLs_id == baseUrls.id)).\
+ filter(tba.tenant_id == tenant_id).all()
diff --git a/keystone/frontends/legacy_auth_frontend.py b/keystone/frontends/legacy_auth_frontend.py
index 5e86d654..9ca4e84e 100644..100755
--- a/keystone/frontends/legacy_auth_frontend.py
+++ b/keystone/frontends/legacy_auth_frontend.py
@@ -27,7 +27,6 @@ the response.
"""
import os
import sys
-import eventlet
import optparse
import httplib
import json
@@ -51,8 +50,8 @@ from keystone.common import config
PROTOCOL_NAME = "Legacy Authentication"
+
class AuthProtocol(object):
-
"""Legacy Auth Middleware that handles authenticating client calls"""
def __init__(self, app, conf):
@@ -61,16 +60,17 @@ class AuthProtocol(object):
self.conf = conf
self.app = app
-
def __call__(self, env, start_response):
""" Handle incoming request. Transform. And send downstream. """
self.start_response = start_response
self.env = env
self.request = Request(env)
- if self.request.path.startswith('/v1.0') or self.request.path.startswith('/v1.1'):
+ if self.request.path.startswith('/v1.0'
+ ) or self.request.path.startswith('/v1.1'):
#Handle 1.0 and 1.1 calls via wrapper.
- params = {"passwordCredentials": {"username": utils.get_auth_user(self.request),
- "password": utils.get_auth_key(self.request)}}
+ params = {"passwordCredentials":
+ {"username": utils.get_auth_user(self.request),
+ "password": utils.get_auth_key(self.request)}}
new_request = Request.blank('/v2.0/tokens')
new_request.headers['Content-type'] = 'application/json'
@@ -78,12 +78,11 @@ class AuthProtocol(object):
new_request.body = json.dumps(params)
new_request.method = 'POST'
response = new_request.get_response(self.app)
-
#Handle failures.
if not str(response.status).startswith('20'):
- return response(env, start_response)
-
- headers = self.transform_keystone_auth_to_legacy_headers(json.loads(response.body))
+ return response(env, start_response)
+ headers = self.transform_keystone_auth_to_legacy_headers(
+ json.loads(response.body))
resp = utils.send_legacy_result(204, headers)
return resp(env, start_response)
else:
@@ -101,8 +100,7 @@ class AuthProtocol(object):
if "X-Auth-Key" in self.request.headers:
auth_key = self.request.headers["X-Auth-Key"]
return auth_key
-
-
+
def transform_keystone_auth_to_legacy_headers(self, content):
headers = {}
if "auth" in content:
@@ -129,7 +127,8 @@ class AuthProtocol(object):
#use X- prefix followed by service name.
headers['X-' + service_name.upper()] = service_urls
return headers
-
+
+
def filter_factory(global_conf, **local_conf):
"""Returns a WSGI filter app for use with paste.deploy."""
conf = global_conf.copy()
@@ -137,4 +136,4 @@ def filter_factory(global_conf, **local_conf):
def auth_filter(app):
return AuthProtocol(app, conf)
- return auth_filter
+ return auth_filter
diff --git a/keystone/logic/types/auth.py b/keystone/logic/types/auth.py
index 804a8841..4b90b8ca 100755
--- a/keystone/logic/types/auth.py
+++ b/keystone/logic/types/auth.py
@@ -120,7 +120,7 @@ class User(object):
class AuthData(object):
"Authentation Information returned upon successful login."
- def __init__(self, token, base_urls = None):
+ def __init__(self, token, base_urls=None):
self.token = token
self.base_urls = base_urls
self.d = {}
@@ -129,7 +129,7 @@ class AuthData(object):
def to_xml(self):
dom = etree.Element("auth",
- xmlns="http://docs.openstack.org/identity/api/v2.0")
+ xmlns="http://docs.openstack.org/identity/api/v2.0")
token = etree.Element("token",
expires=self.token.expires.isoformat())
token.set("id", self.token.token_id)
@@ -138,22 +138,26 @@ class AuthData(object):
service_catalog = etree.Element("serviceCatalog")
for key, key_base_urls in self.d.items():
service = etree.Element("service",
- name = key)
+ name=key)
for base_url in key_base_urls:
endpoint = etree.Element("endpoint")
if base_url.region:
endpoint.set("region", base_url.region)
if base_url.public_url:
- endpoint.set("publicURL", base_url.public_url.replace('%tenant_id%',self.token.tenant_id))
+ endpoint.set("publicURL", base_url.public_url.replace(
+ '%tenant_id%', self.token.tenant_id))
if base_url.admin_url:
- endpoint.set("adminURL", base_url.admin_url.replace('%tenant_id%',self.token.tenant_id))
+ endpoint.set("adminURL", base_url.admin_url.replace(
+ '%tenant_id%', self.token.tenant_id))
if base_url.internal_url:
- endpoint.set("internalURL", base_url.internal_url.replace('%tenant_id%',self.token.tenant_id))
+ endpoint.set("internalURL",
+ base_url.internal_url.replace('%tenant_id%',
+ self.token.tenant_id))
service.append(endpoint)
service_catalog.append(service)
dom.append(service_catalog)
return etree.tostring(dom)
-
+
def __convert_baseurls_to_dict(self):
for base_url in self.base_urls:
if base_url.service not in self.d:
@@ -173,13 +177,16 @@ class AuthData(object):
for base_url in key_base_urls:
endpoint = {}
if base_url.region:
- endpoint["region"] = base_url.region
+ endpoint["region"] = base_url.region
if base_url.public_url:
- endpoint["publicURL"] = base_url.public_url.replace('%tenant_id%',self.token.tenant_id)
+ endpoint["publicURL"] = base_url.public_url.replace(
+ '%tenant_id%', self.token.tenant_id)
if base_url.admin_url:
- endpoint["adminURL"] = base_url.admin_url.replace('%tenant_id%',self.token.tenant_id)
+ endpoint["adminURL"] = base_url.admin_url.replace(
+ '%tenant_id%', self.token.tenant_id)
if base_url.internal_url:
- endpoint["internalURL"] = base_url.internal_url.replace('%tenant_id%',self.token.tenant_id)
+ endpoint["internalURL"] = base_url.internal_url.replace
+ ('%tenant_id%', self.token.tenant_id)
endpoints.append(endpoint)
service_catalog[key] = endpoints
auth["serviceCatalog"] = service_catalog
diff --git a/test/unit/test_authentication.py b/test/unit/test_authentication.py
index a1751c5e..74089023 100755
--- a/test/unit/test_authentication.py
+++ b/test/unit/test_authentication.py
@@ -38,11 +38,11 @@ class AuthenticationTest(unittest.TestCase):
#self.user = utils.get_user()
self.userdisabled = utils.get_userdisabled()
self.auth_token = utils.get_auth_token()
- utils.create_baseurls_ref(self.tenant,"1",
+ utils.create_baseurls_ref(self.tenant, "1",
str(self.auth_token))
- utils.create_baseurls_ref(self.tenant,"2",
- str(self.auth_token))
- utils.create_baseurls_ref(self.tenant,"3",
+ utils.create_baseurls_ref(self.tenant, "2",
+ str(self.auth_token))
+ utils.create_baseurls_ref(self.tenant, "3",
str(self.auth_token))
#self.exp_auth_token = utils.get_exp_auth_token()
#self.disabled_token = utils.get_disabled_token()
@@ -68,7 +68,6 @@ class AuthenticationTest(unittest.TestCase):
self.tenant)
self.assertEqual(200, int(resp['status']))
self.assertEqual('application/xml', utils.content_type(resp))
-
#verify content
dom = etree.Element("root")
dom.append(etree.fromstring(content))
@@ -76,12 +75,12 @@ class AuthenticationTest(unittest.TestCase):
"auth")
if auth == None:
self.fail("Expecting Auth")
- service_catalog = auth.find("{http://docs.openstack.org/identity/api/v2.0}" \
- "serviceCatalog")
+ service_catalog = auth.find(
+ "{http://docs.openstack.org/identity/api/v2.0}" \
+ "serviceCatalog")
if service_catalog == None:
self.fail("Expecting Service Catalog")
-
def test_a_authorize_legacy(self):
resp, content = utils.get_token_legacy('joeuser', 'secrete')
self.assertEqual(204, int(resp['status']))