Skip to content

Commit

Permalink
Updates to the generated config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
CheeseCake87 committed Nov 9, 2023
1 parent d5e55e7 commit 07ae3e9
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 107 deletions.
15 changes: 7 additions & 8 deletions app/default.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEBUG = false
#PROPAGATE_EXCEPTIONS = true
TRAP_HTTP_EXCEPTIONS = false
#TRAP_BAD_REQUEST_ERRORS = true
SECRET_KEY = "super_secret_key"
SECRET_KEY = "a73644a54963a005c5c94099af17493d1d22640b6fc3f6d1"
SESSION_COOKIE_NAME = "session"
#SESSION_COOKIE_DOMAIN = "domain-here.com"
#SESSION_COOKIE_PATH = "/"
Expand All @@ -36,7 +36,7 @@ MAX_COOKIE_SIZE = 4093
[SESSION]
logged_in = false

# These settings are spcific to the Flask-SQLAlchemy extension.
# These settings are specific to the Flask-SQLAlchemy extension.
# Anything here will be accessible using app.config
[SQLALCHEMY]
SQLALCHEMY_ECHO = false
Expand All @@ -47,11 +47,10 @@ SQLALCHEMY_RECORD_QUERIES = false
# that the database will be stored in. true will create the folder on the same level as your
# app, false will create the folder in the app root.
SQLITE_DB_EXTENSION = ".sqlite"
SQLITE_STORE_IN_PARENT = true
SQLITE_STORE_IN_PARENT = false

# [DATABASE.MAIN] is loaded as SQLALCHEMY_DATABASE_URI
# Dialets = mysql / postgresql / sqlite / oracle / mssql

# Uncomment below to generate the SQLALCHEMY_DATABASE_URI.
[DATABASE.MAIN]
ENABLED = true
Expand All @@ -75,8 +74,8 @@ PASSWORD = ""
#[DATABASE.ANOTHER]
#ENABLED = true
#DIALECT = "sqlite"
#DATABASE_NAME = "database_another"
#LOCATION = "db"
#DATABASE_NAME = "another"
#LOCATION = ""
#PORT = ""
#USERNAME = "user"
#PASSWORD = "password"
#USERNAME = ""
#PASSWORD = ""
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

setup(
name='Flask-Imp',
version='2.7.2',
version='2.7.3',
url='https://github.com/CheeseCake87/Flask-Imp',
license='GNU Lesser General Public License v2.1',
author='David Carmichael',
Expand Down
5 changes: 3 additions & 2 deletions src/flask_imp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from flask import Flask
from toml import load as toml_load

from .resources import Resources
from flask_imp_cli.filelib import AppFileLib

from .utilities import cast_to_bool, process_dict


Expand Down Expand Up @@ -93,7 +94,7 @@ def _init_app_config(config_file_path: Path, ignore_missing_env_variables: bool,
if not config_file_path.exists():
logging.critical("Config file was not found, creating default.config.toml to use")

config_file_path.write_text(Resources.default_config.format(secret_key=os.urandom(24).hex()))
config_file_path.write_text(AppFileLib.default_config_toml.format(secret_key=os.urandom(24).hex()))

config_suffix = ('.toml', '.tml')

Expand Down
85 changes: 0 additions & 85 deletions src/flask_imp/resources.py

This file was deleted.

101 changes: 92 additions & 9 deletions src/flask_imp_cli/filelib/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AppFileLib:
# Format to: app_name
default_config_toml = """\
default_init_config_toml = """\
# Flask-Imp Config File
# ------------------------
# Updates the Flask app config with the variables below.
Expand All @@ -13,7 +13,7 @@ class AppFileLib:
#PROPAGATE_EXCEPTIONS = true
TRAP_HTTP_EXCEPTIONS = false
#TRAP_BAD_REQUEST_ERRORS = true
SECRET_KEY = "super_secret_key"
SECRET_KEY = "{secret_key}"
SESSION_COOKIE_NAME = "session"
#SESSION_COOKIE_DOMAIN = "domain-here.com"
#SESSION_COOKIE_PATH = "/"
Expand Down Expand Up @@ -54,16 +54,99 @@ class AppFileLib:
# [DATABASE.MAIN] is loaded as SQLALCHEMY_DATABASE_URI
# Dialets = mysql / postgresql / sqlite / oracle / mssql
# Uncomment below to generate the SQLALCHEMY_DATABASE_URI.
[DATABASE.MAIN]
ENABLED = true
DIALECT = "sqlite"
DATABASE_NAME = "database"
LOCATION = ""
PORT = ""
USERNAME = ""
PASSWORD = ""
# Adding another database is as simple as adding a new section.
# [DATABASE.ANOTHER] will then be accessible using SQLALCHEMY_BINDS
# The bind key will be stored as a lowercase value, so "ANOTHER" will
# be accessible as "another"
# You can then use the bind key in the model as follows:
# class MyModel(db.Model):
# __bind_key__ = "another"
# ...
# Uncomment below to generate and add to SQLALCHEMY_BINDS.
#[DATABASE.ANOTHER]
#ENABLED = true
#DIALECT = "sqlite"
#DATABASE_NAME = "another"
#LOCATION = ""
#PORT = ""
#USERNAME = ""
#PASSWORD = ""
"""

default_config_toml = """\
# Flask-Imp Config File
# ------------------------
# Updates the Flask app config with the variables below.
# If any variable below does not exist in the standard Flask env
# vars it is created and will be accessible using
# app.config. All key names defined below will be
# capitalised when imported.
[FLASK]
DEBUG = false
#PROPAGATE_EXCEPTIONS = true
TRAP_HTTP_EXCEPTIONS = false
#TRAP_BAD_REQUEST_ERRORS = true
SECRET_KEY = "{secret_key}"
SESSION_COOKIE_NAME = "session"
#SESSION_COOKIE_DOMAIN = "domain-here.com"
#SESSION_COOKIE_PATH = "/"
SESSION_COOKIE_HTTPONLY = true
SESSION_COOKIE_SECURE = false
SESSION_COOKIE_SAMESITE = "Lax"
PERMANENT_SESSION_LIFETIME = 3600 # 1 hour
SESSION_REFRESH_EACH_REQUEST = true
USE_X_SENDFILE = false
#SEND_FILE_MAX_AGE_DEFAULT = 43200
ERROR_404_HELP = true
#SERVER_NAME = "localhost:5000"
APPLICATION_ROOT = "/"
PREFERRED_URL_SCHEME = "http"
#MAX_CONTENT_LENGTH = 0
#TEMPLATES_AUTO_RELOAD = true
EXPLAIN_TEMPLATE_LOADING = false
MAX_COOKIE_SIZE = 4093
# This will set the default session variables for the app.
# Anything here will be accessible using session["your_var_name"]
# or session.get("your_var_name")
[SESSION]
logged_in = false
# These settings are specific to the Flask-SQLAlchemy extension.
# Anything here will be accessible using app.config
[SQLALCHEMY]
SQLALCHEMY_ECHO = false
SQLALCHEMY_TRACK_MODIFICATIONS = false
SQLALCHEMY_RECORD_QUERIES = false
# Below are extra settings that Flask-Imp uses but relates to Flask-SQLAlchemy.
# This sets the file extension for SQLite databases, and where to create the folder
# that the database will be stored in. true will create the folder on the same level as your
# app, false will create the folder in the app root.
SQLITE_DB_EXTENSION = ".sqlite"
SQLITE_STORE_IN_PARENT = false
# [DATABASE.MAIN] is loaded as SQLALCHEMY_DATABASE_URI
# Dialets = mysql / postgresql / sqlite / oracle / mssql
# Uncomment below to generate the SQLALCHEMY_DATABASE_URI.
#[DATABASE.MAIN]
#ENABLED = true
#DIALECT = "sqlite"
#DATABASE_NAME = "database"
#LOCATION = "db"
#LOCATION = ""
#PORT = ""
#USERNAME = "database"
#PASSWORD = "password"
#USERNAME = ""
#PASSWORD = ""
# Adding another database is as simple as adding a new section.
# [DATABASE.ANOTHER] will then be accessible using SQLALCHEMY_BINDS
Expand All @@ -78,11 +161,11 @@ class AppFileLib:
#[DATABASE.ANOTHER]
#ENABLED = true
#DIALECT = "sqlite"
#DATABASE_NAME = "database_another"
#LOCATION = "db"
#DATABASE_NAME = "another"
#LOCATION = ""
#PORT = ""
#USERNAME = "user"
#PASSWORD = "password"
#USERNAME = ""
#PASSWORD = ""
"""

init_py = """\
Expand Down
5 changes: 3 additions & 2 deletions src/flask_imp_cli/init_new_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import click
Expand Down Expand Up @@ -88,8 +89,8 @@ def init_new_app(name):
app_files_lu = {
"default.config.toml": (
app_folder / "default.config.toml",
AppFileLib.default_config_toml,
{}
AppFileLib.default_init_config_toml,
{"secret_key": os.urandom(24).hex()}
),
"__init__.py": (
app_folder / "__init__.py",
Expand Down

0 comments on commit 07ae3e9

Please sign in to comment.