Example #1
0
def test_build_cofig_for_multi():
    assert build_es_conn_config({
        "es_host":"localhost",
        "es_port": 9200
    })['es_host'] ==  ['localhost:9200']

    assert build_es_conn_config({
        "es_host": "host1:9200, host2:9200, host3:9300",
        "es_port": 9200
    })['es_host'] == ["host1:9200","host2:9200","host3:9300"]
Example #2
0
def es_client():
    es_conn_config = build_es_conn_config({
        'es_host': es_host,
        'es_port': es_port,
        'es_conn_timeout': es_timeout
    })
    return ElasticSearchClient(es_conn_config)
Example #3
0
def test_build_es_conn_config_es_hosts_csv():
    conf = {}
    conf['es_host'] = 'localhost'
    conf['es_port'] = 9200
    expected = {
        'use_ssl': False,
        'verify_certs': True,
        'ca_certs': None,
        'client_cert': None,
        'client_key': None,
        'http_auth': None,
        'es_username': '******',
        'es_password': '******',
        'es_api_key': 'KEY',
        'es_bearer': 'BEARE',
        'aws_region': None,
        'profile': None,
        'headers': None,
        'es_host': 'localhost',
        'es_hosts': ['host1:123', 'host2:9200'],
        'es_port': 9200,
        'es_url_prefix': '',
        'es_conn_timeout': 20,
        'send_get_body_as': 'GET',
        'ssl_show_warn': True
    }
    actual = build_es_conn_config(conf)
    assert expected == actual
Example #4
0
def test_build_es_conn_config(es_host, es_port, es_conn_timeout,
                              es_send_get_body_as, ssl_show_warn, es_username,
                              es_password, es_api_key, es_bearer, aws_region,
                              profile, use_ssl, verify_certs, ca_certs,
                              client_cert, client_key, es_url_prefix,
                              expected_data):
    try:
        conf = {}
        if es_host:
            conf['es_host'] = es_host
        if es_port:
            conf['es_port'] = es_port
        if es_conn_timeout:
            conf['es_conn_timeout'] = es_conn_timeout
        if es_send_get_body_as:
            conf['es_send_get_body_as'] = es_send_get_body_as
        if ssl_show_warn != '':
            conf['ssl_show_warn'] = ssl_show_warn
        if es_username:
            conf['es_username'] = es_username
        if es_password:
            conf['es_password'] = es_password
        if es_api_key:
            conf['es_api_key'] = es_api_key
        if es_bearer:
            conf['es_bearer'] = es_bearer
        if aws_region:
            conf['aws_region'] = aws_region
        if profile:
            conf['profile'] = profile
        if use_ssl != '':
            conf['use_ssl'] = use_ssl
        if verify_certs != '':
            conf['verify_certs'] = verify_certs
        if ca_certs:
            conf['ca_certs'] = ca_certs
        if client_cert:
            conf['client_cert'] = client_cert
        if client_key:
            conf['client_key'] = client_key
        if es_url_prefix:
            conf['es_url_prefix'] = es_url_prefix
        actual = build_es_conn_config(conf)
        assert expected_data == actual
    except KeyError:
        assert expected_data
Example #5
0
def es_client():
    es_conn_config = build_es_conn_config({'es_host': es_host, 'es_port': es_port, 'es_conn_timeout': es_timeout})
    return ElasticSearchClient(es_conn_config)