"""Opensearch connector.""" from typing import Optional import config from opensearchpy import OpenSearch, RequestsHttpConnection def get_client() -> Optional[OpenSearch]: """Get OpenSearch client instance. Uses connection variables from the environment defined in config. Returns: mixed: OpenSearch client instance or None if not configured. """ if not (config.OPENSEARCH_HOST and config.OPENSEARCH_PORT): return None return OpenSearch( hosts=[ { "host": config.OPENSEARCH_HOST, "port": config.OPENSEARCH_PORT, "timeout": config.OPENSEARCH_DEFAULT_TIMEOUT, } ], http_auth=(config.OPENSEARCH_USER, config.OPENSEARCH_PASSWORD), use_ssl=True, connection_class=RequestsHttpConnection, pool_maxsize=config.OPENSEARCH_POOL_MAXSIZE, ) os_client = get_client()