git://git.onelab.eu
/
sfa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
36608af
)
fix bug where persons that belong to more than one site could get a credential at...
author
Tony Mack
<tmack@cs.princeton.edu>
Tue, 4 May 2010 01:39:51 +0000
(
01:39
+0000)
committer
Tony Mack
<tmack@cs.princeton.edu>
Tue, 4 May 2010 01:39:51 +0000
(
01:39
+0000)
sfa/plc/api.py
patch
|
blob
|
history
diff --git
a/sfa/plc/api.py
b/sfa/plc/api.py
index
f95611a
..
cbe321b
100644
(file)
--- a/
sfa/plc/api.py
+++ b/
sfa/plc/api.py
@@
-21,6
+21,7
@@
from sfa.util.namespace import *
from sfa.util.api import *
from sfa.util.nodemanager import NodeManager
from sfa.util.sfalogging import *
from sfa.util.api import *
from sfa.util.nodemanager import NodeManager
from sfa.util.sfalogging import *
+from collections import defaultdict
def list_to_dict(recs, key):
"""
def list_to_dict(recs, key):
"""
@@
-362,6
+363,10
@@
class SfaAPI(BaseAPI):
return records
def fill_record_sfa_info(self, records):
return records
def fill_record_sfa_info(self, records):
+
+ def startswith(prefix, values):
+ return [value for value in values if value.startswith(prefix)]
+
# get person ids
person_ids = []
site_ids = []
# get person ids
person_ids = []
site_ids = []
@@
-397,7
+402,12
@@
class SfaAPI(BaseAPI):
table = self.SfaTable()
person_list, persons = [], {}
person_list = table.find({'type': 'user', 'pointer': person_ids})
table = self.SfaTable()
person_list, persons = [], {}
person_list = table.find({'type': 'user', 'pointer': person_ids})
- persons = list_to_dict(person_list, 'pointer')
+ # create a hrns keyed on the sfa record's pointer.
+ # Its possible for multiple records to have the same pointer so
+ # the dict's value will be a list of hrns.
+ persons = defaultdict(list)
+ for person in person_list:
+ persons[person['pointer']].append(person)
# get the pl records
pl_person_list, pl_persons = [], {}
# get the pl records
pl_person_list, pl_persons = [], {}
@@
-412,32
+422,36
@@
class SfaAPI(BaseAPI):
sfa_info = {}
type = record['type']
if (type == "slice"):
sfa_info = {}
type = record['type']
if (type == "slice"):
- # slice users
- researchers = [persons[person_id]['hrn'] for person_id in record['person_ids'] \
- if person_id in persons]
- sfa_info['researcher'] = researchers
+ # all slice users are researchers
+ record['PI'] = []
+ record['researchers'] = []
+ for person_id in record['person_ids']:
+ hrns = [person['hrn'] for person in persons[person_id]]
+ record['researchers'].extend(hrns)
+
# pis at the slice's site
pl_pis = site_pis[record['site_id']]
# pis at the slice's site
pl_pis = site_pis[record['site_id']]
- pi_ids = [pi['person_id'] for pi in pl_pis]
- sfa_info['PI'] = [persons[person_id]['hrn'] for person_id in pi_ids]
+ pi_ids = [pi['person_id'] for pi in pl_pis]
+ for person_id in pi_ids:
+ hrns = [person['hrn'] for person in persons[person_id]]
+ record['PI'].extend(hrns)
elif (type == "authority"):
elif (type == "authority"):
- pis, techs, admins = [], [], []
+ record['PI'] = []
+ record['operator'] = []
+ record['owner'] = []
for pointer in record['person_ids']:
if pointer not in persons or pointer not in pl_persons:
# this means there is not sfa or pl record for this user
continue
for pointer in record['person_ids']:
if pointer not in persons or pointer not in pl_persons:
# this means there is not sfa or pl record for this user
continue
- hrn
= persons[pointer]['hrn'
]
+ hrn
s = [person['hrn'] for person in persons[pointer]
]
roles = pl_persons[pointer]['roles']
if 'pi' in roles:
roles = pl_persons[pointer]['roles']
if 'pi' in roles:
-
pis.append(hrn
)
+
record['PI'].extend(hrns
)
if 'tech' in roles:
if 'tech' in roles:
-
techs.append(hrn
)
+
record['operator'].extend(hrns
)
if 'admin' in roles:
if 'admin' in roles:
- admins.append(hrn)
- sfa_info['PI'] = pis
- sfa_info['operator'] = techs
- sfa_info['owner'] = admins
+ record['owner'].extend(hrns)
# xxx TODO: OrganizationName
elif (type == "node"):
sfa_info['dns'] = record.get("hostname", "")
# xxx TODO: OrganizationName
elif (type == "node"):
sfa_info['dns'] = record.get("hostname", "")