qlands / elasticfeeds

A Python library for managing feeds using ElasticSearch
Other
19 stars 4 forks source link

support / example for basicauth #3

Closed johndpope closed 1 year ago

johndpope commented 1 year ago

I looked at the dockercompose - got stuck - and ended up using docker-elk (15,000 stars) https://github.com/deviantony/docker-elk/blob/main/docker-compose.yml

this requires a setup / that initiates the passwords (somewhat mandatory in latest version?)

I upgraded the test_manager . but now I want to pass in the basic_auth - it seems to support it

I attempt to extend manager to pass the basic_auth - but no joy. https://gist.github.com/johndpope/07d03a03cf94d447ec3e61c405081385

but now the


def test_manager():
    es_host = "0.0.0.0"
    es_port = 9200
    use_ssl = "False"
    ready = False
    host = "http://{}:{}/_cluster/health".format(es_host, es_port)
    print("Waiting for ES to be ready check :",host)
    session = requests.Session()
    session.auth = ('elastic', 'changeme')
    while not ready:
        try:
            if use_ssl == "False":
                resp = session.get(
                    "http://{}:{}/_cluster/health".format(es_host, es_port)
                )
            else:
                resp = session.get(
                    "https://{}:{}/_cluster/health".format(es_host, es_port)
                )
            data = resp.json()
            print("json:",data)
            if data["status"] == "yellow" or data["status"] == "green":
                ready = True
            else:
                time.sleep(30)
        except Exception as e:
            print(str(e))
            time.sleep(30)

    print("ES is ready")

    now = datetime.datetime.now()
    tst_manager = Manager(
        "testfeeds",
        "testnetwork",
        delete_network_if_exists=True,
        delete_feeds_if_exists=True,
        basic_auth=HTTPDigestAuth('elastic', 'changeme')
    )

UPDATE

I got around this by disabling security

Screenshot from 2023-08-21 13-43-05

but now I run into a problem with v8 elastic search

(torch2) ➜ elasticfeeds git:(master) ✗ python elasticfeeds/tests/test_00_manager.py Waiting for ES to be ready check : http://0.0.0.0:9200/_cluster/health json: {'cluster_name': 'docker-cluster', 'status': 'green', 'timed_out': False, 'number_of_nodes': 1, 'number_of_data_nodes': 1, 'active_primary_shards': 0, 'active_shards': 0, 'relocating_shards': 0, 'initializing_shards': 0, 'unassigned_shards': 0, 'delayed_unassigned_shards': 0, 'number_of_pending_tasks': 0, 'number_of_in_flight_fetch': 0, 'task_max_waiting_in_queue_millis': 0, 'active_shards_percent_as_number': 100.0} ES is ready args: (<elasticsearch._sync.client.indices.IndicesClient object at 0x7f1bb3afa7a0>, 'feeds') Traceback (most recent call last): File "/home/oem/Documents/gitWorkspace/elasticfeeds/elasticfeeds/tests/test_00_manager.py", line 173, in test_manager() File "/home/oem/Documents/gitWorkspace/elasticfeeds/elasticfeeds/tests/test_00_manager.py", line 42, in test_manager tst_manager = Manager( File "/home/oem/Documents/gitWorkspace/elasticfeeds/elasticfeeds/manager/manager.py", line 278, in init if not connection.indices.exists("feeds"): File "/home/oem/miniconda3/envs/torch2/lib/python3.10/site-packages/elasticsearch/_sync/client/utils.py", line 308, in wrapped raise TypeError( TypeError: Positional arguments can't be used with Elasticsearch API methods. Instead only use keyword arguments.

Not sure why this regressed in v8.

Screenshot from 2023-08-21 13-46-09

New api

Screenshot from 2023-08-21 13-49-13

running

pip install elasticsearch==7.7.1

can see old api from version 7. Screenshot from 2023-08-21 13-50-03

UPDATE making progress - just needed to add index= to front of some methods. https://gist.github.com/johndpope/33e6acec7505b3d7a539b0ad763f088b