Browse Source

frontend: initial local run support

Nikola Kotur 5 years ago
parent
commit
2197ecf209
4 changed files with 28 additions and 10 deletions
  1. 1 0
      .gitignore
  2. 13 0
      README.md
  3. 13 9
      frontend/__init__.py
  4. 1 1
      frontend/frontend.py

+ 1 - 0
.gitignore

@@ -59,3 +59,4 @@ docs/_build/
 target/
 
 frontend/.env
+.env

+ 13 - 0
README.md

@@ -4,8 +4,21 @@ Simple, Platform.sh powered, application to share secrets that can be viewed onl
 
 ## Setup
 
+### Platform.sh
+
 Create Platform.sh project.
 
 Push code.
 
 On master, create variable `env:VAULT_URI` with the URI to the Vault app within the same project (drop the trailing `/`).
+
+### Run locally
+
+```
+virtualenv .env
+source .env/bin/activate
+pip install -r frontend/requirements.txt
+FLASK_ENV=development FLASK_APP=frontend/__init__.py flask run --with-threads -h 0.0.0.0 -p 8888
+```
+
+You will be able to access the frontend on [localhost:8888](http://localhost:8888/).

+ 13 - 9
frontend/__init__.py

@@ -22,18 +22,22 @@ app.config["SECRET_KEY"] = "secretkey"
 app.register_blueprint(frontend)
 nav.init_app(app)
 
-app.config["RELATIONSHIPS"] = json.loads(
-    base64.b64decode(os.environ["PLATFORM_RELATIONSHIPS"])
-)
-app.redis = redis.StrictRedis(
-    host=app.config["RELATIONSHIPS"]["redis"][0]["host"],
-    port=app.config["RELATIONSHIPS"]["redis"][0]["port"],
-    db=0,
-)
+relationships = os.environ.get("PLATFORM_RELATIONSHIPS", None)
+if relationships:
+    app.config["RELATIONSHIPS"] = json.loads(
+        base64.b64decode(relationships)
+    )
+    app.redis = redis.StrictRedis(
+        host=app.config["RELATIONSHIPS"]["redis"][0]["host"],
+        port=app.config["RELATIONSHIPS"]["redis"][0]["port"],
+        db=0,
+    )
+else:
+    app.redis = None
 
 
 def get_token():
-    return app.redis.get("token")
+    return app.redis.get("token") if app.redis else None
 
 
 app.get_token = get_token

+ 1 - 1
frontend/frontend.py

@@ -3,7 +3,7 @@ import base64
 
 import hvac
 import requests
-from flask import Blueprint, render_template, flash, redirect, url_for, current_app, jsonify
+from flask import Blueprint, render_template, flash, redirect, url_for, current_app, jsonify, request
 from flask_bootstrap import __version__ as FLASK_BOOTSTRAP_VERSION
 from flask_nav.elements import Navbar, View, Subgroup, Link, Text, Separator
 from markupsafe import escape