2022-03-16 00:23:57 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from enum import Enum
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from jose.constants import ALGORITHMS
|
2022-03-15 16:19:37 +00:00
|
|
|
from passlib.context import CryptContext
|
2022-03-16 00:23:57 +00:00
|
|
|
from peewee import Database, SqliteDatabase
|
|
|
|
from pydantic import BaseModel, Field
|
2022-03-15 16:19:37 +00:00
|
|
|
|
2022-03-15 17:38:24 +00:00
|
|
|
DB = SqliteDatabase("tmp/vpn.db")
|
2022-03-15 16:19:37 +00:00
|
|
|
PRODUCTION_MODE = False
|
|
|
|
|
|
|
|
# to get a string like this run:
|
|
|
|
# openssl rand -hex 32
|
|
|
|
SECRET_KEY = "2f7875b0d2be8a76eba8077ab4d9f8b1c749e02647e9ac9e0f909c3acbfc9856"
|
|
|
|
ALGORITHM = "HS256"
|
|
|
|
ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
|
|
|
|
|
|
|
CRYPT_CONTEXT = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
2022-03-16 00:23:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DBType(Enum):
|
|
|
|
sqlite = "sqlite"
|
|
|
|
mysql = "mysql"
|
|
|
|
|
|
|
|
|
|
|
|
class DBConfig(BaseModel):
|
2022-03-16 00:51:40 +00:00
|
|
|
db_type: DBType = DBType.sqlite
|
2022-03-16 00:23:57 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def database(self) -> Database:
|
|
|
|
return SqliteDatabase("tmp/vpn.db")
|
|
|
|
|
|
|
|
|
|
|
|
class JWTConfig(BaseModel):
|
|
|
|
secret: Optional[str] = None
|
|
|
|
hash_algorithm: str = ALGORITHMS.HS256
|
|
|
|
expiry_minutes: int = 30
|
|
|
|
|
|
|
|
|
|
|
|
class CryptoConfig(BaseModel):
|
|
|
|
schemes: list[str] = ["bcrypt"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cryptContext(self) -> CryptContext:
|
|
|
|
return CryptContext(schemes=self.schemes, deprecated="auto")
|
|
|
|
|
|
|
|
|
|
|
|
class BaseConfig(BaseModel):
|
|
|
|
db: DBConfig = Field(default_factory=DBConfig)
|
|
|
|
jwt: JWTConfig = Field(default_factory=JWTConfig)
|
|
|
|
crypto: CryptoConfig = Field(default_factory=CryptoConfig)
|