← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/nodekey-token-fk into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/nodekey-token-fk into lp:maas with lp:~jtv/maas/metadata-oauth-key as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jtv/maas/nodekey-token-fk/+merge/94767

Now that we need to look up the Token for a NodeKey, add a foreign key.  Not really _needed_ as such, but will speed things up.  And let's face it, NodeKey was already effectively a linking table.  Its existing "key" attribute becomes more of a cache.

Also, the node, token, and key are now all unique.  Maybe at some point we'll drop NodeKey altogether and make it a foreign key from Node to Token.  For now it's still comforting to have the extra flexibility of a separate table.
-- 
https://code.launchpad.net/~jtv/maas/nodekey-token-fk/+merge/94767
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/nodekey-token-fk into lp:maas.
=== modified file 'src/metadataserver/models.py'
--- src/metadataserver/models.py	2012-02-27 13:43:21 +0000
+++ src/metadataserver/models.py	2012-02-27 13:43:21 +0000
@@ -66,7 +66,7 @@
         :rtype: piston.models.Token
         """
         token = create_auth_token(get_node_init_user())
-        self.create(node=node, key=token.key)
+        self.create(node=node, token=token, key=token.key)
         return token
 
     def get_token_for_node(self, node):
@@ -94,7 +94,7 @@
             return self.create_token(node)
         else:
             [nodekey] = existing_nodekey
-            return Token.objects.get(key=nodekey.key)
+            return nodekey.token
 
     def get_node_for_key(self, key):
         """Find the Node that `key` was created for.
@@ -121,8 +121,10 @@
 
     objects = NodeKeyManager()
 
-    node = ForeignKey(Node, null=False, editable=False)
-    key = CharField(max_length=KEY_SIZE, null=False, editable=False)
+    node = ForeignKey(Node, null=False, editable=False, unique=True)
+    token = ForeignKey(Token, null=False, editable=False, unique=True)
+    key = CharField(
+        max_length=KEY_SIZE, null=False, editable=False, unique=True)
 
 
 class NodeUserDataManager(Manager):