diff --git a/app/default.config.toml b/app/default.config.toml index 05960996..b2836b33 100644 --- a/app/default.config.toml +++ b/app/default.config.toml @@ -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 = "/" @@ -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 @@ -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 @@ -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 = "" diff --git a/setup.py b/setup.py index d6d915bc..442877d8 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/src/flask_imp/helpers.py b/src/flask_imp/helpers.py index 25771fb4..b6afe1d1 100644 --- a/src/flask_imp/helpers.py +++ b/src/flask_imp/helpers.py @@ -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 @@ -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') diff --git a/src/flask_imp/resources.py b/src/flask_imp/resources.py deleted file mode 100644 index 54c4f778..00000000 --- a/src/flask_imp/resources.py +++ /dev/null @@ -1,85 +0,0 @@ -from dataclasses import dataclass - - -@dataclass(frozen=True) -class Resources: - # Format to: secret_key - default_config = """\ -# 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 = "super_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 spcific 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 - -# [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" -#PORT = "" -#USERNAME = "database" -#PASSWORD = "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 = "database_another" -#LOCATION = "db" -#PORT = "" -#USERNAME = "user" -#PASSWORD = "password" -""" diff --git a/src/flask_imp_cli/filelib/app.py b/src/flask_imp_cli/filelib/app.py index 7eac5cf0..923322c9 100644 --- a/src/flask_imp_cli/filelib/app.py +++ b/src/flask_imp_cli/filelib/app.py @@ -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. @@ -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 = "/" @@ -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 @@ -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 = """\ diff --git a/src/flask_imp_cli/init_new_app.py b/src/flask_imp_cli/init_new_app.py index 809b91d2..59a6064e 100644 --- a/src/flask_imp_cli/init_new_app.py +++ b/src/flask_imp_cli/init_new_app.py @@ -1,3 +1,4 @@ +import os from pathlib import Path import click @@ -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",