From 2d8ecd424ae446b76a6c0e79b966f39909c979f3 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 12 Oct 2023 20:11:14 +0200 Subject: [PATCH] Switched mysql package --- src/cpl_core/cpl-core.json | 8 ++-- .../connection/database_connection.py | 38 +++++++++---------- src/cpl_core/database/database_settings.py | 8 ++-- .../database/src/appsettings.edrafts-pc.json | 3 +- tests/custom/database/src/model/db_context.py | 4 +- tests/custom/database/src/startup.py | 2 +- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/cpl_core/cpl-core.json b/src/cpl_core/cpl-core.json index c0971a86..b968200e 100644 --- a/src/cpl_core/cpl-core.json +++ b/src/cpl_core/cpl-core.json @@ -3,8 +3,8 @@ "Name": "cpl-core", "Version": { "Major": "2023", - "Minor": "4", - "Micro": "0.post5" + "Minor": "10", + "Micro": "0" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -18,7 +18,6 @@ "Dependencies": [ "art>=5.9", "colorama>=0.4.6", - "mysql-connector>=2.2.9", "psutil>=5.9.4", "packaging>=23.0", "pynput>=1.7.6", @@ -26,7 +25,8 @@ "tabulate>=0.9.0", "termcolor>=2.2.0", "watchdog>=3.0.0", - "wheel>=0.40.0" + "wheel>=0.40.0", + "mysql-connector-python==8.1.0" ], "DevDependencies": [ "Sphinx==5.0.2", diff --git a/src/cpl_core/database/connection/database_connection.py b/src/cpl_core/database/connection/database_connection.py index 32ba2211..562618fc 100644 --- a/src/cpl_core/database/connection/database_connection.py +++ b/src/cpl_core/database/connection/database_connection.py @@ -25,27 +25,27 @@ class DatabaseConnection(DatabaseConnectionABC): def cursor(self) -> MySQLCursorBuffered: return self._cursor - def connect(self, database_settings: DatabaseSettings): + def connect(self, settings: DatabaseSettings): connection = sql.connect( - host=database_settings.host, - port=database_settings.port, - user=database_settings.user, - passwd=CredentialManager.decrypt(database_settings.password), - charset=database_settings.charset, - use_unicode=database_settings.use_unicode, - buffered=database_settings.buffered, - auth_plugin=database_settings.auth_plugin, + host=settings.host, + port=settings.port, + user=settings.user, + passwd=CredentialManager.decrypt(settings.password), + charset=settings.charset, + use_unicode=settings.use_unicode, + buffered=settings.buffered, + 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( - host=database_settings.host, - port=database_settings.port, - user=database_settings.user, - passwd=CredentialManager.decrypt(database_settings.password), - db=database_settings.database, - charset=database_settings.charset, - use_unicode=database_settings.use_unicode, - buffered=database_settings.buffered, - auth_plugin=database_settings.auth_plugin, + host=settings.host, + port=settings.port, + user=settings.user, + passwd=CredentialManager.decrypt(settings.password), + db=settings.database, + charset=settings.charset, + use_unicode=settings.use_unicode, + buffered=settings.buffered, + auth_plugin=settings.auth_plugin, ) self._cursor = self._database.cursor() diff --git a/src/cpl_core/database/database_settings.py b/src/cpl_core/database/database_settings.py index d6bac435..e1f774ed 100644 --- a/src/cpl_core/database/database_settings.py +++ b/src/cpl_core/database/database_settings.py @@ -13,10 +13,10 @@ class DatabaseSettings(ConfigurationModelABC): user: str = None, password: str = None, database: str = None, - charset: str = None, - use_unicode: bool = None, - buffered: bool = None, - auth_plugin: str = None, + charset: str = "utf8mb4", + use_unicode: bool = False, + buffered: bool = False, + auth_plugin: str = "caching_sha2_password", ): ConfigurationModelABC.__init__(self) diff --git a/tests/custom/database/src/appsettings.edrafts-pc.json b/tests/custom/database/src/appsettings.edrafts-pc.json index 66214fc1..78bff4d4 100644 --- a/tests/custom/database/src/appsettings.edrafts-pc.json +++ b/tests/custom/database/src/appsettings.edrafts-pc.json @@ -20,7 +20,6 @@ "Database": "sh_cpl", "Charset": "utf8mb4", "UseUnicode": "true", - "Buffered": "true", - "AuthPlugin": "mysql_native_password" + "Buffered": "true" } } \ No newline at end of file diff --git a/tests/custom/database/src/model/db_context.py b/tests/custom/database/src/model/db_context.py index 0d6fc017..73a28eb7 100644 --- a/tests/custom/database/src/model/db_context.py +++ b/tests/custom/database/src/model/db_context.py @@ -3,5 +3,5 @@ from cpl_core.database.context import DatabaseContext class DBContext(DatabaseContext): - def __init__(self, db_settings: DatabaseSettings): - DatabaseContext.__init__(self, db_settings) + def __init__(self): + DatabaseContext.__init__(self) diff --git a/tests/custom/database/src/startup.py b/tests/custom/database/src/startup.py index 0fa0daec..fbd1029a 100644 --- a/tests/custom/database/src/startup.py +++ b/tests/custom/database/src/startup.py @@ -21,7 +21,6 @@ class Startup(StartupABC): ) -> ConfigurationABC: configuration.add_environment_variables("PYTHON_") configuration.add_environment_variables("CPL_") - configuration.parse_console_arguments() 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.host_name}.json", optional=True) @@ -34,6 +33,7 @@ class Startup(StartupABC): self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC ) -> ServiceProviderABC: # Create and connect to database + self._configuration.parse_console_arguments(services) db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings) services.add_db_context(DBContext, db_settings)