mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
generate .secret file for jwt hashing
This commit is contained in:
parent
253ff0f0f6
commit
f3b96f9b3f
3 changed files with 24 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,6 +8,7 @@ docs/site/
|
||||||
mealie/temp/*
|
mealie/temp/*
|
||||||
mealie/temp/api.html
|
mealie/temp/api.html
|
||||||
.temp/
|
.temp/
|
||||||
|
.secret
|
||||||
|
|
||||||
|
|
||||||
dev/data/backups/*
|
dev/data/backups/*
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import secrets
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import dotenv
|
import dotenv
|
||||||
|
@ -17,12 +18,10 @@ def ensure_dirs():
|
||||||
# Register ENV
|
# Register ENV
|
||||||
ENV = CWD.joinpath(".env") #! I'm Broken Fix Me!
|
ENV = CWD.joinpath(".env") #! I'm Broken Fix Me!
|
||||||
dotenv.load_dotenv(ENV)
|
dotenv.load_dotenv(ENV)
|
||||||
|
PRODUCTION = os.environ.get("ENV")
|
||||||
|
|
||||||
|
|
||||||
SECRET = "test-secret-shhh"
|
|
||||||
|
|
||||||
# General
|
# General
|
||||||
PRODUCTION = os.environ.get("ENV")
|
|
||||||
PORT = int(os.getenv("mealie_port", 9000))
|
PORT = int(os.getenv("mealie_port", 9000))
|
||||||
API = os.getenv("api_docs", True)
|
API = os.getenv("api_docs", True)
|
||||||
|
|
||||||
|
@ -72,7 +71,7 @@ LOGGER_FILE = DATA_DIR.joinpath("mealie.log")
|
||||||
|
|
||||||
# DATABASE ENV
|
# DATABASE ENV
|
||||||
SQLITE_FILE = None
|
SQLITE_FILE = None
|
||||||
DATABASE_TYPE = os.getenv("db_type", "sqlite")
|
DATABASE_TYPE = os.getenv("DB_TYPE", "sqlite")
|
||||||
if DATABASE_TYPE == "sqlite":
|
if DATABASE_TYPE == "sqlite":
|
||||||
USE_SQL = True
|
USE_SQL = True
|
||||||
SQLITE_FILE = SQLITE_DIR.joinpath(f"mealie_{DB_VERSION}.sqlite")
|
SQLITE_FILE = SQLITE_DIR.joinpath(f"mealie_{DB_VERSION}.sqlite")
|
||||||
|
@ -80,9 +79,25 @@ if DATABASE_TYPE == "sqlite":
|
||||||
else:
|
else:
|
||||||
raise Exception("Unable to determine database type. Acceptible options are 'sqlite' ")
|
raise Exception("Unable to determine database type. Acceptible options are 'sqlite' ")
|
||||||
|
|
||||||
|
|
||||||
|
def determine_secrets() -> str:
|
||||||
|
secrets_file = DATA_DIR.joinpath(".secret")
|
||||||
|
if secrets_file.is_file():
|
||||||
|
with open(secrets_file, "r") as f:
|
||||||
|
return f.read()
|
||||||
|
else:
|
||||||
|
with open(secrets_file, "w") as f:
|
||||||
|
f.write(secrets.token_hex(32))
|
||||||
|
|
||||||
|
|
||||||
|
SECRET = determine_secrets()
|
||||||
|
|
||||||
# Mongo Database
|
# Mongo Database
|
||||||
|
DEFAULT_GROUP = os.getenv("DEFAULT_GROUP", "Home")
|
||||||
|
DEFAULT_PASSWORD = os.getenv("DEFAULT_PASSWORD", "ChangeMe")
|
||||||
|
|
||||||
|
# Database
|
||||||
MEALIE_DB_NAME = os.getenv("mealie_db_name", "mealie")
|
MEALIE_DB_NAME = os.getenv("mealie_db_name", "mealie")
|
||||||
DEFAULT_GROUP = os.getenv("default_group", "Home")
|
|
||||||
DB_USERNAME = os.getenv("db_username", "root")
|
DB_USERNAME = os.getenv("db_username", "root")
|
||||||
DB_PASSWORD = os.getenv("db_password", "example")
|
DB_PASSWORD = os.getenv("db_password", "example")
|
||||||
DB_HOST = os.getenv("db_host", "mongo")
|
DB_HOST = os.getenv("db_host", "mongo")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from fastapi.logger import logger
|
from fastapi.logger import logger
|
||||||
from mealie.core.config import DEFAULT_GROUP
|
from mealie.core.config import DEFAULT_GROUP, DEFAULT_PASSWORD
|
||||||
from mealie.core.security import get_password_hash
|
from mealie.core.security import get_password_hash
|
||||||
from mealie.db.database import db
|
from mealie.db.database import db
|
||||||
from mealie.db.db_setup import create_session, sql_exists
|
from mealie.db.db_setup import create_session, sql_exists
|
||||||
|
@ -40,14 +40,13 @@ def default_group_init(session: Session):
|
||||||
default_group = {"name": DEFAULT_GROUP}
|
default_group = {"name": DEFAULT_GROUP}
|
||||||
logger.info("Generating Default Group")
|
logger.info("Generating Default Group")
|
||||||
db.groups.create(session, default_group)
|
db.groups.create(session, default_group)
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def default_user_init(session: Session):
|
def default_user_init(session: Session):
|
||||||
default_user = {
|
default_user = {
|
||||||
"full_name": "Change Me",
|
"full_name": "Change Me",
|
||||||
"email": "changeme@email.com",
|
"email": "changeme@email.com",
|
||||||
"password": get_password_hash("MyPassword"),
|
"password": get_password_hash(DEFAULT_PASSWORD),
|
||||||
"group": DEFAULT_GROUP,
|
"group": DEFAULT_GROUP,
|
||||||
"admin": True,
|
"admin": True,
|
||||||
}
|
}
|
||||||
|
@ -62,4 +61,4 @@ if __name__ == "__main__":
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
print("Database Doesn't Exists, Initializing...")
|
print("Database Doesn't Exists, Initializing...")
|
||||||
init_db()
|
init_db()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue