Skip to content

Commit

Permalink
[ELASTIC-CERT]: Import elastic on cert
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid authored and ypkang committed Apr 19, 2023
1 parent 936b0e9 commit 299913b
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions jaseci_core/jaseci/extens/svc/elastic_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,34 @@ class ElasticService(JsOrc.CommonService):
###################################################

def run(self):
if not self.config.get("auth"):
kube = JsOrc.svc("kube", KubeService)
kube = JsOrc.svc("kube", KubeService)
if kube.is_running():
elasticsearches = kube.resolve_manifest(
self.manifest, *JsOrc.overrided_namespace("elastic", self.manifest_type)
).get("Elasticsearch", [])

if elasticsearches:
metadata: dict = elasticsearches["jaseci"]["metadata"]
auth = kube.get_secret(
f'{metadata.get("name")}-es-elastic-user',
"elastic",

cert = kube.get_secret(
f'{metadata.get("name")}-es-http-certs-internal',
"ca.crt",
metadata.get("namespace"),
)
self.config[
"auth"
] = f'basic {b64encode(f"elastic:{auth}".encode()).decode()}'

if cert:
with open("elastic-certificate.crt", "w") as cert_file:
cert_file.write(cert)

if not self.config.get("auth"):
auth = kube.get_secret(
f'{metadata.get("name")}-es-elastic-user',
"elastic",
metadata.get("namespace"),
)
self.config[
"auth"
] = f'basic {b64encode(f"elastic:{auth}".encode()).decode()}'

self.app = Elastic(self.config)
self.app.health("timeout=1s")
Expand Down Expand Up @@ -106,12 +119,18 @@ def __init__(self, config: dict):

def _get(self, url: str, json: dict = None):
return get(
f"{self.url}{url}", json=json, headers=self.headers, verify=False
f"{self.url}{url}",
json=json,
headers=self.headers,
verify="elastic-certificate.crt",
).json()

def _post(self, url: str, json: dict = None):
return post(
f"{self.url}{url}", json=json, headers=self.headers, verify=False
f"{self.url}{url}",
json=json,
headers=self.headers,
verify="elastic-certificate.crt",
).json()

def post(self, url: str, body: dict, index: str = "", suffix: str = ""):
Expand Down

0 comments on commit 299913b

Please sign in to comment.