mirror of
https://github.com/enpaul/keyosk.git
synced 2024-11-24 23:47:49 +00:00
Refactor datatypes into submodules
Gonna do some composition up in here Add py38 tox env
This commit is contained in:
parent
227f1e7c18
commit
07828f0063
@ -13,6 +13,7 @@ import toml
|
|||||||
|
|
||||||
from keyosk import constants
|
from keyosk import constants
|
||||||
from keyosk.config.storage import KeyoskStorageConfig
|
from keyosk.config.storage import KeyoskStorageConfig
|
||||||
|
from keyosk.config.storage import StorageBackend # pylint: disable=unused-import
|
||||||
from keyosk.config.storage import StorageConfigSerializer
|
from keyosk.config.storage import StorageConfigSerializer
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""Data containers and utilities related to the storage configuration"""
|
"""Data containers and utilities related to the storage configuration"""
|
||||||
|
import enum
|
||||||
from dataclasses import asdict
|
from dataclasses import asdict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from dataclasses import field
|
from dataclasses import field
|
||||||
@ -11,10 +12,17 @@ from typing import Union
|
|||||||
|
|
||||||
import marshmallow as msh
|
import marshmallow as msh
|
||||||
|
|
||||||
from keyosk import datatypes
|
|
||||||
from keyosk import fields as custom_fields
|
from keyosk import fields as custom_fields
|
||||||
|
|
||||||
|
|
||||||
|
@enum.unique
|
||||||
|
class StorageBackend(enum.Enum):
|
||||||
|
"""Supported storage backends"""
|
||||||
|
|
||||||
|
SQLITE = "sqlite"
|
||||||
|
MARIA = "maria"
|
||||||
|
|
||||||
|
|
||||||
def _default_sqlite_pragmas() -> Dict[str, Any]:
|
def _default_sqlite_pragmas() -> Dict[str, Any]:
|
||||||
"""Generate the default pragmas for the sqlite connection
|
"""Generate the default pragmas for the sqlite connection
|
||||||
|
|
||||||
@ -131,7 +139,7 @@ class KeyoskStorageConfig:
|
|||||||
time, depending on the value of the ``backend`` setting.
|
time, depending on the value of the ``backend`` setting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
backend: datatypes.StorageBackend = datatypes.StorageBackend.SQLITE
|
backend: StorageBackend = StorageBackend.SQLITE
|
||||||
sqlite: KeyoskSQLiteStorageConfig = KeyoskSQLiteStorageConfig()
|
sqlite: KeyoskSQLiteStorageConfig = KeyoskSQLiteStorageConfig()
|
||||||
maria: KeyoskMariaStorageConfig = KeyoskMariaStorageConfig()
|
maria: KeyoskMariaStorageConfig = KeyoskMariaStorageConfig()
|
||||||
|
|
||||||
@ -143,7 +151,7 @@ class StorageConfigSerializer(msh.Schema):
|
|||||||
:class:`KeyoskStorageConfig` class.
|
:class:`KeyoskStorageConfig` class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
backend = custom_fields.EnumItem(datatypes.StorageBackend, pretty_names=True)
|
backend = custom_fields.EnumItem(StorageBackend, pretty_names=True)
|
||||||
sqlite = msh.fields.Nested(SQLiteStorageConfigSerializer)
|
sqlite = msh.fields.Nested(SQLiteStorageConfigSerializer)
|
||||||
maria = msh.fields.Nested(MariaStorageConfigSerializer)
|
maria = msh.fields.Nested(MariaStorageConfigSerializer)
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ from typing import Type
|
|||||||
import peewee
|
import peewee
|
||||||
|
|
||||||
from keyosk import config
|
from keyosk import config
|
||||||
from keyosk import datatypes
|
|
||||||
from keyosk.database._shared import INTERFACE as interface
|
from keyosk.database._shared import INTERFACE as interface
|
||||||
from keyosk.database._shared import KeyoskBaseModel
|
from keyosk.database._shared import KeyoskBaseModel
|
||||||
from keyosk.database.account import Account
|
from keyosk.database.account import Account
|
||||||
@ -57,7 +56,7 @@ def initialize(conf: config.KeyoskConfig):
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
if conf.storage.backend == datatypes.StorageBackend.SQLITE:
|
if conf.storage.backend == config.StorageBackend.SQLITE:
|
||||||
logger.debug("Using SQLite database backend")
|
logger.debug("Using SQLite database backend")
|
||||||
logger.debug(f"Applying SQLite pragmas: {conf.storage.sqlite.pragmas}")
|
logger.debug(f"Applying SQLite pragmas: {conf.storage.sqlite.pragmas}")
|
||||||
# Explicit cast-to-string on the path is to support py3.6: sqlite driver
|
# Explicit cast-to-string on the path is to support py3.6: sqlite driver
|
||||||
@ -66,7 +65,7 @@ def initialize(conf: config.KeyoskConfig):
|
|||||||
str(conf.storage.sqlite.path), pragmas=conf.storage.sqlite.pragmas
|
str(conf.storage.sqlite.path), pragmas=conf.storage.sqlite.pragmas
|
||||||
)
|
)
|
||||||
|
|
||||||
elif conf.storage.backend == datatypes.StorageBackend.MARIA:
|
elif conf.storage.backend == config.StorageBackend.MARIA:
|
||||||
logger.debug("Using MariaDB database backend")
|
logger.debug("Using MariaDB database backend")
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Configuring MariaDB: {conf.storage.maria.username}@{conf.storage.maria.host}:{conf.storage.maria.port}, with database '{conf.storage.maria.schema}'"
|
f"Configuring MariaDB: {conf.storage.maria.username}@{conf.storage.maria.host}:{conf.storage.maria.port}, with database '{conf.storage.maria.schema}'"
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
"""Shared types, enums, and data containers"""
|
|
||||||
import enum
|
|
||||||
from typing import Dict
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
|
|
||||||
Extras = Dict[str, Union[int, float, bool, str, None]]
|
|
||||||
|
|
||||||
|
|
||||||
TokenClaims = Dict[str, Union[str, int, bool, Dict[str, int]]]
|
|
||||||
|
|
||||||
|
|
||||||
@enum.unique
|
|
||||||
class StorageBackend(enum.Enum):
|
|
||||||
"""Supported storage backends"""
|
|
||||||
|
|
||||||
SQLITE = "sqlite"
|
|
||||||
MARIA = "maria"
|
|
8
keyosk/datatypes/__init__.py
Normal file
8
keyosk/datatypes/__init__.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from typing import Dict
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
|
Extras = Dict[str, Union[int, float, bool, str, None]]
|
||||||
|
|
||||||
|
|
||||||
|
TokenClaims = Dict[str, Union[str, int, bool, Dict[str, int]]]
|
@ -5,7 +5,6 @@ import toml
|
|||||||
|
|
||||||
from keyosk import config
|
from keyosk import config
|
||||||
from keyosk import constants
|
from keyosk import constants
|
||||||
from keyosk import datatypes
|
|
||||||
|
|
||||||
|
|
||||||
DEMO_CONFIG = {
|
DEMO_CONFIG = {
|
||||||
@ -39,7 +38,7 @@ def test_roundtrip():
|
|||||||
|
|
||||||
def test_settings():
|
def test_settings():
|
||||||
loaded = config.ConfigSerializer().load(DEMO_CONFIG)
|
loaded = config.ConfigSerializer().load(DEMO_CONFIG)
|
||||||
assert loaded.storage.backend == datatypes.StorageBackend.MARIA
|
assert loaded.storage.backend == config.StorageBackend.MARIA
|
||||||
assert loaded.storage.sqlite.path == Path(DEMO_CONFIG["storage"]["sqlite"]["path"])
|
assert loaded.storage.sqlite.path == Path(DEMO_CONFIG["storage"]["sqlite"]["path"])
|
||||||
assert loaded.storage.sqlite.pragmas == DEMO_CONFIG["storage"]["sqlite"]["pragmas"]
|
assert loaded.storage.sqlite.pragmas == DEMO_CONFIG["storage"]["sqlite"]["pragmas"]
|
||||||
for key, value in DEMO_CONFIG["storage"]["maria"].items():
|
for key, value in DEMO_CONFIG["storage"]["maria"].items():
|
||||||
|
Loading…
Reference in New Issue
Block a user