def _list_tokens_for_trust(self, trust_id): tokens = [] now = timeutils.utcnow() for token, ref in self.db.items(): if not token.startswith('token-') or self.is_expired(now, ref): continue if self.trust_matches(trust_id, ref): tokens.append(token.split('-', 1)[1]) return tokens
def list_tokens(self, user_id): tokens = [] now = datetime.datetime.utcnow() for token, user_ref in self.db.items(): if not token.startswith("token-"): continue if "user" not in user_ref: continue if user_ref["user"].get("id") != user_id: continue if user_ref.get("expires") and user_ref.get("expires") < now: continue tokens.append(token.split("-", 1)[1]) return tokens
def list_tokens(self, user_id): tokens = [] now = timeutils.utcnow() for token, user_ref in self.db.items(): if not token.startswith('token-'): continue if 'user' not in user_ref: continue if user_ref['user'].get('id') != user_id: continue if user_ref.get('expires') and user_ref.get('expires') < now: continue tokens.append(token.split('-', 1)[1]) return tokens
def _list_tokens_for_user(self, user_id, tenant_id=None): def user_matches(user_id, ref): return ref.get("user") and ref["user"].get("id") == user_id def tenant_matches(tenant_id, ref): return (tenant_id is None) or (ref.get("tenant") and ref["tenant"].get("id") == tenant_id) tokens = [] now = timeutils.utcnow() for token, ref in self.db.items(): if not token.startswith("token-") or self.is_expired(now, ref): continue else: if user_matches(user_id, ref) and tenant_matches(tenant_id, ref): tokens.append(token.split("-", 1)[1]) return tokens
def _list_tokens_for_user(self, user_id, tenant_id=None): def user_matches(user_id, ref): return ref.get('user') and ref['user'].get('id') == user_id def tenant_matches(tenant_id, ref): return ((tenant_id is None) or (ref.get('tenant') and ref['tenant'].get('id') == tenant_id)) tokens = [] now = timeutils.utcnow() for token, ref in self.db.items(): if not token.startswith('token-') or self.is_expired(now, ref): continue else: if (user_matches(user_id, ref) and tenant_matches(tenant_id, ref)): tokens.append(token.split('-', 1)[1]) return tokens
def list_tokens(self, user_id, tenant_id=None): tokens = [] now = timeutils.utcnow() for token, ref in self.db.items(): if not token.startswith('token-'): continue if 'user' not in ref: continue if ref['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: continue if ref['tenant'].get('id') != tenant_id: continue tokens.append(token.split('-', 1)[1]) return tokens