From 27382f91654fd2e4c98c0b0a026442382fabc785 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 20 Jun 2014 18:13:15 +0100
Subject: [PATCH] add shard information to the User

---
 authserv/ldap_model.py | 21 ++++++++++++++++++---
 authserv/model.py      |  3 ++-
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/authserv/ldap_model.py b/authserv/ldap_model.py
index af6f7a2..9757ecf 100644
--- a/authserv/ldap_model.py
+++ b/authserv/ldap_model.py
@@ -7,6 +7,15 @@ from ldap.ldapobject import LDAPObject
 from authserv import model
 
 
+# Define the LDAP schema attributes that we will use.
+SCHEMA = {
+    'password': 'userPassword',
+    'otp_secret': 'totpSecret',
+    'app_specific_password': 'appSpecificPassword',
+    'shard': 'host'
+}
+
+
 class Error(Exception):
     pass
 
@@ -101,16 +110,19 @@ class User(model.User):
         self._dn = dn
         self._otp_enabled = False
         self._asps = []
+        self._shard = None
         for key, values in data.iteritems():
-            if key == 'userPassword':
+            if key == SCHEMA['password']:
                 self._password = values[0]
                 if self._password.startswith('{crypt}'):
                     self._password = self._password[7:]
-            elif key == 'totpSecret':
+            elif key == SCHEMA['otp_secret']:
                 self._otp_enabled = True
                 self._totp_secret = values[0]
-            elif key == 'appSpecificPassword':
+            elif key == SCHEMA['app_specific_password']:
                 self._asps = [v.split(':', 1) for v in values]
+            elif SCHEMA['shard'] and key == SCHEMA['shard']:
+                self._shard = values[0]
 
     def otp_enabled(self):
         return self._otp_enabled
@@ -129,3 +141,6 @@ class User(model.User):
 
     def get_password(self):
         return self._password
+
+    def get_shard(self):
+        return self._shard
diff --git a/authserv/model.py b/authserv/model.py
index b596203..9af9c72 100644
--- a/authserv/model.py
+++ b/authserv/model.py
@@ -31,4 +31,5 @@ class User(object):
     def get_password(self):
         pass
 
-
+    def get_shard(self):
+        pass
-- 
GitLab