+from sfa.storage.model import make_record, RegRecord, RegAuthority, RegUser, RegSlice, RegKey, \
+ augment_with_sfa_builtins
+# the types that we need to exclude from sqlobjects before being able to dump
+# them on the xmlrpc wire
+from sqlalchemy.orm.collections import InstrumentedList
+
+# historical note -- april 2014
+# the myslice chaps rightfully complained about the following discrepancy
+# they found that
+# * read operations (resolve) expose stuff like e.g.
+# 'reg-researchers', or 'reg-pis', but that
+# * write operations (register, update) need e.g.
+# 'researcher' or 'pi' to be set - reg-* are just ignored
+#
+# the '_normalize_input' helper functions below aim at ironing this out
+# however in order to break as few code as possible we essentially make sure that *both* fields are set
+# upon entering the write methods (so again register and update) for legacy, as some driver code
+# might depend on the presence of, say, 'researcher'
+
+# normalize an input record to a write method - register or update
+# e.g. registry calls this 'reg-researchers'
+# while some drivers call this 'researcher'
+# we need to make sure that both keys appear and are the same
+
+
+def _normalize_input(record, reg_key, driver_key):
+ # this looks right, use this for both keys
+ if reg_key in record:
+ # and issue a warning if they were both set and different
+ # as we're overwriting some user data here
+ if driver_key in record:
+ logger.warning("normalize_input: incoming record has both values, using {}"
+ .format(reg_key))
+ record[driver_key] = record[reg_key]
+ # we only have one key set, duplicate for the other one
+ elif driver_key in record:
+ logger.warning("normalize_input: you should use '{}' instead of '{}'"
+ .format(reg_key, driver_key))
+ record[reg_key] = record[driver_key]
+
+
+def normalize_input_record(record):
+ _normalize_input(record, 'reg-researchers', 'researcher')
+ _normalize_input(record, 'reg-pis', 'pi')
+ _normalize_input(record, 'reg-keys', 'keys')
+ # xxx the keys thing could use a little bit more attention:
+ # some parts of the code are using 'keys' while they should use 'reg-keys'
+ # but I run out of time for now
+ if 'reg-keys' in record:
+ record['keys'] = record['reg-keys']
+ return record
+