def run(accounts):
    accounts_api = esp_sdk.ExternalAccountsApi()
    disabled_signature_ids = get_disabled_signatures_for_account(
        accounts['template_account_id'], accounts_api)
    copy_config_to_accounts(accounts['target_account_ids'],
                            disabled_signature_ids, accounts_api)
    return
def list_external_accounts():
    # Get a list of accounts
    accounts_api = esp_sdk.ExternalAccountsApi()
    all_accounts = accounts_api.list(page={'size': 100})
    account_ids = []
    for acct in all_accounts:
        account_ids.append(acct.id)
    return account_ids
def main(options):
    accounts_api = esp_sdk.ExternalAccountsApi()
    aws_accounts_api = esp_sdk.ExternalAccountsAmazonApi()
    account = accounts_api.list(filter={'name_eq': options['account_name']})[0]
    response = aws_accounts_api.update(account.id,
                                       arn=options['arn'],
                                       external_id=options['external_id'])
    print(response)
    exit()
    return
Beispiel #4
0
def main():
    # Initialize required API endpoints
    accounts_api = esp_sdk.ExternalAccountsApi()
    reports_api = esp_sdk.ReportsApi()
    report_export_api = esp_sdk.ReportExportApi()
    # Get a list of accounts
    all_accounts = accounts_api.list(page={'size': 100})
    account_ids = []
    for acct in all_accounts:
        account_ids.append(acct.id)
    # Get a list of recent reports
    all_reports = reports_api.list(page={'size': 100})
    reports = []
    for report in all_reports:
        if len(reports) >= len(account_ids):
            break
        reports.append({
            'report_id': report.id,
            'account_id': report.external_account_id
        })

    # Ensure there are no more and no less than one report for each account
    report_ids = []
    for account_id in account_ids:
        count = 0
        for report in reports:
            if report['account_id'] == account_id and count < 1:
                count += 1
                report_ids.append(report['report_id'])
            elif count >= 1:
                break
        if count == 0:
            time.sleep(2)
            report_to_add = reports_api.list(
                filter={'external_account_id_eq': account_id})[0]
            report_ids.append(report_to_add.id)

    # Request file export
    response = report_export_api.request_file('csv',
                                              report_ids,
                                              include='exported_report')

    print(
        'The exported report has been requested and will be sent to your email'
    )
    exit()
def main(event, context):
    """ Run checks and do the work """

    try:
        eaccounts_api = esp_sdk.ExternalAccountsApi()
        eaccounts = eaccounts_api.list(include='team.sub_organization,team',
                                       page='{:number=>1,+:size=>1000}')
    except esp_sdk.rest.ApiException as e:
        if str(e.status) == '401':
            print('Error: Please check your ESP credentials / API keys.')
        else:
            print(e)
        sys.exit(1)
    csv_file_name = '/tmp/esp_eaccounts_report.csv'
    report = create_eaccounts_report(eaccounts)
    result = create_csv_file(csv_file_name, report)
    upload = upload_csv_file(csv_file_name,
                             'accountlist-%s.csv' % time.strftime("%d-%m-%Y"))
    print(result)
def main(options):
    accounts_api = esp_sdk.ExternalAccountsApi()
    custom_signatures_api = esp_sdk.CustomSignaturesApi()
    # Get all accounts
    accounts = accounts_api.list()
    # Get signatures and their custom risk levels
    # for each account
    all_signatures = []
    resp = custom_signatures_api.list(include='external_accounts')
    for acct in accounts:
        # Retrieve the built-in signatures
        built_in_signatures = get_built_in_signatures_for_account(
            options, acct)
        for signature in built_in_signatures:
            all_signatures.append(signature)
        # Retrieve the custom signatures
        custom_signatures = get_custom_signatures_for_account(acct, resp)
        for signature in custom_signatures:
            all_signatures.append(signature)
    signatures_to_csv(all_signatures)
    exit()
def main(options):
    accounts_api = esp_sdk.ExternalAccountsApi()
    # Get Account Info
    accounts = get_accounts(options, accounts_api)
    run(accounts)
    exit()