- def create_admin_user(self):
- """
- Creates a new user admin/admin into database if database is empty. Useful for initialization
- :return: _id identity of the inserted data, or None
- """
- users = self.db.get_one("users", fail_on_empty=False, fail_on_more=False)
- if users:
- return None
- # raise EngineException("Unauthorized. Database users is not empty", HTTPStatus.UNAUTHORIZED)
- user_desc = {"username": "admin", "password": "admin", "projects": ["admin"]}
- fake_session = {"project_id": "admin", "username": "admin", "admin": True, "force": True, "public": None}
- roolback_list = []
- _id = self.map_topic["users"].new(roolback_list, fake_session, user_desc)
- return _id
-
- def create_admin(self):
- """
- Creates new 'admin' user and project into database if database is empty. Useful for initialization.
- :return: _id identity of the inserted data, or None
- """
- project_id = self.create_admin_project()
- user_id = self.create_admin_user()
- if not project_id and not user_id:
- return None
- else:
- return {'project_id': project_id, 'user_id': user_id}
+ if not current_version:
+ # create database version
+ serial = urandom(32)
+ version_data = {
+ "_id": "version", # Always "version"
+ "version_int": 1000, # version number
+ "version": "1.0", # version text
+ "date": "2018-10-25", # version date
+ "description": "added serial", # changes in this version
+ 'status': "ENABLED", # ENABLED, DISABLED (migration in process), ERROR,
+ 'serial': b64encode(serial)
+ }
+ self.db.create("admin", version_data)
+ self.db.set_secret_key(serial)
+ current_version = "1.0"
+
+ if current_version in ("1.0", "1.1") and target_version_int >= self.map_target_version_to_int["1.2"]:
+ if self.config['authentication']['backend'] == "internal":
+ self.db.del_list("roles")