Backslash continuation cleanup
Removed unnecessary backslash continuations Added backslash continuation rules to HACKING.rst Change-Id: Id91da5b7e9be4d4587dded95fe7a0415240213ec
This commit is contained in:
parent
f261f718ee
commit
4f39aa2b94
2
.mailmap
2
.mailmap
@ -20,4 +20,4 @@
|
||||
Sirish Bitra <sirish.bitra@gmail.com> sirish.bitra <sirish.bitra@gmail.com>
|
||||
Sirish Bitra <sirish.bitra@gmail.com> sirishbitra <sirish.bitra@gmail.com>
|
||||
Sirish Bitra <sirish.bitra@gmail.com> root <root@bsirish.(none)>
|
||||
|
||||
Zhongyue Luo <zhongyue.nah@intel.com> <lzyeval@gmail.com>
|
||||
|
@ -11,6 +11,8 @@ General
|
||||
|
||||
- Put two newlines between top-level code (funcs, classes, etc)
|
||||
- Put one newline between methods in classes and anywhere else
|
||||
- Long lines should be wrapped in parentheses
|
||||
in preference to using a backslash for line continuation.
|
||||
- Do not write "except:", use "except Exception:" at the very least
|
||||
- Include your name with TODOs as in "#TODO(termie)"
|
||||
- Do not name anything the same name as a built-in or reserved word
|
||||
|
@ -24,9 +24,9 @@ from keystone import config
|
||||
|
||||
|
||||
CONF = config.CONF
|
||||
DIR_PERMS = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | \
|
||||
stat.S_IRGRP | stat.S_IXGRP | \
|
||||
stat.S_IROTH | stat.S_IXOTH
|
||||
DIR_PERMS = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
|
||||
stat.S_IRGRP | stat.S_IXGRP |
|
||||
stat.S_IROTH | stat.S_IXOTH)
|
||||
CERT_PERMS = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
|
||||
PRIV_PERMS = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
|
||||
DEFAULT_SUBJECT = "/C=US/ST=Unset/L=Unset/O=Unset/CN=www.example.com"
|
||||
|
@ -35,16 +35,17 @@ class Ec2Credential(sql.ModelBase, sql.DictBase):
|
||||
class Ec2(sql.Base):
|
||||
def get_credential(self, credential_id):
|
||||
session = self.get_session()
|
||||
credential_ref = session.query(Ec2Credential)\
|
||||
.filter_by(access=credential_id).first()
|
||||
query = session.query(Ec2Credential)
|
||||
query = query.filter_by(access=credential_id)
|
||||
credential_ref = query.first()
|
||||
if not credential_ref:
|
||||
return
|
||||
return credential_ref.to_dict()
|
||||
|
||||
def list_credentials(self, user_id):
|
||||
session = self.get_session()
|
||||
credential_refs = session.query(Ec2Credential)\
|
||||
.filter_by(user_id=user_id)
|
||||
query = session.query(Ec2Credential)
|
||||
credential_refs = query.filter_by(user_id=user_id)
|
||||
return [x.to_dict() for x in credential_refs]
|
||||
|
||||
# CRUD
|
||||
@ -58,8 +59,9 @@ class Ec2(sql.Base):
|
||||
|
||||
def delete_credential(self, credential_id):
|
||||
session = self.get_session()
|
||||
credential_ref = session.query(Ec2Credential)\
|
||||
.filter_by(access=credential_id).first()
|
||||
query = session.query(Ec2Credential)
|
||||
query = query.filter_by(access=credential_id)
|
||||
credential_ref = query.first()
|
||||
with session.begin():
|
||||
session.delete(credential_ref)
|
||||
session.flush()
|
||||
|
@ -201,11 +201,10 @@ class Identity(sql.Base, identity.Driver):
|
||||
def get_tenant_users(self, tenant_id):
|
||||
session = self.get_session()
|
||||
self.get_tenant(tenant_id)
|
||||
user_refs = session.query(User)\
|
||||
.join(UserTenantMembership)\
|
||||
.filter(UserTenantMembership.tenant_id ==
|
||||
tenant_id)\
|
||||
.all()
|
||||
query = session.query(User)
|
||||
query = query.join(UserTenantMembership)
|
||||
query = query.filter(UserTenantMembership.tenant_id == tenant_id)
|
||||
user_refs = query.all()
|
||||
return [_filter_user(user_ref.to_dict()) for user_ref in user_refs]
|
||||
|
||||
def _get_user(self, user_id):
|
||||
@ -230,10 +229,10 @@ class Identity(sql.Base, identity.Driver):
|
||||
|
||||
def get_metadata(self, user_id, tenant_id):
|
||||
session = self.get_session()
|
||||
metadata_ref = session.query(Metadata)\
|
||||
.filter_by(user_id=user_id)\
|
||||
.filter_by(tenant_id=tenant_id)\
|
||||
.first()
|
||||
query = session.query(Metadata)
|
||||
query = query.filter_by(user_id=user_id)
|
||||
query = query.filter_by(tenant_id=tenant_id)
|
||||
metadata_ref = query.first()
|
||||
if metadata_ref is None:
|
||||
raise exception.MetadataNotFound()
|
||||
return metadata_ref.data
|
||||
@ -260,10 +259,10 @@ class Identity(sql.Base, identity.Driver):
|
||||
session = self.get_session()
|
||||
self.get_tenant(tenant_id)
|
||||
self.get_user(user_id)
|
||||
q = session.query(UserTenantMembership)\
|
||||
.filter_by(user_id=user_id)\
|
||||
.filter_by(tenant_id=tenant_id)
|
||||
rv = q.first()
|
||||
query = session.query(UserTenantMembership)
|
||||
query = query.filter_by(user_id=user_id)
|
||||
query = query.filter_by(tenant_id=tenant_id)
|
||||
rv = query.first()
|
||||
if rv:
|
||||
return
|
||||
|
||||
@ -276,10 +275,10 @@ class Identity(sql.Base, identity.Driver):
|
||||
session = self.get_session()
|
||||
self.get_tenant(tenant_id)
|
||||
self.get_user(user_id)
|
||||
membership_ref = session.query(UserTenantMembership)\
|
||||
.filter_by(user_id=user_id)\
|
||||
.filter_by(tenant_id=tenant_id)\
|
||||
.first()
|
||||
query = session.query(UserTenantMembership)
|
||||
query = query.filter_by(user_id=user_id)
|
||||
query = query.filter_by(tenant_id=tenant_id)
|
||||
membership_ref = query.first()
|
||||
if membership_ref is None:
|
||||
raise exception.NotFound('User not found in tenant')
|
||||
with session.begin():
|
||||
@ -294,9 +293,9 @@ class Identity(sql.Base, identity.Driver):
|
||||
def get_tenants_for_user(self, user_id):
|
||||
session = self.get_session()
|
||||
self.get_user(user_id)
|
||||
membership_refs = session.query(UserTenantMembership)\
|
||||
.filter_by(user_id=user_id)\
|
||||
.all()
|
||||
query = session.query(UserTenantMembership)
|
||||
query = query.filter_by(user_id=user_id)
|
||||
membership_refs = query.all()
|
||||
return [x.tenant_id for x in membership_refs]
|
||||
|
||||
def get_roles_for_user_and_tenant(self, user_id, tenant_id):
|
||||
@ -386,10 +385,12 @@ class Identity(sql.Base, identity.Driver):
|
||||
def delete_user(self, user_id):
|
||||
session = self.get_session()
|
||||
with session.begin():
|
||||
session.query(UserTenantMembership)\
|
||||
.filter_by(user_id=user_id).delete(False)
|
||||
session.query(Metadata)\
|
||||
.filter_by(user_id=user_id).delete(False)
|
||||
query = session.query(UserTenantMembership)
|
||||
query = query.filter_by(user_id=user_id)
|
||||
query.delete(False)
|
||||
query = session.query(Metadata)
|
||||
query = query.filter_by(user_id=user_id)
|
||||
query.delete(False)
|
||||
if not session.query(User).filter_by(id=user_id).delete(False):
|
||||
raise exception.UserNotFound(user_id=user_id)
|
||||
|
||||
@ -425,10 +426,12 @@ class Identity(sql.Base, identity.Driver):
|
||||
def delete_tenant(self, tenant_id):
|
||||
session = self.get_session()
|
||||
with session.begin():
|
||||
session.query(UserTenantMembership)\
|
||||
.filter_by(tenant_id=tenant_id).delete(False)
|
||||
session.query(Metadata)\
|
||||
.filter_by(tenant_id=tenant_id).delete(False)
|
||||
query = session.query(UserTenantMembership)
|
||||
query = query.filter_by(tenant_id=tenant_id)
|
||||
query.delete(False)
|
||||
query = session.query(Metadata)
|
||||
query = query.filter_by(tenant_id=tenant_id)
|
||||
query.delete(False)
|
||||
if not session.query(Tenant).filter_by(id=tenant_id).delete(False):
|
||||
raise exception.TenantNotFound(tenant_id=tenant_id)
|
||||
|
||||
@ -446,10 +449,10 @@ class Identity(sql.Base, identity.Driver):
|
||||
def update_metadata(self, user_id, tenant_id, metadata):
|
||||
session = self.get_session()
|
||||
with session.begin():
|
||||
metadata_ref = session.query(Metadata)\
|
||||
.filter_by(user_id=user_id)\
|
||||
.filter_by(tenant_id=tenant_id)\
|
||||
.first()
|
||||
query = session.query(Metadata)
|
||||
query = query.filter_by(user_id=user_id)
|
||||
query = query.filter_by(tenant_id=tenant_id)
|
||||
metadata_ref = query.first()
|
||||
data = metadata_ref.data.copy()
|
||||
for k in metadata:
|
||||
data[k] = metadata[k]
|
||||
|
@ -242,8 +242,8 @@ class AuthProtocol(object):
|
||||
self.token_cache_time = int(self._conf_get('token_cache_time'))
|
||||
self._token_revocation_list = None
|
||||
self._token_revocation_list_fetched_time = None
|
||||
self.token_revocation_list_cache_timeout = \
|
||||
datetime.timedelta(seconds=0)
|
||||
cache_timeout = datetime.timedelta(seconds=0)
|
||||
self.token_revocation_list_cache_timeout = cache_timeout
|
||||
if memcache_servers:
|
||||
try:
|
||||
import memcache
|
||||
@ -747,8 +747,8 @@ class AuthProtocol(object):
|
||||
|
||||
@property
|
||||
def token_revocation_list(self):
|
||||
timeout = self.token_revocation_list_fetched_time +\
|
||||
self.token_revocation_list_cache_timeout
|
||||
timeout = (self.token_revocation_list_fetched_time +
|
||||
self.token_revocation_list_cache_timeout)
|
||||
list_is_current = timeutils.utcnow() < timeout
|
||||
if list_is_current:
|
||||
# Load the list from disk if required
|
||||
|
@ -53,9 +53,9 @@ class Token(sql.Base, token.Driver):
|
||||
# Public interface
|
||||
def get_token(self, token_id):
|
||||
session = self.get_session()
|
||||
token_ref = session.query(TokenModel)\
|
||||
.filter_by(id=self.token_to_key(token_id),
|
||||
valid=True).first()
|
||||
query = session.query(TokenModel)
|
||||
query = query.filter_by(id=self.token_to_key(token_id), valid=True)
|
||||
token_ref = query.first()
|
||||
now = datetime.datetime.utcnow()
|
||||
if token_ref and (not token_ref.expires or now < token_ref.expires):
|
||||
return token_ref.to_dict()
|
||||
@ -99,9 +99,10 @@ class Token(sql.Base, token.Driver):
|
||||
session = self.get_session()
|
||||
tokens = []
|
||||
now = timeutils.utcnow()
|
||||
for token_ref in session.query(TokenModel)\
|
||||
.filter(TokenModel.expires > now)\
|
||||
.filter_by(valid=True):
|
||||
query = session.query(TokenModel)
|
||||
query = query.filter(TokenModel.expires > now)
|
||||
token_references = query.filter_by(valid=True)
|
||||
for token_ref in token_references:
|
||||
token_ref_dict = token_ref.to_dict()
|
||||
if 'user' not in token_ref_dict:
|
||||
continue
|
||||
@ -119,9 +120,10 @@ class Token(sql.Base, token.Driver):
|
||||
session = self.get_session()
|
||||
tokens = []
|
||||
now = timeutils.utcnow()
|
||||
for token_ref in session.query(TokenModel)\
|
||||
.filter(TokenModel.expires > now)\
|
||||
.filter_by(valid=False):
|
||||
query = session.query(TokenModel)
|
||||
query = query.filter(TokenModel.expires > now)
|
||||
token_references = query.filter_by(valid=False)
|
||||
for token_ref in token_references:
|
||||
record = {
|
||||
'id': token_ref['id'],
|
||||
'expires': token_ref['expires'],
|
||||
|
@ -317,13 +317,14 @@ class BaseAuthTokenMiddlewareTest(test.TestCase):
|
||||
self.response_status = None
|
||||
self.response_headers = None
|
||||
self.middleware.revoked_file_name = tempfile.mkstemp()[1]
|
||||
self.middleware.token_revocation_list_cache_timeout =\
|
||||
datetime.timedelta(days=1)
|
||||
cache_timeout = datetime.timedelta(days=1)
|
||||
self.middleware.token_revocation_list_cache_timeout = cache_timeout
|
||||
self.middleware.token_revocation_list = jsonutils.dumps(
|
||||
{"revoked": [], "extra": "success"})
|
||||
|
||||
globals()['SIGNED_REVOCATION_LIST'] =\
|
||||
globals()['VALID_SIGNED_REVOCATION_LIST']
|
||||
signed_list = 'SIGNED_REVOCATION_LIST'
|
||||
valid_signed_list = 'VALID_SIGNED_REVOCATION_LIST'
|
||||
globals()[signed_list] = globals()[valid_signed_list]
|
||||
|
||||
super(BaseAuthTokenMiddlewareTest, self).setUp()
|
||||
|
||||
|
@ -40,8 +40,8 @@ class PamIdentity(test.TestCase):
|
||||
self.assertDictEqual(self.tenant_in, tenant_out)
|
||||
|
||||
def test_get_tenant_by_name(self):
|
||||
tenant_out = self.identity_api.\
|
||||
get_tenant_by_name(self.tenant_in['name'])
|
||||
tenant_in_name = self.tenant_in['name']
|
||||
tenant_out = self.identity_api.get_tenant_by_name(tenant_in_name)
|
||||
self.assertDictEqual(self.tenant_in, tenant_out)
|
||||
|
||||
def test_get_user(self):
|
||||
|
@ -924,8 +924,8 @@ class KcMasterTestCase(CompatTestCase, KeystoneClientTests):
|
||||
'/v2.0/OS-KSCRUD/users/%s' % self.user_two['id'],
|
||||
headers={'X-Auth-Token': token_id})
|
||||
req.method = 'PATCH'
|
||||
req.body = '{"user":{"password":"%s","original_password":"%s"}}' % \
|
||||
(new_password, self.user_two['password'])
|
||||
req.body = ('{"user":{"password":"%s","original_password":"%s"}}' %
|
||||
(new_password, self.user_two['password']))
|
||||
self.public_server.application(req.environ,
|
||||
responseobject.start_fake_response)
|
||||
|
||||
@ -951,8 +951,8 @@ class KcMasterTestCase(CompatTestCase, KeystoneClientTests):
|
||||
'/v2.0/OS-KSCRUD/users/%s' % self.user_foo['id'],
|
||||
headers={'X-Auth-Token': token_id})
|
||||
req.method = 'PATCH'
|
||||
req.body = '{"user":{"password":"%s","original_password":"%s"}}' % \
|
||||
(new_password, self.user_two['password'])
|
||||
req.body = ('{"user":{"password":"%s","original_password":"%s"}}' %
|
||||
(new_password, self.user_two['password']))
|
||||
self.public_server.application(req.environ,
|
||||
responseobject.start_fake_response)
|
||||
self.assertEquals(403, responseobject.response_status)
|
||||
@ -980,8 +980,8 @@ class KcMasterTestCase(CompatTestCase, KeystoneClientTests):
|
||||
'/v2.0/OS-KSCRUD/users/%s' % self.user_two['id'],
|
||||
headers={'X-Auth-Token': token_id})
|
||||
req.method = 'PATCH'
|
||||
req.body = '{"user":{"password":"%s","original_password":"%s"}}' % \
|
||||
(new_password, self.user_two['password'])
|
||||
req.body = ('{"user":{"password":"%s","original_password":"%s"}}' %
|
||||
(new_password, self.user_two['password']))
|
||||
|
||||
rv = self.public_server.application(
|
||||
req.environ,
|
||||
|
@ -31,9 +31,9 @@ def denied_request(code):
|
||||
'AccessDenied': (401, 'Access denied'),
|
||||
'InvalidURI': (400, 'Could not parse the specified URI'),
|
||||
}
|
||||
xml = '<?xml version="1.0" encoding="UTF-8"?>\r\n<Error>\r\n ' \
|
||||
'<Code>%s</Code>\r\n <Message>%s</Message>\r\n</Error>\r\n' \
|
||||
% (code, error_table[code][1])
|
||||
xml = ('<?xml version="1.0" encoding="UTF-8"?>\r\n<Error>\r\n '
|
||||
'<Code>%s</Code>\r\n <Message>%s</Message>\r\n</Error>\r\n' %
|
||||
(code, error_table[code][1]))
|
||||
return xml
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user