def get_account_details()

in enrichment_function/import_findings/helper.py [0:0]


    def get_account_details(account_id, role_name):
        account_details = {}
        organizations_client = AwsHelper().get_client('organizations')
        response = organizations_client.describe_account(AccountId=account_id)
        account_details["Name"] = response["Account"]["Name"]
        response = organizations_client.list_parents(ChildId=account_id)
        ou_id = response["Parents"][0]["Id"]
        if ou_id and response["Parents"][0]["Type"] == "ORGANIZATIONAL_UNIT":
            response = organizations_client.describe_organizational_unit(OrganizationalUnitId=ou_id)
            account_details["OUName"] = response["OrganizationalUnit"]["Name"]
        elif ou_id:
            account_details["OUName"] = "ROOT"
        if role_name:
            account_client = AwsHelper().get_session_for_role(role_name).client("account")
        else:
            account_client = AwsHelper().get_client('account')
        account_details["AlternateContact"] = {}
        try:
            response = account_client.get_alternate_contact(
                AccountId = account_id,
                AlternateContactType = 'SECURITY'
            )
            AccountHelper.logger.debug("Alternate Contact Response: %", str(response))
            if response['AlternateContact']:
                print("contact :{}".format(str(response["AlternateContact"])))
                account_details["AlternateContact"] = response["AlternateContact"]
        except account_client.exceptions.AccessDeniedException as error:
            #Potentially due to calling alternate contact on Org Management account
            AccountHelper.logger.warning(error.response['Error']['Message'])
        except account_client.exceptions.ResourceNotFoundException as exception:
            #When there is no alternate contacts set
            AccountHelper.logger.warning(exception.response['Error']['Message'])

        response = organizations_client.list_tags_for_resource(ResourceId=account_id)
        results = response["Tags"]
        while "NextToken" in response:
            response = organizations_client.list_tags_for_resource(ResourceId=account_id, NextToken=response["NextToken"])
            results.extend(response["Tags"])

        account_details["tags"] = results
        AccountHelper.logger.info("account_details: %s" , str(account_details))
        return account_details