brynq-sdk-elastic 1.0.0__tar.gz → 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_elastic
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Summary: elastic wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -1,3 +1,4 @@
1
+ import warnings
1
2
  import requests
2
3
  import json
3
4
  import datetime
@@ -15,17 +16,34 @@ class Elastic:
15
16
  """
16
17
  try:
17
18
  self.verify = False
18
- if os.getenv('BRYNQ_ENVIRONMENT') == 'prod':
19
- self.elasticsearch_host = f'https://{os.getenv("ELASTIC_HOST_LIVE", "localhost")}:{os.getenv("ELASTIC_PORT_LIVE", "9200")}'
20
- self.kibana_host = f'http://{os.getenv("ELASTIC_HOST_LIVE", "localhost")}:{os.getenv("KIBANA_PORT_LIVE", "5601")}'
21
- self.elastic_token = os.getenv('ELASTIC_API_KEY_LIVE', api_key)
22
- else:
23
- self.elasticsearch_host = f'https://{os.getenv("ELASTIC_HOST_STAGING", "localhost")}:{os.getenv("ELASTIC_PORT_STAGING", "9200")}'
24
- self.kibana_host = f'http://{os.getenv("ELASTIC_HOST_STAGING", "localhost")}:{os.getenv("KIBANA_PORT_STAGING", "5601")}'
25
- self.elastic_token = os.getenv('ELASTIC_API_KEY_STAGING', api_key)
26
-
27
- self.client_user = os.getenv('BRYNQ_CUSTOMER_NAME', 'default').lower().replace(' ', '_') if customer_name is None else customer_name.lower().replace(' ', '_')
19
+ elasticsearch_host = os.getenv("ELASTIC_HOST", "localhost")
20
+ elasticsearch_port = os.getenv("ELASTIC_PORT", "9200")
21
+ kibana_port = os.getenv("KIBANA_PORT", "5601")
22
+ elastic_token = os.getenv('ELASTIC_API_KEY', None)
23
+
24
+ # Build the host URLs
25
+ self.elasticsearch_host = f'https://{elasticsearch_host}:{elasticsearch_port}'
26
+ self.kibana_host = f'http://{elasticsearch_host}:{kibana_port}'
27
+ self.elastic_token = elastic_token if elastic_token is not None else api_key
28
28
  self.space_name = os.getenv('ELASTIC_SPACE', 'default') if space_name is None else space_name
29
+ self.client_user = os.getenv('BRYNQ_SUBDOMAIN', 'default').lower().replace(' ', '_') if customer_name is None else customer_name.lower().replace(' ', '_')
30
+
31
+ # Check for missing environment variables and show warnings
32
+ if elasticsearch_host == "localhost":
33
+ warnings.warn("Environment variable ELASTIC_HOST is not set. Using default: localhost")
34
+ if elasticsearch_port == "9200":
35
+ warnings.warn("Environment variable ELASTIC_PORT is not set. Using default: 9200")
36
+ if kibana_port == "5601":
37
+ warnings.warn("Environment variable KIBANA_PORT is not set. Using default: 5601")
38
+ if elastic_token is None:
39
+ raise KeyError("Environment variable ELASTIC_API_KEY is not set and no api_key is provided. Please specify either one and try again")
40
+ if self.space_name == 'default':
41
+ warnings.warn("Environment variable ELASTIC_SPACE is not set. Using 'default'")
42
+ if self.client_user == 'default':
43
+ warnings.warn("Environment variable BRYNQ_SUBDOMAIN is not set and customer_name is not specified. Using 'default'")
44
+
45
+ print(f"Elasticsearch running on: {elasticsearch_host}")
46
+
29
47
  self.timestamp = int(datetime.datetime.now().timestamp())
30
48
  self.elastic_headers = {
31
49
  'Content-Type': 'application/json',
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-elastic
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Summary: elastic wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name='brynq_sdk_elastic',
6
- version='1.0.0',
6
+ version='2.0.0',
7
7
  description='elastic wrapper from BrynQ',
8
8
  long_description='elastic wrapper from BrynQ',
9
9
  author='BrynQ',