Skip to content

Commit

Permalink
MINIFICPP-2456 Remove curl output from Elasticsearch responses
Browse files Browse the repository at this point in the history
Closes #1867

Signed-off-by: Marton Szasz <[email protected]>
  • Loading branch information
lordgamez authored and szaszm committed Sep 26, 2024
1 parent 66e465d commit a6ef49d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions docker/test/integration/cluster/checkers/ElasticSearchChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,29 @@ def __init__(self, container_communicator):
self.container_communicator = container_communicator

def is_elasticsearch_empty(self, container_name):
(code, output) = self.container_communicator.execute_command(container_name, ["curl", "-u", "elastic:password", "-k", "-XGET", "https://localhost:9200/_search"])
(code, output) = self.container_communicator.execute_command(container_name, ["curl", "-s", "-u", "elastic:password", "-k", "-XGET", "https://localhost:9200/_search"])
return code == 0 and '"hits":[]' in output

def create_doc_elasticsearch(self, container_name, index_name, doc_id):
(code, output) = self.container_communicator.execute_command(container_name, ["/bin/bash", "-c",
"curl -u elastic:password -k -XPUT https://localhost:9200/" + index_name + "/_doc/" + doc_id + " -H Content-Type:application/json -d'{\"field1\":\"value1\"}'"])
"curl -s -u elastic:password -k -XPUT https://localhost:9200/" + index_name + "/_doc/" + doc_id + " -H Content-Type:application/json -d'{\"field1\":\"value1\"}'"])
return code == 0 and ('"_id":"' + doc_id + '"') in output

def check_elastic_field_value(self, container_name, index_name, doc_id, field_name, field_value):
(code, output) = self.container_communicator.execute_command(container_name, ["/bin/bash", "-c",
"curl -u elastic:password -k -XGET https://localhost:9200/" + index_name + "/_doc/" + doc_id])
"curl -s -u elastic:password -k -XGET https://localhost:9200/" + index_name + "/_doc/" + doc_id])
return code == 0 and (field_name + '":"' + field_value) in output

def elastic_generate_apikey(self, elastic_container_name):
(_, output) = self.container_communicator.execute_command(elastic_container_name, ["/bin/bash", "-c",
"curl -u elastic:password -k -XPOST https://localhost:9200/_security/api_key -H Content-Type:application/json -d'{\"name\":\"my-api-key\",\"expiration\":\"1d\",\"role_descriptors\":{\"role-a\": {\"cluster\": [\"all\"],\"index\": [{\"names\": [\"my_index\"],\"privileges\": [\"all\"]}]}}}'"])
(code, output) = self.container_communicator.execute_command(elastic_container_name, ["/bin/bash", "-c",
"curl -s -u elastic:password -k -XPOST https://localhost:9200/_security/api_key -H Content-Type:application/json -d'{\"name\":\"my-api-key\",\"expiration\":\"1d\",\"role_descriptors\":{\"role-a\": {\"cluster\": [\"all\"],\"index\": [{\"names\": [\"my_index\"],\"privileges\": [\"all\"]}]}}}'"])
if code != 0:
return None
output_lines = output.splitlines()
result = json.loads(output_lines[-1])
return result["encoded"]

def add_elastic_user_to_opensearch(self, container_name):
(code, output) = self.container_communicator.execute_command(container_name, ["/bin/bash", "-c",
'curl -u admin:admin -k -XPUT https://{hostname}:9200/_plugins/_security/api/internalusers/elastic -H Content-Type:application/json -d\'{{"password":"password","backend_roles":["admin"]}}\''.format(hostname=container_name)])
'curl -s -u admin:admin -k -XPUT https://{hostname}:9200/_plugins/_security/api/internalusers/elastic -H Content-Type:application/json -d\'{{"password":"password","backend_roles":["admin"]}}\''.format(hostname=container_name)])
return code == 0 and '"status":"CREATED"' in output
2 changes: 1 addition & 1 deletion docker/test/integration/features/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def retry_check(max_tries=5, retry_interval=1):
def retry_check_func(func):
@functools.wraps(func)
def retry_wrapper(*args, **kwargs):
for i in range(max_tries):
for _ in range(max_tries):
if func(*args, **kwargs):
return True
time.sleep(retry_interval)
Expand Down

0 comments on commit a6ef49d

Please sign in to comment.