From 6f9ef07c2aab70592906ea133c7213970a221307 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sun, 31 May 2020 19:07:58 -0400 Subject: [PATCH 1/2] Add optional ssl and a pip requirements file --- app.py | 27 ++++++++++++++++++++++----- requirements.txt | 18 ++++++++++++++++++ templates/header.html | 5 +++-- 3 files changed, 43 insertions(+), 7 deletions(-) mode change 100644 => 100755 app.py create mode 100644 requirements.txt diff --git a/app.py b/app.py old mode 100644 new mode 100755 index 8d51e37..97564cb --- a/app.py +++ b/app.py @@ -1,8 +1,19 @@ +#!/usr/bin/env python3 + +# @Author: sam +# @Date: 2020-05-31T17:39:09-04:00 +# @Last modified by: sam +# @Last modified time: 2020-05-31T19:06:03-04:00 + + + from flask import Flask, render_template, redirect, request, url_for, jsonify, session from flask_assets import Bundle, Environment import requests from base64 import b64encode +ssl = False + app = Flask(__name__) app.secret_key = "super secret key" @@ -13,9 +24,10 @@ css = Bundle('css/clarity-ui.min.css', 'css/clarity-icons.min.css') env.register('css_all', css) + @app.route('/', methods=["GET", "POST"]) def homepage(): - if request.method == "POST": + if request.method == "POST": attempted_username = request.form['username'] print(attempted_username) attempted_password = request.form['password'] @@ -30,24 +42,29 @@ def homepage(): session['wrong_pass'] = True return render_template('index.html') + @app.route('/vms') def vmlist(): req = requests.get('https://pyva.humblelab.com/rest/vcenter/vms') req_json = req.json() - return render_template('vms.html', vms = req_json) + return render_template('vms.html', vms=req_json) + @app.route('/workflows') def workflows(): url = 'https://hlcloud.humblelab.com' value = b64encode(b"username:password").decode("ascii") headers = { - 'Authorization': 'Basic '+ value, + 'Authorization': 'Basic ' + value, 'content-type': 'application/json', - 'accept' : 'application/json' + 'accept': 'application/json' } req = requests.get('{}/vco/api/workflows/'.format(url), verify=False, headers=headers) return render_template('workflows.html', flows=req.json()['link']) if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + if ssl: + app.run(debug=True, port=5443, ssl_context='adhoc') + else: + app.run(debug=True) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..15fdebd --- /dev/null +++ b/requirements.txt @@ -0,0 +1,18 @@ +certifi==2020.4.5.1 +cffi==1.14.0 +chardet==3.0.4 +click==7.1.2 +cryptography==2.9.2 +Flask==1.1.2 +Flask-Assets==2.0 +idna==2.9 +itsdangerous==1.1.0 +Jinja2==2.11.2 +MarkupSafe==1.1.1 +pycparser==2.20 +pyOpenSSL==19.1.0 +requests==2.23.0 +six==1.15.0 +urllib3==1.25.9 +webassets==2.0 +Werkzeug==1.0.1 diff --git a/templates/header.html b/templates/header.html index 60337cb..4664006 100644 --- a/templates/header.html +++ b/templates/header.html @@ -1,7 +1,8 @@ {% assets "js_all" %} -{% endassets %} {% assets "css_all" %} +{% endassets %} +{% assets "css_all" %} {% endassets %}