0.2 - Feature-Flags (#48) #50

Merged
edraft merged 2 commits from #48 into 0.2 2022-10-02 11:18:27 +02:00
9 changed files with 49 additions and 24 deletions
Showing only changes of commit 890cb6f6b5 - Show all commits

View File

@ -17,7 +17,7 @@
"de"
]
},
"FeatureFlag": {
"FeatureFlags": {
"AdminModule": true,
"BaseModule": true,
"BootLogModule": true,

View File

@ -19,7 +19,7 @@
"Token": "OTk4MTYwNDI3Njg5MTgxMjM3.GI7h67.BqD6Lu1Tz0MuG8iktYrcLnHi1pNozyMiWFGTKI",
"Prefix": "!ke "
},
"FeatureFlag": {
"FeatureFlags": {
"AdminModule": true,
"BaseModule": true,
"BootLogModule": true,

View File

@ -28,7 +28,7 @@
"Buffered": "true",
"AuthPlugin": "mysql_native_password"
},
"FeatureFlag": {
"FeatureFlags": {
"AdminModule": true,
"BaseModule": true,
"BootLogModule": true,

View File

@ -17,7 +17,7 @@
"de"
]
},
"FeatureFlag": {
"FeatureFlags": {
"AdminModule": true,
"BaseModule": true,
"BootLogModule": true,

View File

@ -8,6 +8,7 @@ from bot.application import Application
from bot.startup import Startup
from bot.startup_discord_extension import StartupDiscordExtension
from bot.startup_migration_extension import StartupMigrationExtension
from bot.startup_settings_extension import StartupSettingsExtension
from modules.boot_log.boot_log_extension import BootLogExtension
from modules.database.database_extension import DatabaseExtension
@ -18,12 +19,13 @@ class Program:
self.app: Optional[Application] = None
async def start(self):
app_builder = ApplicationBuilder(Application)
app_builder.use_extension(StartupDiscordExtension)
app_builder.use_extension(StartupMigrationExtension)
app_builder.use_extension(BootLogExtension)
app_builder.use_extension(DatabaseExtension)
app_builder.use_startup(Startup)
app_builder = ApplicationBuilder(Application) \
.use_extension(StartupSettingsExtension) \
.use_extension(StartupDiscordExtension) \
.use_extension(StartupMigrationExtension) \
.use_extension(BootLogExtension) \
.use_extension(DatabaseExtension) \
.use_startup(Startup)
self.app: Application = await app_builder.build_async()
await self.app.run_async()

View File

@ -1,5 +1,3 @@
import os
from datetime import datetime
from typing import Optional
from cpl_core.application import StartupABC
@ -37,22 +35,10 @@ class Startup(StartupABC):
def __init__(self):
StartupABC.__init__(self)
self._start_time = datetime.now()
self._config: Optional[ConfigurationABC] = None
self._feature_flags: Optional[FeatureFlagsSettings] = None
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
environment.set_working_directory(os.path.dirname(os.path.realpath(__file__)))
configuration.add_environment_variables('KDB_')
configuration.add_environment_variables('DISCORD_')
configuration.add_json_file(f'config/appsettings.json', optional=False)
configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True)
configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True)
configuration.add_configuration('Startup_StartTime', str(self._start_time))
self._config = configuration
self._feature_flags = configuration.get_configuration(FeatureFlagsSettings)
return configuration

View File

@ -0,0 +1,28 @@
import os
from datetime import datetime
from cpl_core.application import StartupExtensionABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironmentABC
class StartupSettingsExtension(StartupExtensionABC):
def __init__(self):
self._start_time = datetime.now()
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironmentABC):
# this shit has to be done here because we need settings in subsequent startup extensions
environment.set_working_directory(os.path.dirname(os.path.realpath(__file__)))
configuration.add_environment_variables('KDB_')
configuration.add_environment_variables('DISCORD_')
configuration.add_json_file(f'config/appsettings.json', optional=False)
configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True)
configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True)
configuration.add_configuration('Startup_StartTime', str(self._start_time))
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
pass

View File

@ -5,6 +5,8 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.logging import LoggerABC
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
class BootLogExtension(ApplicationExtensionABC):
@ -12,6 +14,9 @@ class BootLogExtension(ApplicationExtensionABC):
pass
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings)
if not feature_flags.boot_log_module:
return
logger: LoggerABC = services.get_service(LoggerABC)
logger.debug(__name__, 'BootLog extension started')
config.add_configuration('Bot_StartTime', str(datetime.now()))

View File

@ -5,6 +5,7 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.logging import LoggerABC
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_data.service.migration_service import MigrationService
@ -14,6 +15,9 @@ class DatabaseExtension(ApplicationExtensionABC):
pass
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings)
if not feature_flags.database_module:
return
logger: LoggerABC = services.get_service(LoggerABC)
logger.debug(__name__, 'Database extension started')
config.add_configuration('Database_StartTime', str(datetime.now()))