Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
  • Loading branch information
“Erick committed Oct 28, 2021
1 parent 64bb48c commit 19a04e2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
55 changes: 25 additions & 30 deletions Snap-Tool/modules/ElasticClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class Elastic:
"""
form_dialog = None

"""
Property that stores the information defined in the Snap-Tool configuration file.
"""
snap_tool_conf = None

"""
Constructor for the Elastic class.
Expand All @@ -47,7 +42,6 @@ def __init__(self, form_dialog):
self.logger = Logger()
self.form_dialog = form_dialog
self.utils = Utils(form_dialog)
self.snap_tool_conf = self.utils.readYamlFile(self.utils.getPathSnapTool('conf') + '/snap_tool_conf.yaml', 'r')

"""
Method that creates a connection object with ElasticSearch.
Expand All @@ -67,54 +61,55 @@ def __init__(self, form_dialog):
"""
def getConnectionElastic(self):
conn_es = None
snap_tool_conf = self.utils.readYamlFile(self.utils.getPathSnapTool('conf') + '/snap_tool_conf.yaml', 'r')
try:
if(not self.snap_tool_conf['use_ssl'] == True) and (not self.snap_tool_conf['use_http_auth'] == True):
conn_es = Elasticsearch(self.snap_tool_conf['es_host'],
port = self.snap_tool_conf['es_port'],
if(not snap_tool_conf['use_ssl'] == True) and (not snap_tool_conf['use_http_auth'] == True):
conn_es = Elasticsearch(snap_tool_conf['es_host'],
port = snap_tool_conf['es_port'],
connection_class = RequestsHttpConnection,
use_ssl = False)
if(not self.snap_tool_conf['use_ssl'] == True) and self.snap_tool_conf['use_http_auth'] == True:
conn_es = Elasticsearch(self.snap_tool_conf['es_host'],
port = self.snap_tool_conf['es_port'],
if(not snap_tool_conf['use_ssl'] == True) and snap_tool_conf['use_http_auth'] == True:
conn_es = Elasticsearch(snap_tool_conf['es_host'],
port = snap_tool_conf['es_port'],
connection_class = RequestsHttpConnection,
http_auth = (self.utils.decryptAES(self.snap_tool_conf['http_auth_user']).decode('utf-8'), self.utils.decryptAES(self.snap_tool_conf['http_auth_pass']).decode('utf-8')),
http_auth = (self.utils.decryptAES(snap_tool_conf['http_auth_user']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['http_auth_pass']).decode('utf-8')),
use_ssl = False)
if self.snap_tool_conf['use_ssl'] == True and (not self.snap_tool_conf['use_http_auth'] == True):
if not self.snap_tool_conf['valid_certificate']:
conn_es = Elasticsearch(self.snap_tool_conf['es_host'],
port = self.snap_tool_conf['es_port'],
if snap_tool_conf['use_ssl'] == True and (not snap_tool_conf['use_http_auth'] == True):
if not snap_tool_conf['valid_certificate']:
conn_es = Elasticsearch(snap_tool_conf['es_host'],
port = snap_tool_conf['es_port'],
connection_class = RequestsHttpConnection,
use_ssl = True,
verify_certs = False,
ssl_show_warn = False)
else:
context = create_default_context(cafile = self.snap_tool_conf['path_certificate'])
conn_es = Elasticsearch(self.snap_tool_conf['es_host'],
port = self.snap_tool_conf['es_port'],
context = create_default_context(cafile = snap_tool_conf['path_certificate'])
conn_es = Elasticsearch(snap_tool_conf['es_host'],
port = snap_tool_conf['es_port'],
connection_class = RequestsHttpConnection,
use_ssl = True,
verify_certs = True,
ssl_context = context)
if self.snap_tool_conf['use_ssl'] == True and self.snap_tool_conf['use_http_auth'] == True:
if not self.snap_tool_conf['valid_certificate'] == True:
conn_es = Elasticsearch(self.snap_tool_conf['es_host'],
port = self.snap_tool_conf['es_port'],
if snap_tool_conf['use_ssl'] == True and snap_tool_conf['use_http_auth'] == True:
if not snap_tool_conf['valid_certificate'] == True:
conn_es = Elasticsearch(snap_tool_conf['es_host'],
port = snap_tool_conf['es_port'],
connection_class = RequestsHttpConnection,
http_auth = (self.utils.decryptAES(self.snap_tool_conf['http_auth_user']).decode('utf-8'), self.utils.decryptAES(self.snap_tool_conf['http_auth_pass']).decode('utf-8')),
http_auth = (self.utils.decryptAES(snap_tool_conf['http_auth_user']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['http_auth_pass']).decode('utf-8')),
use_ssl = True,
verify_certs = False,
ssl_show_warn = False)
else:
context = create_default_context(cafile = self.snap_tool_conf['path_certificate'])
conn_es = Elasticsearch(self.snap_tool_conf['es_host'],
port = self.snap_tool_conf['es_port'],
context = create_default_context(cafile = snap_tool_conf['path_certificate'])
conn_es = Elasticsearch(snap_tool_conf['es_host'],
port = snap_tool_conf['es_port'],
connection_class = RequestsHttpConnection,
http_auth = (self.utils.decryptAES(self.snap_tool_conf['http_auth_user']).decode('utf-8'), self.utils.decryptAES(self.snap_tool_conf['http_auth_pass']).decode('utf-8')),
http_auth = (self.utils.decryptAES(snap_tool_conf['http_auth_user']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['http_auth_pass']).decode('utf-8')),
use_ssl = True,
verify_certs = True,
ssl_context = context)
if not conn_es == None:
self.logger.createSnapToolLog("Established connection with: " + self.snap_tool_conf['es_host'] + ':' + str(self.snap_tool_conf['es_port']), 1)
self.logger.createSnapToolLog("Established connection with: " + snap_tool_conf['es_host'] + ':' + str(snap_tool_conf['es_port']), 1)
except (KeyError, exceptions.ConnectionError, exceptions.AuthenticationException, exceptions.AuthorizationException, InvalidURL) as exception:
self.logger.createSnapToolLog(exception, 3)
self.form_dialog.d.msgbox(text = "\nFailed to connect to ElasticSearch. For more information, see the logs.", height = 8, width = 50, title = "Error Message")
Expand Down
4 changes: 2 additions & 2 deletions Snap-Tool/modules/FormClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ def defineConfiguration(self):
if not path.exists(self.configuration.conf_file):
opt_conf_false = self.getDataRadioList("Select a option:", options_conf_false, "Configuration Options")
if opt_conf_false == "Create":
configuration.createConfiguration()
self.configuration.createConfiguration()
else:
opt_conf_true = self.getDataRadioList("Select a option:", options_conf_true, "Configuration Options")
if opt_conf_true == "Modify":
configuration.updateConfiguration()
self.configuration.updateConfiguration()

"""
Method that creates a repository of type FS in ElasticSearch.
Expand Down
2 changes: 1 addition & 1 deletion Snap-Tool/modules/UtilsClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def readYamlFile(self, path_file_yaml, mode):
try:
with open(path_file_yaml, mode) as file_yaml:
data_file_yaml = safe_load(file_yaml)
except IOError as exception:
except (IOError, FileNotFoundError) as exception:
self.logger.createSnapToolLog(exception, 3)
self.form_dialog.d.msgbox(text = "\nError opening or reading the YAML file. For more information, see the logs.", height = 8, width = 50, title = "Error Message")
self.form_dialog.mainMenu()
Expand Down
Binary file modified Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc
Binary file not shown.
Binary file modified Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc
Binary file not shown.
Binary file modified Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc
Binary file not shown.

0 comments on commit 19a04e2

Please sign in to comment.