コード例 #1
0
ファイル: updater.py プロジェクト: matthiasritter/DATAGERRY
 def increase_updater_version(self, value: int):
     ssr = SystemSettingsReader(self.database_manager)
     system_setting_writer: SystemSettingsWriter = SystemSettingsWriter(
         self.database_manager)
     updater_settings_values = ssr.get_all_values_from_section('updater')
     updater_setting_instance = UpdateSettings(**updater_settings_values)
     updater_setting_instance.version = value
     system_setting_writer.write(_id='updater',
                                 data=updater_setting_instance.__dict__)
コード例 #2
0
    def update_db_version(self):
        # update version updater settings
        try:
            updater_settings_values = UpdaterModule.__DEFAULT_SETTINGS__
            ssr = SystemSettingsReader(self.setup_database_manager)
            try:
                updater_settings_values = ssr.get_all_values_from_section(
                    'updater')
                updater_setting_instance = UpdateSettings(
                    **updater_settings_values)
            except Exception:
                # create updater section if not exist
                system_setting_writer: SystemSettingsWriter = SystemSettingsWriter(
                    self.setup_database_manager)
                updater_setting_instance = UpdateSettings(
                    **updater_settings_values)
                system_setting_writer.write(
                    _id='updater', data=updater_setting_instance.__dict__)

            # start running update files
            updater_setting_instance.run_updates(
                updater_settings_values.get('version'), ssr)

        except Exception as err:
            self.status = UpdateRoutine.UpateStatus.ERROR
            raise RuntimeError(
                f'Something went wrong during the generation of the updater module. \n Error: {err}'
            )
コード例 #3
0
    def setup(self) -> SetupStatus:
        LOGGER.info('SETUP ROUTINE: STARTED...')
        self.status = SetupRoutine.SetupStatus.RUNNING

        # check database
        if not self.__check_database():
            self.status = SetupRoutine.SetupStatus.ERROR
            raise RuntimeError(
                'The database managers could not be initialized. Perhaps the database cannot be reached, \
                or the database was already initialized.')

        if self.__is_database_empty():
            # init database
            try:
                self.__init_database()
            except Exception as err:
                self.status = SetupRoutine.SetupStatus.ERROR
                raise RuntimeError(
                    f'Something went wrong during the initialization of the database. \n Error: {err}'
                )

            # generate keys
            LOGGER.info('SETUP ROUTINE: Generate rsa key pair')

            try:
                self.init_keys()
            except Exception as err:
                self.status = SetupRoutine.SetupStatus.ERROR
                raise RuntimeError(
                    f'Something went wrong during the generation of the rsa keypair. \n Error: {err}'
                )

            # create user management
            LOGGER.info('SETUP ROUTINE: UserModel management')
            try:
                self.__create_user_management()
            except Exception as err:
                self.status = SetupRoutine.SetupStatus.ERROR
                raise RuntimeError(
                    f'Something went wrong during the generation of the user management. \n Error: {err}'
                )

            # create version updater settings
            try:
                from cmdb.updater import UpdaterModule
                from cmdb.updater.updater_settings import UpdateSettings
                from cmdb.utils.system_reader import SystemSettingsReader
                from cmdb.utils.system_writer import SystemSettingsWriter
                system_setting_writer: SystemSettingsWriter = SystemSettingsWriter(
                    self.setup_database_manager)

                updater_setting_instance = UpdateSettings(
                    **UpdaterModule.get_last_version())
                system_setting_writer.write(
                    _id='updater', data=updater_setting_instance.__dict__)
            except Exception as err:
                self.status = SetupRoutine.SetupStatus.ERROR
                raise RuntimeError(
                    f'Something went wrong during the generation of the updater module. \n Error: {err}'
                )

        self.status = SetupRoutine.SetupStatus.FINISHED
        LOGGER.info('SETUP ROUTINE: FINISHED!')
        return self.status
コード例 #4
0
 def __init_settings(self, auth_settings_values: dict) -> UpdateSettings:
     """Merge default values with database entries"""
     return UpdateSettings(**auth_settings_values)