Skip to content

Commit

Permalink
Merge pull request #601 from grycap/devel
Browse files Browse the repository at this point in the history
Add creds cache
  • Loading branch information
micafer authored Dec 12, 2024
2 parents 5fcf130 + 6a9c294 commit 6299a65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def showinfrastructures():
app.logger.exception("Error getting vm info: %s" % ex)
radl_json = []
try:
creds = cred.get_creds(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 = []
Expand Down Expand Up @@ -768,7 +768,7 @@ def configure():
app.logger.debug("Template: " + json.dumps(toscaInfo[selected_tosca]))

try:
creds = cred.get_creds(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 = []
Expand Down Expand Up @@ -1122,7 +1122,7 @@ def manage_creds():
creds = {}

try:
creds = cred.get_creds(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:
Expand Down Expand Up @@ -1176,6 +1176,9 @@ def write_creds():
if val_res != 1:
# Get project_id to save it to de DB
utils.get_project_ids([creds])
# delete cached credentials
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')
Expand All @@ -1192,6 +1195,9 @@ def delete_creds():

cred_id = request.args.get('cred_id', "")
try:
# delete cached credentials
if 'creds' in session:
del session['creds']
cred.delete_cred(cred_id, get_cred_id())
flash("Credentials successfully deleted!", 'success')
except Exception as ex:
Expand All @@ -1209,6 +1215,9 @@ 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
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')
Expand Down
6 changes: 6 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,9 @@ 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"]

0 comments on commit 6299a65

Please sign in to comment.