def setUp(self): self.account = Account( uuid = test_account_object['uuid'], foreign = test_account_object['foreign'], name = test_account_object['name'], created_at = test_account_object['created_at'] )
def _add_trusted_account(self, trust_policy, role): accounts = trust_policy.get_trusted_accounts_uuids() role.trusted_accounts.clear() for acc in accounts: trusted_account = Account.find_or_create(acc, foreign=True) trusted_account.job_uuid = self.job_uuid role.trusted_accounts.append(trusted_account)
def test_trusted_account(self): role = Role(arn=test_role_object['arn'], name=test_role_object['name'], last_used=test_role_object['last_used'], created_at=test_role_object['created_at']) acc = Account(uuid="123123123", name="Namef") role.trusted_accounts.append(acc) assert role.trusted_accounts[0].name == "Namef"
def _add_trusted_users(self, trust_policy, role): users = trust_policy.get_trusted_principal_arns('user') role.trusted_users.clear() for user in users: trusted_user = User.find_or_create(user.arn, foreign=True) if trusted_user.foreign: trusted_user.account = Account.find_or_create(user.account_number, foreign=True) trusted_user.job_uuid = self.job_uuid role.trusted_users.append(trusted_user)
def _add_trusted_role(self, trust_policy, role): roles = trust_policy.get_trusted_principal_arns('role') role.trusted_roles.clear() for assuming_role in roles: trusted_role = Role.find_or_create(assuming_role.arn, foreign=True) if trusted_role.foreign: trusted_role.account = Account.find_or_create(assuming_role.account_number, foreign=True) trusted_role.job_uuid = self.job_uuid role.trusted_roles.append(trusted_role)
def get_accounts(): job_uuid = datetime.now().strftime('%Y%m%d-%H-%M%S-') + str(uuid4()) accounts = Account.query.filter_by(foreign=False).all() if os.environ.get('SCOPE') == 'single-account': acc = Account.find_or_create(POLP_FICTION_MASTER_ACCOUNT) db.session.add(acc) db.session.commit() accounts = [acc] return accounts, job_uuid
def set_account_to_role(self): acc = Account(uuid="123456789", provider="AWS", name="test_account", created_at=datetime.now()) self.role.account = acc assert self.role.account == acc assert self.role.account.name == "123456789"
def post(): # if os.environ.get('SCOPE') == 'single-account': # return {"msg": "This endpoint is of no use when SCOPE is local, please read the documentation for more info"}, 417 job_uuid= datetime.now().strftime('%Y%m%d-%H-%M%S-') + str(uuid4()) try: org = Organization() accounts = org.get_accounts() for uuid, name in accounts.items(): acc = Account.find_or_create(uuid=uuid) acc.job_uuid = job_uuid acc.name = name acc.updated_at = datetime.now() db.session.add(acc) db.session.commit() _delete_old_accounts(job_uuid) return {"message": "Accounts job ran successfully"}, 201 except Exception as e: db.session.rollback() return {"error": str(e)}, 503 # TODO: See if we need to categorize Exceptions finally: db.session.close()
def setUp(self): self.acc = Account(name="account", uuid="123456789")
def test_find_or_create(self, mock_db_query): account_new = Role(arn='arn') mock_db_query.return_value.filter_by.return_value.first.return_value = account_new account = Account.find_or_create("arn") assert account.arn == account_new.arn assert account == account_new