~ubuntu-branches/ubuntu/saucy/keystone/saucy-proposed

« back to all changes in this revision

Viewing changes to keystone/backends/alterdb/api/token.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-08-23 10:18:22 UTC
  • Revision ID: james.westby@ubuntu.com-20110823101822-enve6zceb3lqhuvj
Tags: upstream-1.0~d4~20110823.1078
ImportĀ upstreamĀ versionĀ 1.0~d4~20110823.1078

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2010 OpenStack LLC.
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
from keystone.backends.alterdb import get_session, models
 
19
from keystone.backends.api import BaseTokenAPI
 
20
 
 
21
 
 
22
class TokenAPI(BaseTokenAPI):
 
23
    def create(self, values):
 
24
        token_ref = models.Token()
 
25
        token_ref.update(values)
 
26
        token_ref.save()
 
27
        return token_ref
 
28
 
 
29
    def get(self, id, session=None):
 
30
        if not session:
 
31
            session = get_session()
 
32
        result = session.query(models.Token).filter_by(id=id).first()
 
33
        return result
 
34
 
 
35
    def delete(self, id, session=None):
 
36
        if not session:
 
37
            session = get_session()
 
38
        with session.begin():
 
39
            token_ref = self.get(id, session)
 
40
            session.delete(token_ref)
 
41
 
 
42
    def get_for_user(self, user_id, session=None):
 
43
        if not session:
 
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()
 
47
        return result
 
48
 
 
49
    def get_for_user_by_tenant(self, user_id, tenant_id, session=None):
 
50
        if not session:
 
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()
 
55
        return result
 
56
 
 
57
    def get_all(self, session=None):
 
58
        if not session:
 
59
            session = get_session()
 
60
        return session.query(models.Token).all()
 
61
 
 
62
 
 
63
def get():
 
64
    return TokenAPI()