summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorTodd Willey <todd@ansolabs.com>2010-07-26 15:01:42 -0400
committerTodd Willey <todd@ansolabs.com>2010-07-26 15:01:42 -0400
commitd6e74751fa156f3879ff2136caccf2a40d4b9e8c (patch)
treebcd57bf0efe0ee01df1cba1eddc7a3db79a522c5 /nova/compute
parent17096b0eef78680164746303d65f9f9a50a91562 (diff)
Basic standup of SessionToken model for shortlived auth tokens.
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/model.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/nova/compute/model.py b/nova/compute/model.py
index cda188183..331b68349 100644
--- a/nova/compute/model.py
+++ b/nova/compute/model.py
@@ -43,6 +43,7 @@ True
import logging
import time
import redis
+import uuid
from nova import datastore
from nova import exception
@@ -228,6 +229,41 @@ class Daemon(datastore.BasicModel):
for x in cls.associated_to("host", hostname):
yield x
+class SessionToken(datastore.BasicModel):
+ """This is a short-lived auth token that is passed through web requests"""
+
+ def __init__(self, session_token):
+ self.token = session_token
+ super(SessionToken, self).__init__()
+
+ @property
+ def identifier(self):
+ return self.token
+
+ def default_state(self):
+ return {'user': None, 'session_type': None, 'token': self.token}
+
+ @classmethod
+ def generate(cls, userid, session_type=None):
+ token = str(uuid.uuid4())
+ while cls.lookup(token):
+ token = str(uuid.uuid4())
+ instance = cls(token)
+ instance['user'] = userid
+ instance['session_type'] = session_type
+ instance.save()
+ return instance
+
+ def save(self):
+ """Call into superclass to save object, then save associations"""
+ if not self['user']:
+ raise exception.Invalid("SessionToken requires a User association")
+ success = super(SessionToken, self).save()
+ if success:
+ self.associate_with("user", self['user'])
+ return True
+
+
if __name__ == "__main__":
import doctest
doctest.testmod()