~soren/nova/rs_auth_fixes

« back to all changes in this revision

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

  • Committer: Cerberus
  • Date: 2010-09-16 19:41:51 UTC
  • Revision ID: matt.dietz@rackspace.com-20100916194151-w5x0yu86j0ziyzu7
Replaced the existing Rackspace Auth Mechanism with one that mirrors the implementation in the design document.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import json
 
2
from hashlib import sha1
 
3
from nova import datastore
 
4
 
 
5
class FakeAuth(object):
 
6
    def __init__(self, store=datastore.Redis.instance):
 
7
        self._store = store()
 
8
        self.auth_hash = 'rs_fake_auth'
 
9
        self._store.hsetnx(self.auth_hash, 'rs_last_id', 0)
 
10
 
 
11
    def authorize_token(self, token):
 
12
        user = self._store.hget(self.auth_hash, token) 
 
13
        if user:
 
14
            return json.loads(user)
 
15
        return None
 
16
 
 
17
    def authorize_user(self, user, key):
 
18
        token = sha1("%s_%s" % (user, key)).hexdigest()
 
19
        user = self._store.hget(self.auth_hash, token)
 
20
        if not user:
 
21
            return None, None
 
22
        else:
 
23
            return token, json.loads(user)
 
24
 
 
25
    def add_user(self, user, key):
 
26
        last_id = self._store.hget(self.auth_hash, 'rs_last_id')
 
27
        token = sha1("%s_%s" % (user, key)).hexdigest()
 
28
        user = {
 
29
            'id':last_id,
 
30
            'cdn_management_url':'cdn_management_url',
 
31
            'storage_url':'storage_url',
 
32
            'server_management_url':'server_management_url'
 
33
        }
 
34
        new_user = self._store.hsetnx(self.auth_hash, token, json.dumps(user))
 
35
        if new_user:
 
36
            self._store.hincrby(self.auth_hash, 'rs_last_id')
 
37