use env vars for passwords, out path and port

This commit is contained in:
Neil Parikh 2021-05-16 06:13:20 -04:00
parent 103f1c9c19
commit d74f20e4e1
3 changed files with 20 additions and 4 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ password.txt
/.vs
/.vscode
data.json
.env

View File

@ -4,13 +4,25 @@ from werkzeug.security import generate_password_hash, check_password_hash
import json
import sqlite3
import os
from dotenv import load_dotenv
DB_PATH = os.path.join(os.path.dirname(__file__), 'links.db')
load_dotenv()
app = Flask(__name__)
auth = HTTPBasicAuth('CustomBasic')
password = os.environ.get("PASSWORD")
if not password:
raise Exception("PASSWORD must be set")
port = int(os.environ.get("PORT") or 3000)
out_path = os.environ.get("OUT_PATH") or "/srv/www-csc-links/index.html"
users = {
"admin": generate_password_hash("test"),
"admin": generate_password_hash(password),
}
def get_data_from_query(query):
@ -29,7 +41,7 @@ def get_data_from_query(query):
def regen_html():
"""Gets links from DB and outputs them in HTML"""
outfile = open('/users/n3parikh/www/links/index.html', 'w')
outfile = open(out_path, 'w')
links_list = get_data_from_query('SELECT url, name FROM links WHERE active=1 ORDER BY position')
html = render_template('template.html', links_list=links_list)
print(html, file=outfile)
@ -106,4 +118,4 @@ def update_clicks():
return 'ok'
if __name__ == "__main__":
app.run(port=5729, host="0.0.0.0")
app.run(port=port, host="0.0.0.0")

View File

@ -1,14 +1,18 @@
astroid==2.5.1
click==7.1.2
Flask==1.1.2
Flask-HTTPAuth==4.2.0
isort==5.7.0
itsdangerous==1.1.0
Jinja2==2.11.3
lazy-object-proxy==1.5.2
MarkupSafe==1.1.1
mccabe==0.6.1
pkg-resources==0.0.0
pylint==2.7.2
python-dotenv==0.17.1
toml==0.10.2
typed-ast==1.4.3
types-click==0.1.4
types-Flask==0.1.1
types-Jinja2==0.1.0
@ -17,4 +21,3 @@ types-typing-extensions==3.7.2
types-Werkzeug==0.1.1
Werkzeug==1.0.1
wrapt==1.12.1
Flask-HTTPAuth==4.2.0