def insert_data(self) -> list: """insert data into database""" if self._database_manager is None: raise NoDatabaseManagerError() from cmdb.framework.cmdb_object_manager import CmdbObjectManager from cmdb.user_management.user_manager import UserManager obm = CmdbObjectManager(database_manager=self._database_manager) usm = UserManager(database_manager=self._database_manager) error = [] for group_element in self.groups: try: usm.insert_group(group_element) except CMDBError as e: error.append(e.message) continue for user_element in self.users: try: usm.insert_user(user_element) except CMDBError as e: error.append(e.message) continue for type_element in self.types: try: obm.insert_type(type_element) except CMDBError as e: error.append(e.message) continue for category_element in self.categories: try: obm.insert_category(category_element) except CMDBError as e: error.append(e.message) continue for object_element in self.objects: try: obm.insert_object(object_element) except CMDBError as e: error.append(e.message) continue return error
def __create_user_management(self): from cmdb.user_management.user_manager import UserManager, User from cmdb.user_management import __FIXED_GROUPS__ from cmdb.utils.security import SecurityManager scm = SecurityManager(self.setup_database_manager) usm = UserManager(self.setup_database_manager) for group in __FIXED_GROUPS__: usm.insert_group(group) # setting the initial user to admin/admin as default admin_name = 'admin' admin_pass = '******' import datetime admin_user = User(public_id=1, user_name=admin_name, password=scm.generate_hmac(admin_pass), group_id=__FIXED_GROUPS__[0].get_public_id(), registration_time=datetime.datetime.utcnow()) usm.insert_user(admin_user) return True