diff --git a/Snap-Tool/modules/ElasticClass.py b/Snap-Tool/modules/ElasticClass.py index 1a31b5e..1ac2bab 100644 --- a/Snap-Tool/modules/ElasticClass.py +++ b/Snap-Tool/modules/ElasticClass.py @@ -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. @@ -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. @@ -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") diff --git a/Snap-Tool/modules/FormClass.py b/Snap-Tool/modules/FormClass.py index e4d493b..2e4b345 100644 --- a/Snap-Tool/modules/FormClass.py +++ b/Snap-Tool/modules/FormClass.py @@ -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. diff --git a/Snap-Tool/modules/UtilsClass.py b/Snap-Tool/modules/UtilsClass.py index fe91a28..941b98b 100644 --- a/Snap-Tool/modules/UtilsClass.py +++ b/Snap-Tool/modules/UtilsClass.py @@ -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() diff --git a/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc index 8270de8..5784f37 100644 Binary files a/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc differ diff --git a/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc index 5301581..dfc1140 100644 Binary files a/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc differ diff --git a/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc index ca8bdb6..3dd85e6 100644 Binary files a/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc differ