Update user attribute handling (#593)

* Update user attribute handling

User attribite type handling issues.

Custom types have their case lowered.

* Use custom keyword as part of type
Old - address, im, phone: type a|b|c|(custom <String>)
New - address, im, phone: type a|b|c|<String>

Dropping custom keyword will break existing scripts

* Use separate keyword for custom type
Old - organization: (type a|b|c) | (customtype <String>)
New - organization: (type a|b|c|<String>)

Dropping customtype keyword will break existing scripts

Unlike all other attributes, you do not set type: custom when customType is set

* Use implied custom
Old - location: type a|b|c|<String>
New - location: type a|b|c|<String>

No change

* Use implied custom, no type keyword
Old - externalid, otheremail, relation, website: a|b|c|<String>
New - externalid, otheremail, relation, website: a|b|c|<String>

No change

This update normalizes the type handling.

Case of custom types is preserved.

In update, for all fields, you can do:
a|b|c|<String>
a|b|c|custom <String>

customtype <String> is still allowed for organization for backward compatability.

* Just in case user does type work and then customtype xxx

* Update documentation
This commit is contained in:
Ross Scroggs
2017-09-19 14:35:52 -07:00
committed by Jay Lee
parent 774c084708
commit 0327f5c30f

View File

@ -6434,6 +6434,33 @@ def doGetUserSchema():
_showSchema(schema)
def getUserAttributes(i, cd, updateCmd=False):
def getEntryType(i, entry, entryTypes, setTypeCustom=True):
""" Get attribute entry type
entryTypes is list of pre-defined types, a|b|c
Allow a|b|c|<String>, a|b|c|custom <String>
setTypeCustom=True, For all fields except organizations, when setting a custom type you do:
entry[u'type'] = u'custom'
entry[u'customType'] = <String>
setTypeCustom=False, For organizations, you don't set entry[u'type'] = u'custom'
Preserve case of custom types
"""
utype = sys.argv[i]
ltype = utype.lower()
if ltype == u'custom':
i += 1
utype = sys.argv[i]
ltype = utype.lower()
if ltype in entryTypes:
entry[u'type'] = ltype
entry.pop(u'customType', None)
else:
entry[u'customType'] = utype
if setTypeCustom:
entry[u'type'] = u'custom'
else:
entry.pop(u'type', None)
return i+1
def checkClearBodyList(i, body, itemName):
if sys.argv[i].lower() == u'clear':
if itemName in body:
@ -6442,7 +6469,7 @@ def getUserAttributes(i, cd, updateCmd=False):
return True
return False
def appendItemToBodyList(body, itemName, itemValue):
def appendItemToBodyList(body, itemName, itemValue, checkSystemId=False):
if (itemName in body) and (body[itemName] is None):
del body[itemName]
body.setdefault(itemName, [])
@ -6450,8 +6477,9 @@ def getUserAttributes(i, cd, updateCmd=False):
if itemValue.get(u'primary', False):
for citem in body[itemName]:
if citem.get(u'primary', False):
print u'ERROR: Multiple {0} are marked primary, only one can be primary'.format(itemName)
sys.exit(2)
if not checkSystemId or itemValue.get(u'systemId') == citem.get(u'systemId'):
print u'ERROR: Multiple {0} are marked primary, only one can be primary'.format(itemName)
sys.exit(2)
body[itemName].append(itemValue)
def _splitSchemaNameDotFieldName(sn_fn, fnRequired=True):
@ -6587,12 +6615,7 @@ def getUserAttributes(i, cd, updateCmd=False):
if sys.argv[i].lower() != u'type':
print u'ERROR: wrong format for account address details. Expected type got %s' % sys.argv[i]
sys.exit(2)
i += 1
address[u'type'] = sys.argv[i].lower()
if address[u'type'] not in USER_ADDRESS_TYPES:
address[u'customType'] = address[u'type']
address[u'type'] = u'custom'
i += 1
i = getEntryType(i+1, address, USER_ADDRESS_TYPES)
if sys.argv[i].lower() in [u'unstructured', u'formatted']:
i += 1
address[u'sourceIsStructured'] = False
@ -6638,11 +6661,7 @@ def getUserAttributes(i, cd, updateCmd=False):
i += 1
continue
an_email = {}
an_email[u'type'] = sys.argv[i].lower()
if an_email[u'type'] not in USER_EMAIL_TYPES:
an_email[u'customType'] = an_email[u'type']
an_email[u'type'] = u'custom'
i += 1
i = getEntryType(i, an_email, USER_EMAIL_TYPES)
an_email[u'address'] = sys.argv[i]
i += 1
appendItemToBodyList(body, u'emails', an_email)
@ -6655,12 +6674,7 @@ def getUserAttributes(i, cd, updateCmd=False):
if sys.argv[i].lower() != u'type':
print u'ERROR: wrong format for account im details. Expected type got %s' % sys.argv[i]
sys.exit(2)
i += 1
im[u'type'] = sys.argv[i].lower()
if im[u'type'] not in USER_IM_TYPES:
im[u'customType'] = im[u'type']
im[u'type'] = u'custom'
i += 1
i = getEntryType(i+1, im, USER_IM_TYPES)
if sys.argv[i].lower() != u'protocol':
print u'ERROR: wrong format for account details. Expected protocol got %s' % sys.argv[i]
sys.exit(2)
@ -6699,12 +6713,12 @@ def getUserAttributes(i, cd, updateCmd=False):
elif myopt == u'title':
organization[u'title'] = sys.argv[i+1]
i += 2
elif myopt == u'type':
organization[u'type'] = sys.argv[i+1].lower()
if organization[u'type'] not in USER_ORGANIZATION_TYPES:
organization[u'customType'] = organization[u'type']
organization[u'type'] = u'custom'
elif myopt == u'customtype':
organization[u'customType'] = sys.argv[i+1]
organization.pop(u'type', None)
i += 2
elif myopt == u'type':
i = getEntryType(i+1, organization, USER_ORGANIZATION_TYPES, setTypeCustom=False)
elif myopt == u'department':
organization[u'department'] = sys.argv[i+1]
i += 2
@ -6743,11 +6757,7 @@ def getUserAttributes(i, cd, updateCmd=False):
phone[u'value'] = sys.argv[i+1]
i += 2
elif myopt == u'type':
phone[u'type'] = sys.argv[i+1].lower()
if phone[u'type'] not in USER_PHONE_TYPES:
phone[u'customType'] = phone[u'type']
phone[u'type'] = u'custom'
i += 2
i = getEntryType(i+1, phone, USER_PHONE_TYPES)
elif myopt in [u'notprimary', u'primary']:
phone[u'primary'] = myopt == u'primary'
i += 1
@ -6762,11 +6772,7 @@ def getUserAttributes(i, cd, updateCmd=False):
i += 1
continue
relation = {}
relation[u'type'] = sys.argv[i].lower()
if relation[u'type'] not in USER_RELATION_TYPES:
relation[u'customType'] = relation[u'type']
relation[u'type'] = u'custom'
i += 1
i = getEntryType(i, relation, USER_RELATION_TYPES)
relation[u'value'] = sys.argv[i]
i += 1
appendItemToBodyList(body, u'relations', relation)
@ -6776,11 +6782,7 @@ def getUserAttributes(i, cd, updateCmd=False):
i += 1
continue
externalid = {}
externalid[u'type'] = sys.argv[i].lower()
if externalid[u'type'] not in USER_EXTERNALID_TYPES:
externalid[u'customType'] = externalid[u'type']
externalid[u'type'] = u'custom'
i += 1
i = getEntryType(i, externalid, USER_EXTERNALID_TYPES)
externalid[u'value'] = sys.argv[i]
i += 1
appendItemToBodyList(body, u'externalIds', externalid)
@ -6790,11 +6792,7 @@ def getUserAttributes(i, cd, updateCmd=False):
i += 1
continue
website = {}
website[u'type'] = sys.argv[i].lower()
if website[u'type'] not in USER_WEBSITE_TYPES:
website[u'customType'] = website[u'type']
website[u'type'] = u'custom'
i += 1
i = getEntryType(i, website, USER_WEBSITE_TYPES)
website[u'value'] = sys.argv[i]
i += 1
myopt = sys.argv[i].lower()
@ -6828,11 +6826,7 @@ def getUserAttributes(i, cd, updateCmd=False):
while True:
myopt = sys.argv[i].lower()
if myopt == u'type':
location[u'type'] = sys.argv[i+1].lower()
if location[u'type'] not in USER_LOCATION_TYPES:
location[u'customType'] = location[u'type']
location[u'type'] = u'custom'
i += 2
i = getEntryType(i+1, location, USER_LOCATION_TYPES)
elif myopt == u'area':
location[u'area'] = sys.argv[i+1]
i += 2
@ -6920,7 +6914,7 @@ def getUserAttributes(i, cd, updateCmd=False):
else:
print u'ERROR: %s is not a valid argument for user posix details. Make sure user posix details end with an endposix argument'
sys.exit(3)
appendItemToBodyList(body, u'posixAccounts', posix)
appendItemToBodyList(body, u'posixAccounts', posix, checkSystemId=True)
elif myarg == u'clearschema':
if not updateCmd:
print u'ERROR: %s is not a valid create user argument.' % sys.argv[i]