2023.10 #175
@ -3,8 +3,8 @@
|
|||||||
"Name": "cpl-core",
|
"Name": "cpl-core",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2023",
|
"Major": "2023",
|
||||||
"Minor": "4",
|
"Minor": "10",
|
||||||
"Micro": "0.post5"
|
"Micro": "0"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
@ -18,7 +18,6 @@
|
|||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"art>=5.9",
|
"art>=5.9",
|
||||||
"colorama>=0.4.6",
|
"colorama>=0.4.6",
|
||||||
"mysql-connector>=2.2.9",
|
|
||||||
"psutil>=5.9.4",
|
"psutil>=5.9.4",
|
||||||
"packaging>=23.0",
|
"packaging>=23.0",
|
||||||
"pynput>=1.7.6",
|
"pynput>=1.7.6",
|
||||||
@ -26,7 +25,8 @@
|
|||||||
"tabulate>=0.9.0",
|
"tabulate>=0.9.0",
|
||||||
"termcolor>=2.2.0",
|
"termcolor>=2.2.0",
|
||||||
"watchdog>=3.0.0",
|
"watchdog>=3.0.0",
|
||||||
"wheel>=0.40.0"
|
"wheel>=0.40.0",
|
||||||
|
"mysql-connector-python==8.1.0"
|
||||||
],
|
],
|
||||||
"DevDependencies": [
|
"DevDependencies": [
|
||||||
"Sphinx==5.0.2",
|
"Sphinx==5.0.2",
|
||||||
|
@ -25,27 +25,27 @@ class DatabaseConnection(DatabaseConnectionABC):
|
|||||||
def cursor(self) -> MySQLCursorBuffered:
|
def cursor(self) -> MySQLCursorBuffered:
|
||||||
return self._cursor
|
return self._cursor
|
||||||
|
|
||||||
def connect(self, database_settings: DatabaseSettings):
|
def connect(self, settings: DatabaseSettings):
|
||||||
connection = sql.connect(
|
connection = sql.connect(
|
||||||
host=database_settings.host,
|
host=settings.host,
|
||||||
port=database_settings.port,
|
port=settings.port,
|
||||||
user=database_settings.user,
|
user=settings.user,
|
||||||
passwd=CredentialManager.decrypt(database_settings.password),
|
passwd=CredentialManager.decrypt(settings.password),
|
||||||
charset=database_settings.charset,
|
charset=settings.charset,
|
||||||
use_unicode=database_settings.use_unicode,
|
use_unicode=settings.use_unicode,
|
||||||
buffered=database_settings.buffered,
|
buffered=settings.buffered,
|
||||||
auth_plugin=database_settings.auth_plugin,
|
auth_plugin=settings.auth_plugin,
|
||||||
)
|
)
|
||||||
connection.cursor().execute(f"CREATE DATABASE IF NOT EXISTS `{database_settings.database}`;")
|
connection.cursor().execute(f"CREATE DATABASE IF NOT EXISTS `{settings.database}`;")
|
||||||
self._database = sql.connect(
|
self._database = sql.connect(
|
||||||
host=database_settings.host,
|
host=settings.host,
|
||||||
port=database_settings.port,
|
port=settings.port,
|
||||||
user=database_settings.user,
|
user=settings.user,
|
||||||
passwd=CredentialManager.decrypt(database_settings.password),
|
passwd=CredentialManager.decrypt(settings.password),
|
||||||
db=database_settings.database,
|
db=settings.database,
|
||||||
charset=database_settings.charset,
|
charset=settings.charset,
|
||||||
use_unicode=database_settings.use_unicode,
|
use_unicode=settings.use_unicode,
|
||||||
buffered=database_settings.buffered,
|
buffered=settings.buffered,
|
||||||
auth_plugin=database_settings.auth_plugin,
|
auth_plugin=settings.auth_plugin,
|
||||||
)
|
)
|
||||||
self._cursor = self._database.cursor()
|
self._cursor = self._database.cursor()
|
||||||
|
@ -13,10 +13,10 @@ class DatabaseSettings(ConfigurationModelABC):
|
|||||||
user: str = None,
|
user: str = None,
|
||||||
password: str = None,
|
password: str = None,
|
||||||
database: str = None,
|
database: str = None,
|
||||||
charset: str = None,
|
charset: str = "utf8mb4",
|
||||||
use_unicode: bool = None,
|
use_unicode: bool = False,
|
||||||
buffered: bool = None,
|
buffered: bool = False,
|
||||||
auth_plugin: str = None,
|
auth_plugin: str = "caching_sha2_password",
|
||||||
):
|
):
|
||||||
ConfigurationModelABC.__init__(self)
|
ConfigurationModelABC.__init__(self)
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
"Database": "sh_cpl",
|
"Database": "sh_cpl",
|
||||||
"Charset": "utf8mb4",
|
"Charset": "utf8mb4",
|
||||||
"UseUnicode": "true",
|
"UseUnicode": "true",
|
||||||
"Buffered": "true",
|
"Buffered": "true"
|
||||||
"AuthPlugin": "mysql_native_password"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,5 +3,5 @@ from cpl_core.database.context import DatabaseContext
|
|||||||
|
|
||||||
|
|
||||||
class DBContext(DatabaseContext):
|
class DBContext(DatabaseContext):
|
||||||
def __init__(self, db_settings: DatabaseSettings):
|
def __init__(self):
|
||||||
DatabaseContext.__init__(self, db_settings)
|
DatabaseContext.__init__(self)
|
||||||
|
@ -21,7 +21,6 @@ class Startup(StartupABC):
|
|||||||
) -> ConfigurationABC:
|
) -> ConfigurationABC:
|
||||||
configuration.add_environment_variables("PYTHON_")
|
configuration.add_environment_variables("PYTHON_")
|
||||||
configuration.add_environment_variables("CPL_")
|
configuration.add_environment_variables("CPL_")
|
||||||
configuration.parse_console_arguments()
|
|
||||||
configuration.add_json_file(f"appsettings.json")
|
configuration.add_json_file(f"appsettings.json")
|
||||||
configuration.add_json_file(f"appsettings.{configuration.environment.environment_name}.json")
|
configuration.add_json_file(f"appsettings.{configuration.environment.environment_name}.json")
|
||||||
configuration.add_json_file(f"appsettings.{configuration.environment.host_name}.json", optional=True)
|
configuration.add_json_file(f"appsettings.{configuration.environment.host_name}.json", optional=True)
|
||||||
@ -34,6 +33,7 @@ class Startup(StartupABC):
|
|||||||
self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC
|
self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC
|
||||||
) -> ServiceProviderABC:
|
) -> ServiceProviderABC:
|
||||||
# Create and connect to database
|
# Create and connect to database
|
||||||
|
self._configuration.parse_console_arguments(services)
|
||||||
db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings)
|
db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings)
|
||||||
services.add_db_context(DBContext, db_settings)
|
services.add_db_context(DBContext, db_settings)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user