def deregister_delegated_administrator(self, **kwargs): account_id = kwargs["AccountId"] service = kwargs["ServicePrincipal"] if account_id == ACCOUNT_ID: raise ConstraintViolationException( "You cannot register master account/yourself as delegated administrator for your organization." ) admin = next( (admin for admin in self.admins if admin.account.id == account_id), None, ) if admin is None: account = next( (account for account in self.accounts if account.id == kwargs["AccountId"]), None, ) if account: raise AccountNotRegisteredException raise AccountNotFoundException admin.remove_service_principal(service) # remove account, when no services attached if not admin.services: self.admins.remove(admin)
def register_delegated_administrator(self, **kwargs): account_id = kwargs["AccountId"] if account_id == ACCOUNT_ID: raise ConstraintViolationException( "You cannot register master account/yourself as delegated administrator for your organization." ) account = self.get_account_by_id(account_id) admin = next( (admin for admin in self.admins if admin.account.id == account_id), None) if admin is None: admin = FakeDelegatedAdministrator(account) self.admins.append(admin) admin.add_service_principal(kwargs["ServicePrincipal"])