Skip to content

Commit

Permalink
Add integration with yourls to shorten long urls (e.g. swift download…
Browse files Browse the repository at this point in the history
… links)
  • Loading branch information
maricaantonacci committed Nov 21, 2020
1 parent 7c64bbb commit 7395dc0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/deployments/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from flask import Blueprint, session, render_template, flash, redirect, url_for, json, request
from app import app, iam_blueprint, tosca, vaultservice
from app.lib import auth, utils, settings, dbhelpers
from app.lib import auth, utils, settings, dbhelpers, yourls
from app.lib.ldap_user import LdapUserManager
from app.models.Deployment import Deployment
from app.providers import sla
Expand Down Expand Up @@ -110,6 +110,20 @@ def unlockdeployment(depid=None):
return redirect(url_for('deployments_bp.showdeployments'))


def preprocess_outputs(browser, depid, outputs, stoutputs):
for key, value in stoutputs.items():
if value["type"] == "download-url":
if value["action"] == "shorturl":
try:
shorturl = yourls.url_shorten(outputs[key], depid)
if shorturl:
outputs[key] = shorturl
except:
pass
if browser['name'] == "chrome" and browser['version'] >= 86:
message = stoutputs[key]['warning'] if 'warning' in stoutputs[key] else ""
stoutputs[key]['warning'] = "{}<br>{}".format("The download will be blocked by Chrome. Please, use Firefox for a full user experience.", message)

@deployments_bp.route('/<depid>/details')
@auth.authorized_with_valid_token
def depoutput(depid=None):
Expand All @@ -136,6 +150,11 @@ def depoutput(depid=None):

outputs = {**outputs, **additional_outputs}

browser = request.user_agent.browser
version = request.user_agent.version and int(request.user_agent.version.split('.')[0])

preprocess_outputs(dict(name = browser, version = version), depid, outputs, stoutputs)

return render_template('depoutput.html',
deployment=dep,
inputs=inputs,
Expand Down
3 changes: 3 additions & 0 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
MAIL_PASSWORD = None
MAIL_DEBUG = False

### YOURLS SETTINGS
YOURLS_SITE = None
YOURLS_API_SIGNATURE_TOKEN=None

### ADMIN SETTINGS
SUPPORT_EMAIL = "[email protected]"
Expand Down

0 comments on commit 7395dc0

Please sign in to comment.