diff --git a/app/__init__.py b/app/__init__.py
index 9bcef72f..f798ceed 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -27,7 +27,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
@@ -253,10 +252,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, session['userid'], 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")
@@ -503,7 +498,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 = cred.get_creds(get_cred_id())
except Exception as ex:
app.logger.exception("Error getting user credentials: %s" % ex)
creds = []
@@ -772,13 +767,6 @@ def configure():
else:
app.logger.debug("Template: " + json.dumps(toscaInfo[selected_tosca]))
- try:
- creds = utils.get_cache_creds(cred, session['userid'], 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)
@@ -795,7 +783,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)
@@ -1127,14 +1115,23 @@ def manage_creds():
creds = {}
try:
- creds = utils.get_cache_creds(cred, session['userid'], 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:
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 elem in json_creds:
+ for key in to_delete:
+ if key in elem:
+ del elem[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
@@ -1181,8 +1178,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
- utils.clear_cache_creds(session['userid'])
cred.write_creds(creds["id"], get_cred_id(), creds, cred_id in [None, ''])
if val_res == 0:
flash("Credentials successfully written!", 'success')
@@ -1199,8 +1194,6 @@ def delete_creds():
cred_id = request.args.get('cred_id', "")
try:
- # delete cached credentials
- utils.clear_cache_creds(session['userid'])
cred.delete_cred(cred_id, get_cred_id())
flash("Credentials successfully deleted!", 'success')
except Exception as ex:
@@ -1218,8 +1211,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
- utils.clear_cache_creds(session['userid'])
cred.enable_cred(cred_id, get_cred_id(), enable)
except Exception as ex:
flash("Error updating credentials %s!" % ex, 'error')
diff --git a/app/templates/advanced_config.html b/app/templates/advanced_config.html
index 45e8f8b1..e95145fb 100644
--- a/app/templates/advanced_config.html
+++ b/app/templates/advanced_config.html
@@ -249,23 +249,14 @@
Cloud Provider:
- {% if not creds %}
-
- {% else %}
+
+
+
+
- {% endif %}
+
diff --git a/app/templates/config_form.html b/app/templates/config_form.html
index bd281c20..682509aa 100644
--- a/app/templates/config_form.html
+++ b/app/templates/config_form.html
@@ -6,15 +6,15 @@
{% for tab in tabs %}
{% set tab_id = tab.replace(" ", "_") %}
{% if loop.first %}
-
{{tab}}
+
{{tab}}
{% else %}
{{tab}}
{% endif %}
{% endfor %}
{% else %}
-
Input Values
+
Input Values
{% endif %}
-
Cloud Provider
+
Cloud Provider
@@ -24,7 +24,7 @@
{% for tab in tabs %}
{% set tab_id = tab.replace(" ", "_") %}
{% if loop.first %}
-
+
{% else %}
{% endif %}
@@ -49,7 +49,7 @@
-
+
{% include 'advanced_config.html' %}
diff --git a/app/templates/createdep.html b/app/templates/createdep.html
index 694ec3a5..a5661bbf 100644
--- a/app/templates/createdep.html
+++ b/app/templates/createdep.html
@@ -134,5 +134,34 @@
}
});
});
+
+// Load cloud sites
+$(document).ready(function () {
+ $('#selectedCred').empty();
+ $('#selectedCred').append("");
+ $.getJSON("{{url_for('manage_creds')}}?json=1", function( data ) {
+ if (data.length == 0) {
+ $('#selectedCred').empty();
+ $('#noCloud').show();
+ $('#cloudSelect').hide();
+ $('#tabAdvanced').tab('show');
+ } else {
+ $('#noCloud').hide();
+ $('#cloudSelect').show();
+ $('#selectedCred').empty();
+ $('#selectedCred').append("");
+ for (var i = 0; i < data.length; i++) {
+ var option = ""
+ console.log(option);
+ $('#selectedCred').append(option);
+ }
+ }
+ });
+});
{% endblock %}
diff --git a/app/templates/default_form.html b/app/templates/default_form.html
index 54a05855..99699ad2 100644
--- a/app/templates/default_form.html
+++ b/app/templates/default_form.html
@@ -1,13 +1,13 @@
{% set inputs=template['inputs'] %}
-
+
{% if inputs|length > 0 %}
{% for key, value in inputs.items() %}
{% set input_value = input_values[key] | default(value.default, true) %}
@@ -44,7 +44,7 @@
No input value to submit.
-
+
{% include 'advanced_config.html' %}
diff --git a/app/tests/test_app.py b/app/tests/test_app.py
index b6002a0e..ed843aff 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
@@ -248,7 +248,6 @@ def test_settings(self, avatar):
def test_infrastructures(self, avatar, get, user_data, get_creds):
user_data.return_value = "type = InfrastructureManager; token = access_token"
get_creds.return_value = []
- utils.CREDS_CACHE = {}
get.side_effect = self.get_response
self.login(avatar)
res = self.client.get('/infrastructures')
@@ -446,7 +445,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",
@@ -454,12 +452,6 @@ def test_configure(self, get, get_creds, avatar):
res = self.client.get('/configure?selected_tosca=simple-node-disk.yml&childs=users.yml')
self.assertEqual(200, res.status_code)
self.assertIn(b"Deploy a compute node getting the IP and SSH credentials to access via ssh", res.data)
- self.assertIn(b'
', res.data)
- self.assertIn(b'
', res.data)
res = self.client.get('/configure?selected_tosca=simple-node-disk.yml&inf_id=infid')
self.assertEqual(200, res.status_code)
@@ -585,13 +577,17 @@ 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)
self.assertIn(b'site_url', res.data)
self.assertIn(b'fedcloudRow.png', res.data)
+ res = self.client.get('/manage_creds?json=1')
+ self.assertEqual(200, res.status_code)
+ self.assertEqual(json.loads(res.data), [{"id": "credid", "type": "fedcloud", "host": "site_url",
+ "project_id": "project"}])
+
@patch("app.utils.avatar")
@patch("app.db_cred.DBCredentials.get_cred")
@patch("app.db_cred.DBCredentials.write_creds")
diff --git a/app/utils.py b/app/utils.py
index 75622f52..a4356683 100644
--- a/app/utils.py
+++ b/app/utils.py
@@ -46,7 +46,6 @@
SITE_LIST = {}
LAST_UPDATE = 0
PORT_SPECT_TYPES = ["PortSpec", "tosca.datatypes.network.PortSpec", "tosca.datatypes.indigo.network.PortSpec"]
-CREDS_CACHE = {}
def _getStaticSitesInfo(force=False):
@@ -983,22 +982,3 @@ def merge_templates(template, new_template):
template["metadata"]["tabs"].update(tabs)
return template
-
-
-def get_cache_creds(cred, userid, creduserid, enabled=None):
- global CREDS_CACHE
- if userid not in CREDS_CACHE:
- CREDS_CACHE[userid] = cred.get_creds(creduserid)
-
- res = []
- for cred in CREDS_CACHE[userid]:
- 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]
diff --git a/docker/Dockerfile b/docker/Dockerfile
index ba32ecf9..26c3dbcd 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,4 +1,4 @@
-FROM python:3.10-alpine3.15
+FROM python:3.12-alpine3.21
COPY . /app
WORKDIR /app/
diff --git a/requirements.txt b/requirements.txt
index 56d3b983..cb5c095c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,18 +1,18 @@
Flask_Dance==7.1.0
-Werkzeug==3.0.6
-Flask==3.0.3
-requests==2.32.2
+Werkzeug==3.1.3
+Flask==3.1.0
+requests==2.32.3
PyYAML==6.0.2
-packaging==24.1
-xmltodict==0.13.0
+packaging==24.2
+xmltodict==0.14.2
radl==1.3.4
-cryptography==43.0.1
-apscheduler==3.10.4 # 3.8.1 version fails
+cryptography==44.0.0
+apscheduler==3.11.0
Flask-APScheduler==1.13.1
-Flask-WTF==1.2.1
+Flask-WTF==1.2.2
hvac==2.3.0
-tosca-parser==2.11.0
-mysqlclient==2.2.4
+tosca-parser==2.12.0
+mysqlclient==2.2.6
lxml==5.3.0
defusedxml==0.7.1
-paramiko==3.4.1
+paramiko==3.5.0