mirror of
https://github.com/GAM-team/GAM.git
synced 2025-05-12 12:17:20 +00:00
* Add verifytarget to update alias to address Issue #1479 * Make default behavior in update alias to be verify; provide opt-out * Update __init__.py * Remove verifynotinvitable check on update alias
This commit is contained in:
parent
f6c4e26b3b
commit
1d5a8ec81b
@ -1052,7 +1052,7 @@ gam info org|ou <OrgUnitPath> [nousers|notsuspended|suspended] [children|child]
|
|||||||
gam print orgs|ous [todrive] [toplevelonly] [from_parent <OrgUnitPath>] [allfields|(fields <OrgUnitFieldNameList>)]
|
gam print orgs|ous [todrive] [toplevelonly] [from_parent <OrgUnitPath>] [allfields|(fields <OrgUnitFieldNameList>)]
|
||||||
|
|
||||||
gam create alias|nickname <EmailAddress> user|group|target <UniqueID>|<EmailAddress> [verifynotinvitable]
|
gam create alias|nickname <EmailAddress> user|group|target <UniqueID>|<EmailAddress> [verifynotinvitable]
|
||||||
gam update alias|nickname <EmailAddress> user|group|target <UniqueID>|<EmailAddress> [verifynotinvitable]
|
gam update alias|nickname <EmailAddress> user|group|target <UniqueID>|<EmailAddress> [notargetverify]
|
||||||
gam delete alias|nickname [user|group|target] <UniqueID>|<EmailAddress>
|
gam delete alias|nickname [user|group|target] <UniqueID>|<EmailAddress>
|
||||||
gam info alias|nickname <EmailAddress>
|
gam info alias|nickname <EmailAddress>
|
||||||
gam print aliases|nicknames [todrive] [shownoneditable] [nogroups] [nousers] [(query <QueryUser>)|(queries <QueryUserList)]
|
gam print aliases|nicknames [todrive] [shownoneditable] [nogroups] [nousers] [(query <QueryUser>)|(queries <QueryUserList)]
|
||||||
|
@ -8327,6 +8327,24 @@ def doRemoveUsersAliases(users):
|
|||||||
|
|
||||||
|
|
||||||
def doUpdateAlias():
|
def doUpdateAlias():
|
||||||
|
def verify_alias_target_exists():
|
||||||
|
if target_type != 'group':
|
||||||
|
try:
|
||||||
|
gapi.call(cd.users(), 'get',
|
||||||
|
throw_reasons=[gapi_errors.ErrorReason.USER_NOT_FOUND],
|
||||||
|
userKey=target_email)
|
||||||
|
return 'user'
|
||||||
|
except gapi_errors.GapiUserNotFoundError:
|
||||||
|
if target_type == 'user':
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
gapi.call(cd.groups(), 'get',
|
||||||
|
throw_reasons=[gapi_errors.ErrorReason.GROUP_NOT_FOUND],
|
||||||
|
groupKey=target_email)
|
||||||
|
return 'group'
|
||||||
|
except gapi_errors.GapiGroupNotFoundError:
|
||||||
|
return None
|
||||||
|
|
||||||
cd = buildGAPIObject('directory')
|
cd = buildGAPIObject('directory')
|
||||||
alias = normalizeEmailAddressOrUID(sys.argv[3], noUid=True, noLower=True)
|
alias = normalizeEmailAddressOrUID(sys.argv[3], noUid=True, noLower=True)
|
||||||
target_type = sys.argv[4].lower()
|
target_type = sys.argv[4].lower()
|
||||||
@ -8334,15 +8352,19 @@ def doUpdateAlias():
|
|||||||
controlflow.expected_argument_exit(
|
controlflow.expected_argument_exit(
|
||||||
'target type', ', '.join(['user', 'group', 'target']), target_type)
|
'target type', ', '.join(['user', 'group', 'target']), target_type)
|
||||||
target_email = normalizeEmailAddressOrUID(sys.argv[5])
|
target_email = normalizeEmailAddressOrUID(sys.argv[5])
|
||||||
if len(sys.argv) > 6:
|
verifyTarget = True
|
||||||
myarg = sys.argv[6].lower().replace('_', '')
|
i = 6
|
||||||
if myarg != 'verifynotinvitable':
|
while i < len(sys.argv):
|
||||||
controlflow.system_error_exit(
|
myarg = sys.argv[i].lower().replace('_', '')
|
||||||
3,
|
if myarg == 'noverifytarget':
|
||||||
f'{myarg} is not a valid argument for "gam update alias"'
|
verifyTarget = False
|
||||||
)
|
i += 1
|
||||||
if gapi_cloudidentity_userinvitations.is_invitable_user(alias):
|
else:
|
||||||
controlflow.system_error_exit(51, f'Alias not updated, {alias} is an unmanaged account')
|
controlflow.system_error_exit(3, f'{myarg} is not a valid argument for "gam update alias"')
|
||||||
|
if verifyTarget:
|
||||||
|
target_type = verify_alias_target_exists()
|
||||||
|
if target_type is None:
|
||||||
|
controlflow.system_error_exit(51, f'Alias not updated, {target_email} does not exist')
|
||||||
try:
|
try:
|
||||||
gapi.call(cd.users().aliases(),
|
gapi.call(cd.users().aliases(),
|
||||||
'delete',
|
'delete',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user