1
0
mirror of https://github.com/enpaul/keyosk.git synced 2024-11-24 23:47:49 +00:00

Revert "Refactor datatypes into submodules"

This reverts commit 07828f0063.
This commit is contained in:
Ethan Paul 2020-02-26 22:01:25 -05:00
parent 07828f0063
commit d6265c4797
7 changed files with 27 additions and 24 deletions

View File

@ -13,7 +13,6 @@ 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

View File

@ -1,5 +1,4 @@
"""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
@ -12,17 +11,10 @@ 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
@ -139,7 +131,7 @@ class KeyoskStorageConfig:
time, depending on the value of the ``backend`` setting. time, depending on the value of the ``backend`` setting.
""" """
backend: StorageBackend = StorageBackend.SQLITE backend: datatypes.StorageBackend = datatypes.StorageBackend.SQLITE
sqlite: KeyoskSQLiteStorageConfig = KeyoskSQLiteStorageConfig() sqlite: KeyoskSQLiteStorageConfig = KeyoskSQLiteStorageConfig()
maria: KeyoskMariaStorageConfig = KeyoskMariaStorageConfig() maria: KeyoskMariaStorageConfig = KeyoskMariaStorageConfig()
@ -151,7 +143,7 @@ class StorageConfigSerializer(msh.Schema):
:class:`KeyoskStorageConfig` class. :class:`KeyoskStorageConfig` class.
""" """
backend = custom_fields.EnumItem(StorageBackend, pretty_names=True) backend = custom_fields.EnumItem(datatypes.StorageBackend, pretty_names=True)
sqlite = msh.fields.Nested(SQLiteStorageConfigSerializer) sqlite = msh.fields.Nested(SQLiteStorageConfigSerializer)
maria = msh.fields.Nested(MariaStorageConfigSerializer) maria = msh.fields.Nested(MariaStorageConfigSerializer)

View File

@ -24,6 +24,7 @@ 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
@ -56,7 +57,7 @@ def initialize(conf: config.KeyoskConfig):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
if conf.storage.backend == config.StorageBackend.SQLITE: if conf.storage.backend == datatypes.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
@ -65,7 +66,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 == config.StorageBackend.MARIA: elif conf.storage.backend == datatypes.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}'"

18
keyosk/datatypes.py Normal file
View File

@ -0,0 +1,18 @@
"""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"

View File

@ -1,8 +0,0 @@
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]]]

View File

@ -5,6 +5,7 @@ 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 = {
@ -38,7 +39,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 == config.StorageBackend.MARIA assert loaded.storage.backend == datatypes.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():

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py36, py37, py38, lint, typing, security, docs envlist = py37, py36, lint, typing, security, docs
isolated_build = true isolated_build = true
[testenv] [testenv]