finish for init core

This commit is contained in:
2024-05-09 16:01:32 +00:00
parent ab1e864478
commit bc8815f40e
42 changed files with 520 additions and 214 deletions

View File

@ -17,7 +17,7 @@ class SQLiteProvider(AbstractDBProvider, BaseModel):
@property
def db_path(self):
return self.data_dir / f"{self.prefix}mealie.db"
return self.data_dir / f"{self.prefix}fuware.db"
@property
def db_url(self) -> str:

View File

@ -1,26 +1,23 @@
import secrets
from pathlib import Path
from fuware.core.settings.db_providers import AbstractDBProvider, SQLiteProvider
from pydantic_settings import BaseSettings # type: ignore
def determine_secrets(data_dir: Path, production: bool) -> str:
def determine_secrets(production: bool) -> str:
if not production:
return "shh-secret-test-key"
secrets_file = data_dir.joinpath(".secret")
if secrets_file.is_file():
with open(secrets_file) as f:
return f.read()
else:
data_dir.mkdir(parents=True, exist_ok=True)
with open(secrets_file, "w") as f:
new_secret = secrets.token_hex(32)
f.write(new_secret)
return new_secret
return "oWNhXlfo666JlMHk6UHYxeNB6z_CA2MisDDZJe4N0yc="
def determine_cookie(production: bool) -> str:
if not production:
return "logcook"
return "7fo24CMyIc"
class AppSettings(BaseSettings):
PRODUCTION: bool
TESTING: bool
BASE_URL: str = "http://localhost:8080"
"""trailing slashes are trimmed (ex. `http://localhost:8080/` becomes ``http://localhost:8080`)"""
@ -32,6 +29,9 @@ class AppSettings(BaseSettings):
ALLOW_SIGNUP: bool = False
SECRET: str
COOKIE_KEY: str
@property
def DOCS_URL(self) -> str | None:
return "/docs" if self.API_DOCS else None
@ -43,7 +43,6 @@ class AppSettings(BaseSettings):
# ===============================================
# Database Configuration
DB_ENGINE: str = "sqlite" # Options: 'sqlite', 'postgres'
DB_PROVIDER: AbstractDBProvider | None = None
@property
@ -63,7 +62,7 @@ def app_settings_constructor(data_dir: Path, production: bool, env_file: Path, e
app_settings = AppSettings(
_env_file=env_file, # type: ignore
_env_file_encoding=env_encoding, # type: ignore
**{"SECRET": determine_secrets(data_dir, production)},
**{"SECRET": determine_secrets(production), 'COOKIE_KEY': determine_cookie(production)},
)
app_settings.DB_PROVIDER = SQLiteProvider(data_dir=data_dir)

View File

@ -1,22 +0,0 @@
import os
from dotenv import load_dotenv
from pathlib import Path
from fuware import __version__
load_dotenv()
APP_VERSION = __version__
CWD = Path(__file__).parent
BASE_DIR = CWD.parent.parent.parent
SERCET_KEY = b"oWNhXlfo666JlMHk6UHYxeNB6z_CA2MisDDZJe4N0yc="
COOKIE_KEY = os.getenv('VITE_LOGIN_KEY') or '7fo24CMyIc'
# URL_DATABASE = "postgresql://{0}:{1}@{2}:{3}/{4}".format(
# os.getenv('LOL_DB_USER'),
# os.getenv('LOL_DB_PASSWORD'),
# os.getenv('LOL_DB_HOST'),
# os.getenv('LOL_DB_PORT'),
# os.getenv('LOL_DB_NAME'),
# )
URL_DATABASE = "sqlite:///./test.db"