config.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- encoding: utf-8 -*-
  2. """
  3. Copyright (c) 2019 - present AppSeed.us
  4. """
  5. import os, random, string
  6. class Config(object):
  7. basedir = os.path.abspath(os.path.dirname(__file__))
  8. # Set up the App SECRET_KEY
  9. SECRET_KEY = os.getenv('SECRET_KEY', None)
  10. if not SECRET_KEY:
  11. SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 ))
  12. SQLALCHEMY_TRACK_MODIFICATIONS = False
  13. DB_ENGINE = os.getenv('DB_ENGINE' , None)
  14. DB_USERNAME = os.getenv('DB_USERNAME' , None)
  15. DB_PASS = os.getenv('DB_PASS' , None)
  16. DB_HOST = os.getenv('DB_HOST' , None)
  17. DB_PORT = os.getenv('DB_PORT' , None)
  18. DB_NAME = os.getenv('DB_NAME' , None)
  19. USE_SQLITE = True
  20. # try to set up a Relational DBMS
  21. if DB_ENGINE and DB_NAME and DB_USERNAME:
  22. try:
  23. # Relational DBMS: PSQL, MySql
  24. SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
  25. DB_ENGINE,
  26. DB_USERNAME,
  27. DB_PASS,
  28. DB_HOST,
  29. DB_PORT,
  30. DB_NAME
  31. )
  32. USE_SQLITE = False
  33. except Exception as e:
  34. print('> Error: DBMS Exception: ' + str(e) )
  35. print('> Fallback to SQLite ')
  36. if USE_SQLITE:
  37. # This will create a file in <app> FOLDER
  38. SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
  39. # Assets Management
  40. ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
  41. SOCIAL_AUTH_GITHUB = False
  42. GITHUB_ID = os.getenv('GITHUB_ID')
  43. GITHUB_SECRET = os.getenv('GITHUB_SECRET')
  44. # Enable/Disable Github Social Login
  45. if GITHUB_ID and GITHUB_SECRET:
  46. SOCIAL_AUTH_GITHUB = True
  47. class ProductionConfig(Config):
  48. DEBUG = False
  49. # Security
  50. SESSION_COOKIE_HTTPONLY = True
  51. REMEMBER_COOKIE_HTTPONLY = True
  52. REMEMBER_COOKIE_DURATION = 3600
  53. class DebugConfig(Config):
  54. DEBUG = True
  55. # Load all possible configurations
  56. config_dict = {
  57. 'Production': ProductionConfig,
  58. 'Debug' : DebugConfig
  59. }