~abrindeyev/nova/lp785763

« back to all changes in this revision

Viewing changes to nova/api/openstack/auth.py

  • Committer: Tarmac
  • Author(s): Vishvananda Ishaya
  • Date: 2011-05-17 21:40:25 UTC
  • mfrom: (1077.2.5 fix-token)
  • Revision ID: tarmac-20110517214025-tj6atttn3sz7g94f
Fixes the naming of the server_management_url in auth and tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import datetime
19
19
import hashlib
20
 
import json
21
20
import time
22
21
 
23
22
import webob.exc
25
24
 
26
25
from nova import auth
27
26
from nova import context
28
 
from nova import db
29
27
from nova import exception
30
28
from nova import flags
31
29
from nova import log as logging
32
 
from nova import manager
33
30
from nova import utils
34
31
from nova import wsgi
35
32
from nova.api.openstack import faults
102
99
        token, user = self._authorize_user(username, key, req)
103
100
        if user and token:
104
101
            res = webob.Response()
105
 
            res.headers['X-Auth-Token'] = token.token_hash
 
102
            res.headers['X-Auth-Token'] = token['token_hash']
106
103
            res.headers['X-Server-Management-Url'] = \
107
 
                token.server_management_url
108
 
            res.headers['X-Storage-Url'] = token.storage_url
109
 
            res.headers['X-CDN-Management-Url'] = token.cdn_management_url
 
104
                token['server_management_url']
 
105
            res.headers['X-Storage-Url'] = token['storage_url']
 
106
            res.headers['X-CDN-Management-Url'] = token['cdn_management_url']
110
107
            res.content_type = 'text/plain'
111
108
            res.status = '204'
112
109
            LOG.debug(_("Successfully authenticated '%s'") % username)
130
127
        except exception.NotFound:
131
128
            return None
132
129
        if token:
133
 
            delta = datetime.datetime.now() - token.created_at
 
130
            delta = datetime.datetime.utcnow() - token['created_at']
134
131
            if delta.days >= 2:
135
 
                self.db.auth_token_destroy(ctxt, token.token_hash)
 
132
                self.db.auth_token_destroy(ctxt, token['token_hash'])
136
133
            else:
137
 
                return self.auth.get_user(token.user_id)
 
134
                return self.auth.get_user(token['user_id'])
138
135
        return None
139
136
 
140
137
    def _authorize_user(self, username, key, req):