1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 OpenStack LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
from keystone.backends.alterdb import get_session, models
19
from keystone.backends.api import BaseTokenAPI
22
class TokenAPI(BaseTokenAPI):
23
def create(self, values):
24
token_ref = models.Token()
25
token_ref.update(values)
29
def get(self, id, session=None):
31
session = get_session()
32
result = session.query(models.Token).filter_by(id=id).first()
35
def delete(self, id, session=None):
37
session = get_session()
39
token_ref = self.get(id, session)
40
session.delete(token_ref)
42
def get_for_user(self, user_id, session=None):
44
session = get_session()
45
result = session.query(models.Token).filter_by(
46
user_id=user_id, tenant_id=None).order_by("expires desc").first()
49
def get_for_user_by_tenant(self, user_id, tenant_id, session=None):
51
session = get_session()
52
result = session.query(models.Token).filter_by(
53
user_id=user_id, tenant_id=tenant_id).\
54
order_by("expires desc").first()
57
def get_all(self, session=None):
59
session = get_session()
60
return session.query(models.Token).all()