in source/Lambda/innovation_create_account_ou.py [0:0]
def validate_inputs(mgmt_name, sbx_name, mgmt_email, sbx_email, mgmt_ou, sbx_ou, client, root):
error_flag = False
error_reason = ""
logger.info("Validating input parameters")
if mgmt_name == sbx_name:
error_reason = error_reason + "Account names cannot be same" + " | "
error_flag = True
if mgmt_email == sbx_email:
error_reason = error_reason + "Emails cannot be same" + " | "
error_flag = True
if mgmt_ou == sbx_ou:
error_reason = error_reason + "OU names cannot be same" + " | "
error_flag = True
# Validate Emails
if not re.match('^[a-z0-9\+]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$', mgmt_email.lower()) or not re.match(
'^[a-z0-9\+]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$', sbx_email.lower()):
error_reason = error_reason + "Invalid Email in the input parameters" + " | "
error_flag = True
# Validate Email already exists
response = client.list_accounts()
all_accounts = response["Accounts"]
while 'NextToken' in response.keys():
response = client.list_accounts(NextToken=response["NextToken"])
all_accounts = all_accounts + response["Accounts"]
for acct in all_accounts:
if mgmt_email == acct["Email"] or sbx_email == acct["Email"]:
error_reason = error_reason + "Account Email already exists" + " | "
error_flag = True
break
# Validate OU already exists
response = client.list_organizational_units_for_parent(ParentId=root)
all_ous = response['OrganizationalUnits']
while 'NextToken' in response.keys():
response = client.list_organizational_units_for_parent(
ParentId=root, NextToken=response["NextToken"])
all_ous = all_ous + response['OrganizationalUnits']
for ou in all_ous:
if mgmt_ou == ou['Name'] or sbx_ou == ou['Name']:
error_reason = error_reason + "OU already exists under root" + " | "
error_flag = True
break
if error_flag is True:
message = {'MESSAGE': 'Invalid Inputs :'+ error_reason, 'FILE': __file__.split('/')[-1],
'METHOD': inspect.stack()[0][3]}
logger.error(message)
raise Exception(error_reason)
return