summaryrefslogtreecommitdiffstats
path: root/ipsilon/info/common.py
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-10-09 14:44:04 -0400
committerPatrick Uiterwijk <puiterwijk@redhat.com>2014-10-24 18:03:18 +0200
commitd274763d8dc06b42f70014b14fcb2e852c086751 (patch)
treed27d9caa5ea65440325fbb94c454f4ab1e5b0172 /ipsilon/info/common.py
parentf461a713ce28e434a34dca4e4d1abbfe255ef1ff (diff)
downloadipsilon-d274763d8dc06b42f70014b14fcb2e852c086751.tar.gz
ipsilon-d274763d8dc06b42f70014b14fcb2e852c086751.tar.xz
ipsilon-d274763d8dc06b42f70014b14fcb2e852c086751.zip
Add attribute mapping for user information
When user information is retrieved we map any wellknown data to a standardized set of names. A ne InfoMapping class takes cares of helping the info modules to map the data they retrieve so that providers can find it in wellknown attribute names for further use. Mapping of attribute names for diplay purposes is also provided. Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Diffstat (limited to 'ipsilon/info/common.py')
-rwxr-xr-xipsilon/info/common.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/ipsilon/info/common.py b/ipsilon/info/common.py
index c4be8fe..92a3ba2 100755
--- a/ipsilon/info/common.py
+++ b/ipsilon/info/common.py
@@ -47,6 +47,48 @@ class InfoProviderBase(PluginObject, Log):
self.debug('Info plugin disabled: %s' % self.name)
+class InfoMapping(Log):
+
+ def __init__(self):
+ self.standard_attributes = {
+ 'fullname': 'Full Name',
+ 'nickname': 'Nickname',
+ 'surname': 'Last Name',
+ 'firstname': 'First Name',
+ 'title': 'Title',
+ 'dob': 'Date of Birth',
+ 'email': 'E-mail Address',
+ 'gender': 'Gender',
+ 'postcode': 'Postal Code',
+ 'street': 'Street Address',
+ 'state': 'State or Province',
+ 'country': 'Country',
+ 'phone': 'Telephone Number',
+ 'language': 'Language',
+ 'timezone': 'Time Zone',
+ }
+ self.mapping = dict()
+
+ def set_mapping(self, attrs_map):
+ self.mapping = attrs_map
+
+ def display_name(self, name):
+ if name in self.standard_attributes:
+ return self.standard_attributes[name]
+ return name
+
+ def map_attrs(self, attrs):
+ s = dict()
+ e = dict()
+ for a in attrs:
+ if a in self.mapping:
+ s[self.mapping[a]] = attrs[a]
+ else:
+ e[a] = attrs[a]
+
+ return s, e
+
+
FACILITY = 'info_config'