def validate(self) -> None: exceptions: List[ValidationError] = [] # Validate/populate model exists self._model = DatabaseDAO.find_by_id(self._model_id) if not self._model: raise DatabaseNotFoundError() database_name: Optional[str] = self._properties.get("database_name") if database_name: # Check database_name uniqueness if not DatabaseDAO.validate_update_uniqueness( self._model_id, database_name): exceptions.append(DatabaseExistsValidationError()) if exceptions: exception = DatabaseInvalidError() exception.add_list(exceptions) raise exception
def validate(self) -> None: exceptions: List[ValidationError] = list() sqlalchemy_uri: Optional[str] = self._properties.get("sqlalchemy_uri") database_name: Optional[str] = self._properties.get("database_name") if not sqlalchemy_uri: exceptions.append(DatabaseRequiredFieldValidationError("sqlalchemy_uri")) if not database_name: exceptions.append(DatabaseRequiredFieldValidationError("database_name")) else: # Check database_name uniqueness if not DatabaseDAO.validate_uniqueness(database_name): exceptions.append(DatabaseExistsValidationError()) if exceptions: exception = DatabaseInvalidError() exception.add_list(exceptions) raise exception
def validate(self) -> None: exceptions: List[ValidationError] = [] sqlalchemy_uri: Optional[str] = self._properties.get("sqlalchemy_uri") database_name: Optional[str] = self._properties.get("database_name") if not sqlalchemy_uri: exceptions.append(DatabaseRequiredFieldValidationError("sqlalchemy_uri")) if not database_name: exceptions.append(DatabaseRequiredFieldValidationError("database_name")) else: # Check database_name uniqueness if not DatabaseDAO.validate_uniqueness(database_name): exceptions.append(DatabaseExistsValidationError()) if exceptions: exception = DatabaseInvalidError() exception.add_list(exceptions) event_logger.log_with_context( action=f"db_connection_failed.{exception.__class__.__name__}" ) raise exception
def make_url_safe(raw_url: Union[str, URL]) -> URL: """ Wrapper for SQLAlchemy's make_url(), which tends to raise too detailed of errors, which inevitably find their way into server logs. ArgumentErrors tend to contain usernames and passwords, which makes them non-log-friendly :param raw_url: :return: """ if isinstance(raw_url, str): url = raw_url.strip() try: return make_url(url) # noqa except Exception: raise DatabaseInvalidError() # pylint: disable=raise-missing-from else: return raw_url