Ejemplo n.º 1
0
def create_tasks(server_to_writer):
    """
    Create a pair of Producer-Consumer objects for each endpoint enabled within
    the account defined in config, or retrieve child accounts and do the same
    if the account is MSP. Return a list containing the asyncio tasks for
    running those objects.

    @param writer   Dictionary mapping server ids to writer objects

    @return list of asyncio tasks for running the Producer and Consumer objects
    """
    tasks = []

    # Object with functions needed to utilize log API calls
    admin = create_admin(Config.get_account_ikey(),
                         Config.get_account_skey(),
                         Config.get_account_hostname(),
                         is_msp=Config.account_is_msp(),
                         proxy_server=Config.get_proxy_server(),
                         proxy_port=Config.get_proxy_port())

    # This is where functionality would be added to check if an account is MSP
    # (Config.account_is_msp), and then retrieve child accounts (ignoring those
    # in a blocklist) if the account is indeed MSP
    # TODO: Implement blocklist
    if Config.account_is_msp():
        child_account = admin.get_child_accounts()
        child_accounts_id = [
            account['account_id'] for account in child_account
        ]

        for account in child_accounts_id:
            # TODO: This can be made into a separate function
            for mapping in Config.get_account_endpoint_server_mappings():
                # Get the writer to be used for this set of endpoints
                writer = server_to_writer[mapping.get('server')]

                for endpoint in mapping.get('endpoints'):
                    new_tasks = create_consumer_producer_pair(
                        endpoint, writer, admin, account)
                    tasks.extend(new_tasks)
    else:
        for mapping in Config.get_account_endpoint_server_mappings():
            # Get the writer to be used for this set of endpoints
            writer = server_to_writer[mapping.get('server')]

            for endpoint in mapping.get('endpoints'):
                new_tasks = create_consumer_producer_pair(
                    endpoint, writer, admin)
                tasks.extend(new_tasks)

    return tasks
Ejemplo n.º 2
0
    def test_get_account_endpoint_server_mappings(self):
        config = {'account': {'endpoint_server_mappings': {'auth': 'ha.com'}}}

        Config.set_config(config)
        endpoint_server_mappings = Config.get_account_endpoint_server_mappings(
        )

        self.assertEqual(endpoint_server_mappings, {'auth': 'ha.com'})