Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

61 linhas
2.5 KiB

  1. # Copyright 2017 New Vector Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import logging
  15. from typing import Any, Dict, List, Tuple
  16. from synapse.config import ConfigError
  17. from synapse.types import JsonDict
  18. from synapse.util.module_loader import load_module
  19. from ._base import Config
  20. logger = logging.getLogger(__name__)
  21. LEGACY_SPAM_CHECKER_WARNING = """
  22. This server is using a spam checker module that is implementing the deprecated spam
  23. checker interface. Please check with the module's maintainer to see if a new version
  24. supporting Synapse's generic modules system is available. For more information, please
  25. see https://matrix-org.github.io/synapse/latest/modules/index.html
  26. ---------------------------------------------------------------------------------------"""
  27. class SpamCheckerConfig(Config):
  28. section = "spamchecker"
  29. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  30. self.spam_checkers: List[Tuple[Any, Dict]] = []
  31. spam_checkers = config.get("spam_checker") or []
  32. if isinstance(spam_checkers, dict):
  33. # The spam_checker config option used to only support one
  34. # spam checker, and thus was simply a dictionary with module
  35. # and config keys. Support this old behaviour by checking
  36. # to see if the option resolves to a dictionary
  37. self.spam_checkers.append(load_module(spam_checkers, ("spam_checker",)))
  38. elif isinstance(spam_checkers, list):
  39. for i, spam_checker in enumerate(spam_checkers):
  40. config_path = ("spam_checker", "<item %i>" % i)
  41. if not isinstance(spam_checker, dict):
  42. raise ConfigError("expected a mapping", config_path)
  43. self.spam_checkers.append(load_module(spam_checker, config_path))
  44. else:
  45. raise ConfigError("spam_checker syntax is incorrect")
  46. # If this configuration is being used in any way, warn the admin that it is going
  47. # away soon.
  48. if self.spam_checkers:
  49. logger.warning(LEGACY_SPAM_CHECKER_WARNING)