Add configuration via .env file

pull/10/head
Özcan Oğuz 4 years ago
parent 686708a1d6
commit 1e90dec29e
Signed by: ooguz
GPG Key ID: 2D33E2BD3D975818
  1. 8
      .env.example
  2. 18
      main.py
  3. 3
      requirements.txt

@ -0,0 +1,8 @@
APP_SECRET=s3cr3tk3yh3r3
FLASK_DEBUG=1
MONGO_HOST=mongo
MONGO_USER=username
MONGO_PASSWORD=Pa$$w0rD
ADUNATIO_PRIV_KEY=privkey.pem

@ -4,6 +4,9 @@ from flask_jwt_extended import JWTManager, create_access_token
from mongoengine import connect
from werkzeug.security import check_password_hash
from os import environ, path
from dotenv import load_dotenv
from internal_lib.AuthMethots import AuthJWT
from models.Group import Group
from models.Union import Union
@ -11,13 +14,24 @@ from models.User import User
from restapi import MongoApi
from flask_admin import Admin
"""
Load .env file and get variables
"""
base_path = path.abspath(path.dirname(__file__))
load_dotenv(path.join(base_path, '.env'))
MONGO_HOST = environ.get('MONGO_HOST')
MONGO_USER = environ.get('MONGO_USER')
MONGO_PASSWORD = environ.get('MONGO_PASSWORD')
"""
Mongodb connection string
"""
connect('adunatio', host='mongo', username="xcoder", password="4dun4710", authentication_source='admin')
connect('adunatio', host=MONGO_HOST, username=MONGO_USER, password=MONGO_PASSWORD, authentication_source='admin')
app = Flask(__name__)
app.secret_key = "secret_key+secret_key"
app.secret_key = environ.get('APP_SECRET')
app.config["JWT_TOKEN_LOCATION"] = "headers"
app.config["JWT_HEADER_NAME"] = "Adunation_Session_Token"
app.config["JWT_HEADER_TYPE"] = "Bearer"

@ -6,4 +6,5 @@ flask_jwt_extended
flask_views
flask_login
pillow
flask-admin
flask-admin
python-dotenv

Loading…
Cancel
Save