示例#1
0
def make_gunicorn_server():
    """Create a gunicorn server.

    Use this to run the REST API using Gunicorn.
    """
    # We load some options from config.webservice, while other extended options
    # for gunicorn can be defined in configuration: section. We also load up
    # some logging options since gunicorn sets up it's own loggers.
    host = config.webservice.hostname
    port = int(config.webservice.port)
    log_path = os.path.join(config.LOG_DIR, config.logging.http['path'])
    options = {
        'bind': '{}:{}'.format(host, port),
        'accesslog': log_path,
        'errorlog': log_path,
        'loglevel': config.logging.http['level'],
        'access_log_format': config.logging.http['format'],
        'disable_redirect_access_to_syslog': True,
        'workers': int(config.webservice.workers),
    }
    # Read the ini configuration and pass those values to the
    # GunicornApplication.
    gunicorn_config = external_configuration(config.webservice.configuration)
    for key in gunicorn_config['gunicorn']:
        options[key] = gunicorn_config['gunicorn'][key]

    return GunicornApplication(make_application(), options)
示例#2
0
    def _load_config(self):
        """Load configuration."""
        # Read our specific configuration file
        archiver_config = external_configuration(
            config.archiver.telegram_webhook.configuration
        )
        try:
            self.token = archiver_config.get("global", "token")
        except (KeyError, NoOptionError):
            self.token = None
            _log_error("No telegram token found in configuration")

        try:
            self.chat_id = archiver_config.get("global", "chat_id")
        except (KeyError, NoOptionError):
            self.chat_id = None

        try:
            self.filter_spam = archiver_config.get("global", "filter_spam")
        except (KeyError, NoOptionError):
            self.filter_spam = False

        try:
            for section in archiver_config.sections():
                if section.startswith("list."):
                    list_name = section[5:]
                    self.chats_id[list_name] = archiver_config[section]["chat_id"]
                else:
                    continue
        except (KeyError, NoOptionError) as e:
            _log_error(
                "While parsing the config for lists configuration, there was an error "
                + str(e.message)
            )
示例#3
0
 def _load_conf(self):
     """
     Find the location of the Django settings module from Mailman's
     configuration file, and load it to get the store's URL.
     """
     # Read our specific configuration file
     archiver_config = external_configuration(
             config.archiver.hyperkitty.configuration)
     self.base_url = archiver_config.get("general", "base_url")
     settings_path = archiver_config.get("general", "django_settings")
     if settings_path.endswith("/settings.py"):
         # we want the directory
         settings_path = os.path.dirname(settings_path)
     #path_added = False
     if settings_path not in sys.path:
         #path_added = True
         sys.path.append(settings_path)
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
     try:
         from django.conf import settings
     except ImportError:
         raise ImportError("Could not import Django's settings from %s"
                           % settings_path)
     self.store_url = settings.KITTYSTORE_URL
     self.store_search_index = settings.KITTYSTORE_SEARCH_INDEX
 def _load_config(self):
     """
     Find the location of the HyperKitty-specific config file from Mailman's
     main config file and load the values.
     """
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.webhook.configuration)
     try:
         self.url = archiver_config.get("global", "url")
     except (KeyError, NoOptionError):
         self.url = ""
         pass
     try:
         self.message_format = archiver_config.get("global",
                                                   "message_format")
     except (KeyError, NoOptionError):
         pass
     try:
         for section in archiver_config.sections():
             if section.startswith("list."):
                 list_name = section[5:]
                 self.list_urls[list_name] = archiver_config[section]["url"]
                 if archiver_config[section]["url"] != "":
                     _log_error(list_name +
                                " channel is ready to send out messages!")
             else:
                 continue
     except (KeyError, NoOptionError) as e:
         _log_error(
             "While parsing the config for lists configuration, there was an error "
             + str(e.message))
示例#5
0
    def __init__(self):
        # Read our specific configuration file
        archiver_config = external_configuration(
            config.archiver.public_inbox.configuration)
        self.public_inbox_config = archiver_config.get('general', 'pi_config')
        self.public_inbox_home = archiver_config.get('general', 'pi_home')
        self.public_inbox_path = archiver_config.get('general', 'pi_path')

        self.pi_config = {}
示例#6
0
 def _load_conf(self):
     """
     Find the location of the Django settings module from Mailman's
     configuration file, and load it to get the store's URL.
     """
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.hyperkitty.configuration)
     self._base_url = archiver_config.get("general", "base_url")
     if not self._base_url.endswith("/"):  # pylint: disable=no-member
         self._base_url += "/"
     self._api_key = archiver_config.get("general", "api_key")
示例#7
0
 def _load_conf(self):
     """
     Find the location of the Django settings module from Mailman's
     configuration file, and load it to get the store's URL.
     """
     # Read our specific configuration file
     archiver_config = external_configuration(
             config.archiver.hyperkitty.configuration)
     self._base_url = archiver_config.get("general", "base_url")
     if not self._base_url.endswith("/"): # pylint: disable=no-member
         self._base_url += "/"
     self._api_key = archiver_config.get("general", "api_key")
示例#8
0
def init():
    cfg = external_configuration(
        config.plugin.mailman_rest_event.configuration)
    event_webhook_url = cfg.get("general", "webhook_url", fallback=None)
    try:
        timeout = int(cfg.get("general", "timeout", fallback=2))
    except:
        timeout = 2
    auth_user = cfg.get("auth", "user", fallback=None)
    auth_key = cfg.get("auth", "key", fallback=None)

    auth = None
    if auth_user and auth_key:
        auth = (auth_user, auth_key)

    if not event_webhook_url:
        logger.info("Webhook URL not set, will not be sending events")
        return

    logger.info(f"Webhook URL: {event_webhook_url}")

    handlers = {
        SubscriptionEvent: (lambda evt: {
            "event": "user_subscribed",
            "mlist": mlist_to_json(evt.mlist),
            "member": member_to_json(evt.member)
        }),
        UnsubscriptionEvent: (lambda evt: {
            "event": "user_unsubscribed",
            "mlist": mlist_to_json(evt.mlist),
            "member": member_to_json(evt.member)
        }),
        HandledMessageEvent: (lambda evt: {
            "event": "new_message",
            "mlist": mlist_to_json(evt.mlist),
            "message": message_to_obj(evt.msg)
        }),
    }

    def handle_event(evt):
        t = type(evt)
        if t in handlers:
            try:
                logger.info(f"Posting: {type(evt)}")
                result = requests.post(event_webhook_url,
                                       json=handlers[t](evt),
                                       auth=auth,
                                       timeout=timeout)
            except Exception as e:
                logger.error(f"Failed to post: {e}")

    subscribers.append(handle_event)
示例#9
0
 def _load_conf(self):
     """
     Find the location of the HyperKitty-specific config file from Mailman's
     main config file and load the values.
     """
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.hyperkitty.configuration)
     for option in ("base_url", ):
         url = archiver_config.get("general", option)
         if not url.endswith("/"):
             url += "/"
         self._conf[option] = url
     self._conf["api_key"] = archiver_config.get("general", "api_key")
示例#10
0
 def _load_conf(self):
     """
     Find the location of the Django settings module from Mailman's
     configuration file, and load it to get the store's URL.
     """
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.hyperkitty.configuration)
     settings_path = archiver_config.get("general", "django_settings")
     if settings_path.endswith("/settings.py"):
         # we want the directory
         settings_path = os.path.dirname(settings_path)
     #path_added = False
     if settings_path not in sys.path:
         #path_added = True
         sys.path.append(settings_path)
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
     try:
         from django.conf import settings
     except ImportError:
         raise ImportError("Could not import Django's settings from %s" %
                           settings_path)
     self.store_url = settings.KITTYSTORE_URL
示例#11
0
 def test_external_configuration_by_path(self):
     parser = external_configuration('python:mailman.config.postfix')
     self.assertEqual(parser.get('postfix', 'postmap_command'),
                      '/usr/sbin/postmap')
示例#12
0
 def test_external_configuration_by_filename(self):
     filename = resource_filename('mailman.config', 'postfix.cfg')
     parser = external_configuration(filename)
     self.assertEqual(parser.get('postfix', 'postmap_command'),
                      '/usr/sbin/postmap')
示例#13
0
 def __init__(self):
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.mhonarc.configuration)
     self.base_url = archiver_config.get('general', 'base_url')
     self.command = archiver_config.get('general', 'command')
示例#14
0
 def __init__(self):
     # Read our specific configuration file
     archiver_config = external_configuration(config.archiver.mhonarc.configuration)
     self.base_url = archiver_config.get("general", "base_url")
     self.command = archiver_config.get("general", "command")
示例#15
0
 def __init__(self):
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.mhonarc.configuration)
     self.base_url = archiver_config.get('general', 'base_url')
     self.command = archiver_config.get('general', 'command')
示例#16
0
 def test_external_configuration_by_path(self):
     parser = external_configuration('python:mailman.config.postfix')
     self.assertEqual(parser.get('postfix', 'postmap_command'),
                      '/usr/sbin/postmap')
示例#17
0
 def test_external_configuration_by_filename(self):
     filename = resource_filename('mailman.config', 'postfix.cfg')
     parser = external_configuration(filename)
     self.assertEqual(parser.get('postfix', 'postmap_command'),
                      '/usr/sbin/postmap')
示例#18
0
 def test_missing_configuration_file(self):
     with self.assertRaises(MissingConfigurationFileError) as cm:
         external_configuration('path:mailman.config.missing')
     self.assertEqual(cm.exception.path, 'path:mailman.config.missing')
示例#19
0
 def test_external_configuration_by_filename(self):
     with path('mailman.config', 'postfix.cfg') as filename:
         parser = external_configuration(str(filename))
     self.assertEqual(parser.get('postfix', 'postmap_command'),
                      '/usr/sbin/postmap')
示例#20
0
 def test_missing_configuration_file(self):
     with self.assertRaises(MissingConfigurationFileError) as cm:
         external_configuration('path:mailman.config.missing')
     self.assertEqual(cm.exception.path, 'path:mailman.config.missing')
示例#21
0
 def __init__(self):
     # Locate and read the Postfix specific configuration file.
     mta_config = external_configuration(config.mta.configuration)
     self.postmap_command = mta_config.get("postfix", "postmap_command")
示例#22
0
 def __init__(self):
     # Locate and read the Postfix specific configuration file.
     mta_config = external_configuration(config.mta.configuration)
     self.postmap_command = mta_config.get('postfix', 'postmap_command')
     self.transport_file_type = mta_config.get('postfix',
                                               'transport_file_type')
示例#23
0
 def __init__(self):
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.mail_archive.configuration)
     self.base_url = archiver_config.get('general', 'base_url')
     self.recipient = archiver_config.get('general', 'recipient')
示例#24
0
 def __init__(self):
     # Read our specific configuration file
     archiver_config = external_configuration(
         config.archiver.mail_archive.configuration)
     self.base_url = archiver_config.get('general', 'base_url')
     self.recipient = archiver_config.get('general', 'recipient')