1 from manifold.core.query import Query
2 from manifoldapi.manifoldapi import execute_query
4 from datetime import datetime
9 import json, os, re, itertools
12 def __init__ (self, platform_id, user_id):
13 account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config').filter_by('platform_id', '==', platform_id).filter_by('user_id', '==', user_id)
15 account_details = execute_query(self.request, account_query)
16 self.user_id = account_details['user_id']
17 self.platform_id = account_details['platform_id']
18 self.auth_type = account_details['auth_type']
19 self.config = account_details['config']
20 account_config = json.loads(account_details['config'])
22 self.usr_hrn = account_config.get('user_hrn',None)
23 self.pub_key = account_config.get('user_public_key',None)
24 self.reference = account_config.get ('reference_platform',None)
26 self.user_cred = account_config.get('delegated_user_credential',None)
27 self.user_cred_expiration = get_expiration(self.user_cred)
29 slice_creds = account_config.get('delegated_slice_credentials',None)
30 for slice_name, slice_cred in slice_creds.iteritems():
31 self.slice_cred_expiration = get_expiration(self.slice_cred)
33 self.auth_cred = account_config.get('delegated_authority_credentials',None)
34 self.auth_cred_expiration = get_expiration(self.auth_cred)
36 def get_expiration (credential, format = 'UTC'):
37 exp_date = re.search('<expires>(.*)</expires>', credential)
39 exp_date = exp_date.group(1)
40 if format == 'timestamp':
41 exp_date = calendar.timegm(dateutil.parser.parse(exp_date).utctimetuple())