Merge "Properly list tokens with a null tenant" into stable/folsom

This commit is contained in:
Jenkins 2012-11-20 17:07:15 +00:00 committed by Gerrit Code Review
commit bd3f2189bb
3 changed files with 15 additions and 10 deletions

View File

@ -56,16 +56,18 @@ class Token(kvs.Base, token.Driver):
for token, ref in self.db.items():
if not token.startswith('token-'):
continue
if 'user' not in ref:
user = ref.get('user')
if not user:
continue
if ref['user'].get('id') != user_id:
if user.get('id') != user_id:
continue
if ref.get('expires') and ref.get('expires') < now:
continue
if tenant_id is not None:
if 'tenant' not in ref:
tenant = ref.get('tenant')
if not tenant:
continue
if ref['tenant'].get('id') != tenant_id:
if tenant.get('id') != tenant_id:
continue
tokens.append(token.split('-', 1)[1])
return tokens

View File

@ -107,9 +107,10 @@ class Token(token.Driver):
token_ref = self.client.get(ptk)
if token_ref:
if tenant_id is not None:
if 'tenant' not in token_ref:
tenant = token_ref.get('tenant')
if not tenant:
continue
if token_ref['tenant'].get('id') != tenant_id:
if tenant.get('id') != tenant_id:
continue
tokens.append(token_id)
return tokens

View File

@ -103,14 +103,16 @@ class Token(sql.Base, token.Driver):
.filter(TokenModel.expires > now)\
.filter_by(valid=True):
token_ref_dict = token_ref.to_dict()
if 'user' not in token_ref_dict:
user = token_ref_dict.get('user')
if not user:
continue
if token_ref_dict['user'].get('id') != user_id:
if user.get('id') != user_id:
continue
if tenant_id is not None:
if 'tenant' not in token_ref_dict:
tenant = token_ref_dict.get('tenant')
if not tenant:
continue
if token_ref_dict['tenant'].get('id') != tenant_id:
if tenant.get('id') != tenant_id:
continue
tokens.append(token_ref['id'])
return tokens