From fd2ec379b55c3ef82d385a975a54571cc5617477 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:08 +0100 Subject: [PATCH 01/17] Revert "Fix error" This reverts commit 6a6b47a43dcbab9323d27231bcca0986bc3ce138. --- app/__init__.py | 14 +++++++------- app/utils.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 3b8fd49c..86d9347c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -248,7 +248,7 @@ def home(): # Force to get the user credentials to cache them scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=datetime.datetime.now(), - misfire_grace_time=20, args=[cred, session['userid'], get_cred_id()], id='get_cache_creds') + misfire_grace_time=20, args=[cred, get_cred_id()], id='get_cache_creds') # if there are any next url, redirect to it if "next" in session and session["next"]: @@ -496,7 +496,7 @@ def showinfrastructures(): app.logger.exception("Error getting vm info: %s" % ex) radl_json = [] try: - creds = utils.get_cache_creds(cred, session['userid'], get_cred_id()) + creds = utils.get_cache_creds(cred, get_cred_id()) except Exception as ex: app.logger.exception("Error getting user credentials: %s" % ex) creds = [] @@ -766,7 +766,7 @@ def configure(): app.logger.debug("Template: " + json.dumps(toscaInfo[selected_tosca])) try: - creds = utils.get_cache_creds(cred, session['userid'], get_cred_id(), 1) + creds = utils.get_cache_creds(cred, get_cred_id(), 1) except Exception as ex: flash("Error getting user credentials: %s" % ex, "error") creds = [] @@ -1120,7 +1120,7 @@ def manage_creds(): creds = {} try: - creds = utils.get_cache_creds(cred, session['userid'], get_cred_id()) + creds = utils.get_cache_creds(cred, get_cred_id()) # Get the project_id in case it has changed utils.get_project_ids(creds) except Exception as e: @@ -1175,7 +1175,7 @@ def write_creds(): # Get project_id to save it to de DB utils.get_project_ids([creds]) # delete cached credentials - utils.clear_cache_creds(session['userid']) + utils.clear_cache_creds(get_cred_id()) cred.write_creds(creds["id"], get_cred_id(), creds, cred_id in [None, '']) if val_res == 0: flash("Credentials successfully written!", 'success') @@ -1193,7 +1193,7 @@ def delete_creds(): cred_id = request.args.get('cred_id', "") try: # delete cached credentials - utils.clear_cache_creds(session['userid']) + utils.clear_cache_creds(get_cred_id()) cred.delete_cred(cred_id, get_cred_id()) flash("Credentials successfully deleted!", 'success') except Exception as ex: @@ -1212,7 +1212,7 @@ def enable_creds(): if val_res == 2: flash(val_msg, 'warning') # delete cached credentials - utils.clear_cache_creds(session['userid']) + utils.clear_cache_creds(get_cred_id()) cred.enable_cred(cred_id, get_cred_id(), enable) except Exception as ex: flash("Error updating credentials %s!" % ex, 'error') diff --git a/app/utils.py b/app/utils.py index 75622f52..bb202afa 100644 --- a/app/utils.py +++ b/app/utils.py @@ -985,10 +985,10 @@ def merge_templates(template, new_template): return template -def get_cache_creds(cred, userid, creduserid, enabled=None): +def get_cache_creds(cred, userid, enabled=None): global CREDS_CACHE if userid not in CREDS_CACHE: - CREDS_CACHE[userid] = cred.get_creds(creduserid) + CREDS_CACHE[userid] = cred.get_creds(userid) res = [] for cred in CREDS_CACHE[userid]: From 1adf64f6a83e8b3ca6c26df7f980f8e2b62efe1f Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:09 +0100 Subject: [PATCH 02/17] Revert "Fix test" This reverts commit 19014c423848326fce0cd223325ea5737052e996. --- app/tests/test_app.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/tests/test_app.py b/app/tests/test_app.py index 4c682b49..69897d40 100644 --- a/app/tests/test_app.py +++ b/app/tests/test_app.py @@ -576,6 +576,16 @@ def test_manage_creds(self, get_project_ids, get_sites, get_creds, avatar): self.assertIn(b'credid', res.data) self.assertIn(b'site_url', res.data) self.assertIn(b'fedcloudRow.png', res.data) + self.assertEqual(utils.CREDS_CACHE, {"userid": [{"id": "credid", "type": "fedcloud", + "host": "site_url", "project_id": "project"}]}) + self.assertEqual(get_creds.call_count, 2) + + res = self.client.get('/manage_creds') + self.assertEqual(200, res.status_code) + self.assertIn(b'credid', res.data) + self.assertIn(b'site_url', res.data) + self.assertIn(b'fedcloudRow.png', res.data) + self.assertEqual(get_creds.call_count, 2) @patch("app.utils.avatar") @patch("app.db_cred.DBCredentials.get_cred") From 1b2703e4a70527d47fc12e200ff1170709a01561 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:10 +0100 Subject: [PATCH 03/17] Revert "Fix test" This reverts commit 3a3eddde32aa02bf09ba33a027694c826bbd2613. --- app/tests/test_app.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/tests/test_app.py b/app/tests/test_app.py index 69897d40..28b67c4e 100644 --- a/app/tests/test_app.py +++ b/app/tests/test_app.py @@ -431,7 +431,6 @@ def test_configure(self, get, get_creds, avatar): self.assertEqual(200, res.status_code) self.assertIn(b"Select Optional Features:", res.data) - utils.CREDS_CACHE = {} get_creds.return_value = [{"id": "credid", "type": "fedcloud", "host": "site_url", "vo": "voname", "enabled": True}, {"id": "credid1", "type": "OpenStack", "host": "site_url1", @@ -576,16 +575,6 @@ def test_manage_creds(self, get_project_ids, get_sites, get_creds, avatar): self.assertIn(b'credid', res.data) self.assertIn(b'site_url', res.data) self.assertIn(b'fedcloudRow.png', res.data) - self.assertEqual(utils.CREDS_CACHE, {"userid": [{"id": "credid", "type": "fedcloud", - "host": "site_url", "project_id": "project"}]}) - self.assertEqual(get_creds.call_count, 2) - - res = self.client.get('/manage_creds') - self.assertEqual(200, res.status_code) - self.assertIn(b'credid', res.data) - self.assertIn(b'site_url', res.data) - self.assertIn(b'fedcloudRow.png', res.data) - self.assertEqual(get_creds.call_count, 2) @patch("app.utils.avatar") @patch("app.db_cred.DBCredentials.get_cred") From 012c13ce3588c5366735f2644b12a302818a89c2 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:10 +0100 Subject: [PATCH 04/17] =?UTF-8?q?Revert=20"Fix=20sty=C3=B1e"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit df6e4f8780974877c1d34ceb1cb3ecf2b2e52857. --- app/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index 86d9347c..b2b633fd 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -73,7 +73,7 @@ def create_app(oidc_blueprint=None): ssh_key = SSHKey(settings.db_url) vault_info = VaultInfo(settings.db_url) ott = OneTimeTokenData(settings.vault_url) - + # To Reload internally the site cache scheduler = APScheduler() scheduler.api_enabled = False From 78879770b35ed637276be73f3ae4ed081d923620 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:10 +0100 Subject: [PATCH 05/17] Revert "Fix tests" This reverts commit 19f538e589e4e3d6899e742d0d41903f44de121f. --- .github/workflows/main.yaml | 1 + app/__init__.py | 14 ++++++++------ app/tests/test_app.py | 3 +-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index dd5b70e3..65ea7f35 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -37,6 +37,7 @@ jobs: wget -P tosca-templates https://raw.githubusercontent.com/grycap/tosca/main/templates/simple-node-disk.yml sed -i -e 's|/opt|'${GITHUB_WORKSPACE}'|g' app/config.json sed -i -e 's|creds.db|tmp/creds.db|g' app/config.json + sed -i -e 's|"EXTRA_AUTH": {},|"DISABLE_APPSCHEDULER": true,|g' app/config.json - name: Unit tests run: python -m coverage run --source=. -m unittest discover -s app/tests -p 'test*.py' diff --git a/app/__init__.py b/app/__init__.py index b2b633fd..c444f290 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -73,12 +73,13 @@ def create_app(oidc_blueprint=None): ssh_key = SSHKey(settings.db_url) vault_info = VaultInfo(settings.db_url) ott = OneTimeTokenData(settings.vault_url) - - # To Reload internally the site cache + scheduler = APScheduler() - scheduler.api_enabled = False - scheduler.init_app(app) - scheduler.start() + # To Reload internally the site cache + if 'DISABLE_APPSCHEDULER' not in app.config: + scheduler.api_enabled = False + scheduler.init_app(app) + scheduler.start() toscaTemplates = utils.loadToscaTemplates(settings.toscaDir) toscaInfo = utils.extractToscaInfo(settings.toscaDir, toscaTemplates, settings.hide_tosca_tags) @@ -247,7 +248,8 @@ def home(): return render_template('home.html', oidc_name=settings.oidcName) # Force to get the user credentials to cache them - scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=datetime.datetime.now(), + ndate = datetime.datetime.now() + datetime.timedelta(0, 2) + scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=ndate, misfire_grace_time=20, args=[cred, get_cred_id()], id='get_cache_creds') # if there are any next url, redirect to it diff --git a/app/tests/test_app.py b/app/tests/test_app.py index 28b67c4e..cc9fa0a6 100644 --- a/app/tests/test_app.py +++ b/app/tests/test_app.py @@ -6,7 +6,7 @@ import unittest import json import defusedxml.ElementTree as etree -from app import create_app, utils +from app import create_app from urllib.parse import urlparse from mock import patch, MagicMock @@ -569,7 +569,6 @@ def test_manage_creds(self, get_project_ids, get_sites, get_creds, avatar): get_sites.return_value = {"SITE_NAME": {"url": "URL", "state": "", "id": ""}, "SITE2": {"url": "URL2", "state": "CRITICAL", "id": ""}} get_creds.return_value = [{"id": "credid", "type": "fedcloud", "host": "site_url", "project_id": "project"}] - utils.CREDS_CACHE = {} res = self.client.get('/manage_creds') self.assertEqual(200, res.status_code) self.assertIn(b'credid', res.data) From c0b39839eaf1abcbab13ec5fbcc647c26881211d Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:10 +0100 Subject: [PATCH 06/17] Revert "Fix tests" This reverts commit 9e0140bb11bf7e00545207184f07c0d7a46911bf. --- .github/workflows/main.yaml | 1 - app/__init__.py | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 65ea7f35..dd5b70e3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -37,7 +37,6 @@ jobs: wget -P tosca-templates https://raw.githubusercontent.com/grycap/tosca/main/templates/simple-node-disk.yml sed -i -e 's|/opt|'${GITHUB_WORKSPACE}'|g' app/config.json sed -i -e 's|creds.db|tmp/creds.db|g' app/config.json - sed -i -e 's|"EXTRA_AUTH": {},|"DISABLE_APPSCHEDULER": true,|g' app/config.json - name: Unit tests run: python -m coverage run --source=. -m unittest discover -s app/tests -p 'test*.py' diff --git a/app/__init__.py b/app/__init__.py index c444f290..eb0562aa 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -74,12 +74,11 @@ def create_app(oidc_blueprint=None): vault_info = VaultInfo(settings.db_url) ott = OneTimeTokenData(settings.vault_url) - scheduler = APScheduler() # To Reload internally the site cache - if 'DISABLE_APPSCHEDULER' not in app.config: - scheduler.api_enabled = False - scheduler.init_app(app) - scheduler.start() + scheduler = APScheduler() + scheduler.api_enabled = False + scheduler.init_app(app) + scheduler.start() toscaTemplates = utils.loadToscaTemplates(settings.toscaDir) toscaInfo = utils.extractToscaInfo(settings.toscaDir, toscaTemplates, settings.hide_tosca_tags) From a395a72b0890f18de2fff51730e9118f7ab46bfe Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:10 +0100 Subject: [PATCH 07/17] Revert "Fix style" This reverts commit e014d3fb5bf70f1119650a3ea0ea66731de5c5c0. --- app/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index eb0562aa..77cd764d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -247,7 +247,7 @@ def home(): return render_template('home.html', oidc_name=settings.oidcName) # Force to get the user credentials to cache them - ndate = datetime.datetime.now() + datetime.timedelta(0, 2) + ndate = datetime.datetime.now() + datetime.timedelta(0,2) scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=ndate, misfire_grace_time=20, args=[cred, get_cred_id()], id='get_cache_creds') From 7b7767528bae96a6a53791f142a3b96e0b6c0e20 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:11 +0100 Subject: [PATCH 08/17] Revert "Fix test" This reverts commit 875fbf8fd0739c1bfa70e6e73ae2f841897ca945. --- app/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 77cd764d..86d9347c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -247,8 +247,7 @@ def home(): return render_template('home.html', oidc_name=settings.oidcName) # Force to get the user credentials to cache them - ndate = datetime.datetime.now() + datetime.timedelta(0,2) - scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=ndate, + scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=datetime.datetime.now(), misfire_grace_time=20, args=[cred, get_cred_id()], id='get_cache_creds') # if there are any next url, redirect to it From 1cc436485fb33f1d2c86c6e6d604abae3ec811ca Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:11 +0100 Subject: [PATCH 09/17] Revert "Fix style" This reverts commit aff6eabaa212f9a4178426b93e5e10a1acb61e69. --- app/__init__.py | 1 - app/utils.py | 1 - 2 files changed, 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 86d9347c..7c0b0300 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -246,7 +246,6 @@ def home(): flash("Error getting User info: \n" + account_info.text, 'error') return render_template('home.html', oidc_name=settings.oidcName) - # Force to get the user credentials to cache them scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=datetime.datetime.now(), misfire_grace_time=20, args=[cred, get_cred_id()], id='get_cache_creds') diff --git a/app/utils.py b/app/utils.py index bb202afa..c6472dc5 100644 --- a/app/utils.py +++ b/app/utils.py @@ -48,7 +48,6 @@ PORT_SPECT_TYPES = ["PortSpec", "tosca.datatypes.network.PortSpec", "tosca.datatypes.indigo.network.PortSpec"] CREDS_CACHE = {} - def _getStaticSitesInfo(force=False): # Remove cache if force is True if force and g.settings.static_sites_url: From fc3e57b66dda05cd5eaa070564486e5cddf63d19 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:11 +0100 Subject: [PATCH 10/17] Revert "Improve cache code" This reverts commit 566b004db3109ebdc94a661c4967f7ec13f16a76. --- app/__init__.py | 19 +++++++++---------- app/utils.py | 17 +++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 7c0b0300..b7d14061 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -26,7 +26,6 @@ import logging import copy import requests -import datetime from requests.exceptions import Timeout from werkzeug.middleware.proxy_fix import ProxyFix from flask_dance.consumer import OAuth2ConsumerBlueprint @@ -246,9 +245,6 @@ def home(): flash("Error getting User info: \n" + account_info.text, 'error') return render_template('home.html', oidc_name=settings.oidcName) - scheduler.add_job(func=utils.get_cache_creds, trigger='date', run_date=datetime.datetime.now(), - misfire_grace_time=20, args=[cred, get_cred_id()], id='get_cache_creds') - # if there are any next url, redirect to it if "next" in session and session["next"]: next_url = session.pop("next") @@ -495,7 +491,7 @@ def showinfrastructures(): app.logger.exception("Error getting vm info: %s" % ex) radl_json = [] try: - creds = utils.get_cache_creds(cred, get_cred_id()) + creds = utils.get_cache_creds(session, cred, get_cred_id()) except Exception as ex: app.logger.exception("Error getting user credentials: %s" % ex) creds = [] @@ -765,7 +761,7 @@ def configure(): app.logger.debug("Template: " + json.dumps(toscaInfo[selected_tosca])) try: - creds = utils.get_cache_creds(cred, get_cred_id(), 1) + creds = utils.get_cache_creds(session, cred, get_cred_id(), 1) except Exception as ex: flash("Error getting user credentials: %s" % ex, "error") creds = [] @@ -1119,7 +1115,7 @@ def manage_creds(): creds = {} try: - creds = utils.get_cache_creds(cred, get_cred_id()) + creds = utils.get_cache_creds(session, cred, get_cred_id()) # Get the project_id in case it has changed utils.get_project_ids(creds) except Exception as e: @@ -1174,7 +1170,8 @@ def write_creds(): # Get project_id to save it to de DB utils.get_project_ids([creds]) # delete cached credentials - utils.clear_cache_creds(get_cred_id()) + if 'creds' in session: + del session['creds'] cred.write_creds(creds["id"], get_cred_id(), creds, cred_id in [None, '']) if val_res == 0: flash("Credentials successfully written!", 'success') @@ -1192,7 +1189,8 @@ def delete_creds(): cred_id = request.args.get('cred_id', "") try: # delete cached credentials - utils.clear_cache_creds(get_cred_id()) + if 'creds' in session: + del session['creds'] cred.delete_cred(cred_id, get_cred_id()) flash("Credentials successfully deleted!", 'success') except Exception as ex: @@ -1211,7 +1209,8 @@ def enable_creds(): if val_res == 2: flash(val_msg, 'warning') # delete cached credentials - utils.clear_cache_creds(get_cred_id()) + if 'creds' in session: + del session['creds'] cred.enable_cred(cred_id, get_cred_id(), enable) except Exception as ex: flash("Error updating credentials %s!" % ex, 'error') diff --git a/app/utils.py b/app/utils.py index c6472dc5..f6bb7587 100644 --- a/app/utils.py +++ b/app/utils.py @@ -46,7 +46,7 @@ SITE_LIST = {} LAST_UPDATE = 0 PORT_SPECT_TYPES = ["PortSpec", "tosca.datatypes.network.PortSpec", "tosca.datatypes.indigo.network.PortSpec"] -CREDS_CACHE = {} + def _getStaticSitesInfo(force=False): # Remove cache if force is True @@ -984,20 +984,13 @@ def merge_templates(template, new_template): return template -def get_cache_creds(cred, userid, enabled=None): - global CREDS_CACHE - if userid not in CREDS_CACHE: - CREDS_CACHE[userid] = cred.get_creds(userid) +def get_cache_creds(session, cred, userid, enabled=None): + if "creds" not in session: + session["creds"] = cred.get_creds(userid) res = [] - for cred in CREDS_CACHE[userid]: + for cred in session["creds"]: if enabled is None or enabled == cred['enabled']: res.append(cred) return res - - -def clear_cache_creds(userid): - global CREDS_CACHE - if userid in CREDS_CACHE: - del CREDS_CACHE[userid] From 62ade74e1bb2c3a678c21f73feed42d07866a40f Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:11 +0100 Subject: [PATCH 11/17] Revert "Fix error" This reverts commit 9d9bfbc4606f295d45f2ea582f5e281a0143c9a9. --- app/utils.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/utils.py b/app/utils.py index f6bb7587..a2a1416b 100644 --- a/app/utils.py +++ b/app/utils.py @@ -986,11 +986,5 @@ def merge_templates(template, new_template): def get_cache_creds(session, cred, userid, enabled=None): if "creds" not in session: - session["creds"] = cred.get_creds(userid) - - res = [] - for cred in session["creds"]: - if enabled is None or enabled == cred['enabled']: - res.append(cred) - - return res + session["creds"] = cred.get_creds(userid, enabled) + return session["creds"] From b4444dfbca7ce4b140e66b2ae943e9a15cfa0463 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:11 +0100 Subject: [PATCH 12/17] Revert "Fix error" This reverts commit 6a9c29482f78517390d7e39668943ca7e4383365. --- app/__init__.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index b7d14061..7d0da22a 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1170,8 +1170,7 @@ def write_creds(): # Get project_id to save it to de DB utils.get_project_ids([creds]) # delete cached credentials - if 'creds' in session: - del session['creds'] + del session['creds'] cred.write_creds(creds["id"], get_cred_id(), creds, cred_id in [None, '']) if val_res == 0: flash("Credentials successfully written!", 'success') @@ -1189,8 +1188,7 @@ def delete_creds(): cred_id = request.args.get('cred_id', "") try: # delete cached credentials - if 'creds' in session: - del session['creds'] + del session['creds'] cred.delete_cred(cred_id, get_cred_id()) flash("Credentials successfully deleted!", 'success') except Exception as ex: @@ -1209,8 +1207,7 @@ def enable_creds(): if val_res == 2: flash(val_msg, 'warning') # delete cached credentials - if 'creds' in session: - del session['creds'] + del session['creds'] cred.enable_cred(cred_id, get_cred_id(), enable) except Exception as ex: flash("Error updating credentials %s!" % ex, 'error') From a4546e1cd9212146179b31a28359fc417bedacd7 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 10:57:12 +0100 Subject: [PATCH 13/17] Revert "Add creds cache" This reverts commit 62632f31fecc20b2943c697527f315283558da78. --- app/__init__.py | 12 +++--------- app/utils.py | 6 ------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 7d0da22a..e49b8c3e 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -491,7 +491,7 @@ def showinfrastructures(): app.logger.exception("Error getting vm info: %s" % ex) radl_json = [] try: - creds = utils.get_cache_creds(session, cred, get_cred_id()) + creds = cred.get_creds(get_cred_id()) except Exception as ex: app.logger.exception("Error getting user credentials: %s" % ex) creds = [] @@ -761,7 +761,7 @@ def configure(): app.logger.debug("Template: " + json.dumps(toscaInfo[selected_tosca])) try: - creds = utils.get_cache_creds(session, cred, get_cred_id(), 1) + creds = cred.get_creds(get_cred_id(), 1) except Exception as ex: flash("Error getting user credentials: %s" % ex, "error") creds = [] @@ -1115,7 +1115,7 @@ def manage_creds(): creds = {} try: - creds = utils.get_cache_creds(session, cred, get_cred_id()) + creds = cred.get_creds(get_cred_id()) # Get the project_id in case it has changed utils.get_project_ids(creds) except Exception as e: @@ -1169,8 +1169,6 @@ def write_creds(): if val_res != 1: # Get project_id to save it to de DB utils.get_project_ids([creds]) - # delete cached credentials - del session['creds'] cred.write_creds(creds["id"], get_cred_id(), creds, cred_id in [None, '']) if val_res == 0: flash("Credentials successfully written!", 'success') @@ -1187,8 +1185,6 @@ def delete_creds(): cred_id = request.args.get('cred_id', "") try: - # delete cached credentials - del session['creds'] cred.delete_cred(cred_id, get_cred_id()) flash("Credentials successfully deleted!", 'success') except Exception as ex: @@ -1206,8 +1202,6 @@ def enable_creds(): val_res, val_msg = cred.validate_cred(get_cred_id(), cred_id) if val_res == 2: flash(val_msg, 'warning') - # delete cached credentials - del session['creds'] cred.enable_cred(cred_id, get_cred_id(), enable) except Exception as ex: flash("Error updating credentials %s!" % ex, 'error') diff --git a/app/utils.py b/app/utils.py index a2a1416b..a4356683 100644 --- a/app/utils.py +++ b/app/utils.py @@ -982,9 +982,3 @@ def merge_templates(template, new_template): template["metadata"]["tabs"].update(tabs) return template - - -def get_cache_creds(session, cred, userid, enabled=None): - if "creds" not in session: - session["creds"] = cred.get_creds(userid, enabled) - return session["creds"] From 343ab9fb8a6e45df2a20f5475f7fe5d78907fed4 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Tue, 17 Dec 2024 09:10:26 +0100 Subject: [PATCH 14/17] Load creds ajax --- app/__init__.py | 22 ++++++++++++---------- app/templates/advanced_config.html | 19 +++++-------------- app/templates/config_form.html | 10 +++++----- app/templates/createdep.html | 29 +++++++++++++++++++++++++++++ app/templates/default_form.html | 8 ++++---- app/tests/test_app.py | 6 ------ 6 files changed, 55 insertions(+), 39 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e49b8c3e..4b54ed88 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -760,13 +760,6 @@ def configure(): else: app.logger.debug("Template: " + json.dumps(toscaInfo[selected_tosca])) - try: - creds = cred.get_creds(get_cred_id(), 1) - except Exception as ex: - flash("Error getting user credentials: %s" % ex, "error") - creds = [] - utils.get_project_ids(creds) - # Enable to get input values from URL parameters for input_name, input_value in selected_template["inputs"].items(): value = request.args.get(input_name, None) @@ -783,7 +776,7 @@ def configure(): return render_template('createdep.html', template=selected_template, selectedTemplate=selected_tosca, - creds=creds, input_values=inputs, + input_values=inputs, infra_name=infra_name, child_templates=child_templates, vos=utils.getVOs(session), utils=utils) @@ -1121,8 +1114,17 @@ def manage_creds(): except Exception as e: flash("Error retrieving credentials: \n" + str(e), 'warning') - return render_template('service_creds.html', creds=creds, - vault=(settings.vault_url and settings.enable_external_vault)) + if request.args.get('json', 0): + json_creds = json.dumps(creds) + to_delete = ['password', 'token', 'proxy', 'private_key', 'client_id', 'secret'] + for cred in json_creds: + for key in to_delete: + if key in cred: + del cred[key] + return json_creds + else: + return render_template('service_creds.html', creds=creds, + vault=(settings.vault_url and settings.enable_external_vault)) @app.route('/write_creds', methods=['GET', 'POST']) @authorized_with_valid_token diff --git a/app/templates/advanced_config.html b/app/templates/advanced_config.html index 10d5375e..1ef7bfde 100644 --- a/app/templates/advanced_config.html +++ b/app/templates/advanced_config.html @@ -247,23 +247,14 @@
Cloud Provider:
- {% if not creds %} - - {% else %} + +
- {% endif %} +