def set_password(self, database_client: DatabaseClient, user: str, password: str) -> dict: now = self.date_time_provider.now() authentication = database_client.find_one(self.table, { "user": user, "type": "password" }) if authentication is None: authentication = { "identifier": str(uuid.uuid4()), "user": user, "type": "password", "creation_date": self.date_time_provider.serialize(now), "update_date": self.date_time_provider.serialize(now), } database_client.insert_one(self.table, authentication) authentication.update({ "hash_function": self.password_hash_function, "hash_function_parameters": self.password_hash_function_parameters, "hash_function_salt": secrets.token_hex(self.password_salt_size), "update_date": self.date_time_provider.serialize(now), }) authentication["secret"] = self.hash_password(password, authentication["hash_function_salt"], authentication["hash_function"], authentication["hash_function_parameters"]) database_client.update_one(self.table, { "identifier": authentication["identifier"] }, authentication) return self.convert_to_public(authentication)
def update_status( self, database_client: DatabaseClient, # pylint: disable = too-many-arguments worker: dict, is_active: Optional[bool] = None, is_enabled: Optional[bool] = None, should_disconnect: Optional[bool] = None) -> None: now = self.date_time_provider.now() update_data = { "is_active": is_active, "is_enabled": is_enabled, "should_disconnect": should_disconnect, "update_date": self.date_time_provider.serialize(now), } update_data = { key: value for key, value in update_data.items() if value is not None } worker.update(update_data) database_client.update_one(self.table, {"identifier": worker["identifier"]}, update_data)
def create_or_update(self, database_client: DatabaseClient, # pylint: disable = too-many-arguments schedule_identifier: str, project: str, display_name: str, job: str, parameters: dict, expression: str) -> dict: now = self.date_time_provider.now() schedule = self.get(database_client, project, schedule_identifier) if schedule is None: schedule = { "project": project, "identifier": schedule_identifier, "display_name": display_name, "job": job, "parameters": parameters, "expression": expression, "is_enabled": False, "last_run": None, "creation_date": self.date_time_provider.serialize(now), "update_date": self.date_time_provider.serialize(now), } database_client.insert_one(self.table, schedule) else: update_data = { "display_name": display_name, "job": job, "parameters": parameters, "expression": expression, "update_date": self.date_time_provider.serialize(now), } schedule.update(update_data) database_client.update_one(self.table, { "project": project, "identifier": schedule_identifier }, update_data) return schedule
def update_properties( self, database_client: DatabaseClient, # pylint: disable = too-many-arguments worker: dict, version: Optional[str] = None, display_name: Optional[str] = None, properties: Optional[dict] = None) -> None: now = self.date_time_provider.now() update_data = { "version": version, "display_name": display_name, "properties": properties, "update_date": self.date_time_provider.serialize(now), } update_data = { key: value for key, value in update_data.items() if value is not None } worker.update(update_data) database_client.update_one(self.table, {"identifier": worker["identifier"]}, update_data)
def update_roles(self, database_client: DatabaseClient, user: dict, roles: List[str]) -> None: now = self.date_time_provider.now() update_data = { "roles": roles, "update_date": self.date_time_provider.serialize(now), } user.update(update_data) database_client.update_one(self.table, { "identifier": user["identifier"] }, update_data)
def set_results(self, database_client: DatabaseClient, run: dict, results: dict) -> None: now = self.date_time_provider.now() update_data = { "results": results, "update_date": self.date_time_provider.serialize(now), } run.update(update_data) database_client.update_one(self.table, { "project": run["project"], "identifier": run["identifier"] }, update_data)
def update_status(self, database_client: DatabaseClient, user: dict, is_enabled: Optional[bool] = None) -> None: now = self.date_time_provider.now() update_data = { "is_enabled": is_enabled, "update_date": self.date_time_provider.serialize(now), } update_data = { key: value for key, value in update_data.items() if value is not None } user.update(update_data) database_client.update_one(self.table, { "identifier": user["identifier"] }, update_data)
def update_identity(self, database_client: DatabaseClient, user: dict, display_name: Optional[str] = None) -> None: now = self.date_time_provider.now() update_data = { "display_name": display_name, "update_date": self.date_time_provider.serialize(now), } update_data = { key: value for key, value in update_data.items() if value is not None } user.update(update_data) database_client.update_one(self.table, { "identifier": user["identifier"] }, update_data)
def set_token_expiration(self, database_client: DatabaseClient, user_identifier: str, token_identifier: str, expiration: datetime.timedelta) -> None: token = database_client.find_one(self.table, { "identifier": token_identifier, "user": user_identifier, "type": "token" }) if token["expiration_date"] is None: raise ValueError("Token '%s' does not expire" % token_identifier) now = self.date_time_provider.now() update_data = { "expiration_date": self.date_time_provider.serialize(now + expiration), "update_date": self.date_time_provider.serialize(now), } database_client.update_one(self.table, { "identifier": token_identifier, "user": user_identifier, "type": "token" }, update_data)
def update_status(self, database_client: DatabaseClient, schedule: dict, is_enabled: Optional[bool] = None, last_run: Optional[str] = None) -> None: now = self.date_time_provider.now() update_data = { "is_enabled": is_enabled, "last_run": last_run, "update_date": self.date_time_provider.serialize(now), } update_data = { key: value for key, value in update_data.items() if value is not None } schedule.update(update_data) database_client.update_one(self.table, { "project": schedule["project"], "identifier": schedule["identifier"] }, update_data)
def create_or_update( self, database_client: DatabaseClient, # pylint: disable = too-many-arguments job_identifier: str, project: str, display_name: str, description: str, definition: dict, parameters: list, properties: dict) -> dict: now = self.date_time_provider.now() job = self.get(database_client, project, job_identifier) if job is None: job = { "project": project, "identifier": job_identifier, "display_name": display_name, "description": description, "definition": definition, "parameters": parameters, "properties": properties, "is_enabled": True, "creation_date": self.date_time_provider.serialize(now), "update_date": self.date_time_provider.serialize(now), } database_client.insert_one(self.table, job) else: update_data = { "display_name": display_name, "description": description, "definition": definition, "parameters": parameters, "properties": properties, "update_date": self.date_time_provider.serialize(now), } job.update(update_data) database_client.update_one(self.table, { "project": project, "identifier": job_identifier }, update_data) return job
def update_status(self, database_client: DatabaseClient, # pylint: disable = too-many-arguments run: dict, worker: Optional[str] = None, status: Optional[str] = None, start_date: Optional[str] = None, completion_date: Optional[str] = None, should_cancel: Optional[bool] = None, should_abort: Optional[bool] = None) -> None: now = self.date_time_provider.now() update_data = { "worker": worker, "status": status, "start_date": start_date, "completion_date": completion_date, "should_cancel": should_cancel, "should_abort": should_abort, "update_date": self.date_time_provider.serialize(now), } update_data = { key: value for key, value in update_data.items() if value is not None } run.update(update_data) database_client.update_one(self.table, { "project": run["project"], "identifier": run["identifier"] }, update_data)