Example #1
0
    def postOptions(self):
        BaseOptions.postOptions(self)
        if self['running_author-whitelist']:
            self['author-whitelist'] = self['running_author-whitelist']
        else:
            self['author-whitelist'] = [ip_network(self['author-whitelist'], strict=False)]

        if self['running_subscriber-whitelist']:
            self['subscriber-whitelist'] = self['running_subscriber-whitelist']
        else:
            self['subscriber-whitelist'] = [ip_network(self['subscriber-whitelist'], strict=False)]

        if self['verbosity'] >= 2:
            log.LEVEL = log.Levels.DEBUG
        elif self['verbosity'] == 1:
            log.LEVEL = log.Levels.INFO
        else:
            log.LEVEL = log.Levels.WARNING

        # Now enable plugins if requested.
        # We loop over all plugins, checking if the user supplied their name
        # on the command line and adding them to our list of handlers if so.
        for plugin in getPlugins(IHandler, comet.plugins):
            if self[plugin.name]:
                if IHasOptions.providedBy(plugin):
                    for name, _, _ in plugin.get_options():
                        plugin.set_option(name, self["%s-%s" % (plugin.name, name)])
                self['handlers'].append(plugin)
Example #2
0
    def postOptions(self):
        BaseOptions.postOptions(self)
        if self['running_author-whitelist']:
            self['author-whitelist'] = self['running_author-whitelist']
        else:
            self['author-whitelist'] = [ip_network(self['author-whitelist'], strict=False)]

        if self['running_subscriber-whitelist']:
            self['subscriber-whitelist'] = self['running_subscriber-whitelist']
        else:
            self['subscriber-whitelist'] = [ip_network(self['subscriber-whitelist'], strict=False)]

        if self['verbosity'] >= 2:
            log.LEVEL = log.Levels.DEBUG
        elif self['verbosity'] == 1:
            log.LEVEL = log.Levels.INFO
        else:
            log.LEVEL = log.Levels.WARNING

        # Now enable plugins if requested.
        # We loop over all plugins, checking if the user supplied their name
        # on the command line and adding them to our list of handlers if so.
        for plugin in getPlugins(IHandler, comet.plugins):
            if self[plugin.name]:
                if IHasOptions.providedBy(plugin):
                    for name, _, _ in plugin.get_options():
                        plugin.set_option(name, self["%s-%s" % (plugin.name, name)])
                self['handlers'].append(plugin)
Example #3
0
 def _configure_plugins(self):
     """Internal-use method to configure any plugins requested.
     """
     if self._config.handlers is None:
         self._config.handlers = []
     if self._config.plugins:
         for plugin in getPlugins(IHandler, comet.plugins):
             if plugin.name in self._config.plugins:
                 if IHasOptions.providedBy(plugin):
                     for name, _, _ in plugin.get_options():
                         plugin.set_option(name,
                                           getattr(self._config,
                                                   f"{plugin.name}-{name}".replace("-", "_")))
                 self._config.handlers.append(plugin)
Example #4
0
 def _configure_plugins(self):
     """Internal-use method to configure any plugins requested.
     """
     if self._config.handlers is None:
         self._config.handlers = []
     if self._config.plugins:
         for plugin in getPlugins(IHandler, comet.plugins):
             if plugin.name in self._config.plugins:
                 if IHasOptions.providedBy(plugin):
                     for name, _, _ in plugin.get_options():
                         plugin.set_option(
                             name,
                             getattr(
                                 self._config,
                                 f"{plugin.name}-{name}".replace("-", "_")))
                 self._config.handlers.append(plugin)
Example #5
0
        # We loop over all plugins, checking if the user supplied their name
        # on the command line and adding them to our list of handlers if so.
        for plugin in getPlugins(IHandler, comet.plugins):
            if self[plugin.name]:
                if IHasOptions.providedBy(plugin):
                    for name, _, _ in plugin.get_options():
                        plugin.set_option(name, self["%s-%s" % (plugin.name, name)])
                self['handlers'].append(plugin)


# Stub the options for all our plugins into the option handler
for plugin in getPlugins(IHandler, comet.plugins):
    Options.optFlags.append(
        [plugin.name, None, "Enable the %s plugin." % (plugin.name,)]
    )
    if IHasOptions.providedBy(plugin):
        for name, default, description in plugin.get_options():
            Options.optParameters.append(
                ["%s-%s" % (plugin.name, name), None, default, description]
            )


def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
Example #6
0
 def test_interface(self):
     self.assertTrue(IHandler.implementedBy(EventWriter))
     self.assertTrue(IPlugin.implementedBy(EventWriter))
     self.assertTrue(IHasOptions.implementedBy(EventWriter))
Example #7
0
    def _configureParser(self):
        std_group = self.parser.add_argument_group(
            "Standard arguments", "Global options affecting "
            "broker operation.")
        std_group.add_argument("--local-ivo",
                               type=valid_ivoid,
                               help="IVOA identifier for this system. "
                               "Required if using --receive or --broadcast.")

        # Note that `Event_DB` fails gracefully(ish) if this isn't an
        # appopriate location, so we don't sanity check it here.
        std_group.add_argument(
            "--eventdb",
            default=gettempdir(),
            help="Event database root [default=%(default)s].")

        rcv_group = self.parser.add_argument_group(
            "Event Receiver", "Receive events submitted "
            "by remote authors.")
        rcv_group.add_argument(
            "--receive",
            default=None,
            const=f"tcp:{DEFAULT_SUBMIT_PORT}",
            nargs="?",
            action="append",
            type=lambda ep: coerce_to_server_endpoint(reactor, ep),
            help="Add an endpoint for receiving events.")
        rcv_group.add_argument("--receive-whitelist",
                               default=[ip_network("0.0.0.0/0")],
                               nargs="*",
                               type=ip_network,
                               help="Networks from which to accept "
                               "event submissions [default=accept from "
                               "everywhere].")

        bcast_group = self.parser.add_argument_group(
            "Event Broadcaster", "Broadcast events to "
            "remote subscribers.")
        bcast_group.add_argument(
            "--broadcast",
            default=None,
            const=f"tcp:{DEFAULT_SUBSCRIBE_PORT}",
            nargs="?",
            action="append",
            type=lambda ep: coerce_to_server_endpoint(reactor, ep),
            help="Add an endpoint for broadcasting events.")
        bcast_group.add_argument("--broadcast-test-interval",
                                 default=BCAST_TEST_INTERVAL,
                                 type=int,
                                 help="Interval between test event broadcasts "
                                 "(seconds) [default=%(default)s].")
        bcast_group.add_argument("--broadcast-whitelist",
                                 default=[ip_network("0.0.0.0/0")],
                                 nargs="*",
                                 type=ip_network,
                                 help="Networks from which to accept "
                                 "subscription requests [default=accept "
                                 "from everywhere].")

        sub_group = self.parser.add_argument_group(
            "Event Subscriber", "Subscribe to event streams"
            " from remote brokers.")
        sub_group.add_argument("--subscribe",
                               default=None,
                               action="append",
                               type=lambda ep: coerce_to_client_endpoint(
                                   reactor, ep, DEFAULT_SUBSCRIBE_PORT),
                               help="Add a remote broker to which "
                               "to subscribe.")
        sub_group.add_argument("--filter",
                               default=None,
                               action="append",
                               dest="filters",
                               type=valid_xpath,
                               help="XPath filter to be applied to events "
                               "received from remote brokers.")

        proc_group = self.parser.add_argument_group(
            "Event Processors", "Define 'event handlers' "
            "which are applied to all "
            "events processed by this "
            "system.")
        proc_group.add_argument("--cmd",
                                default=None,
                                action="append",
                                dest="handlers",
                                type=SpawnCommand,
                                help="External command to spawn when an "
                                "event is received.")

        for plugin in getPlugins(IHandler, comet.plugins):
            proc_group.add_argument(f"--{plugin.name}",
                                    help=f"Enable the {plugin.name} plugin.",
                                    action="append_const",
                                    const=plugin.name,
                                    dest="plugins")
            if IHasOptions.providedBy(plugin):
                for name, default, description in plugin.get_options():
                    proc_group.add_argument(f"--{plugin.name}-{name}",
                                            default=default,
                                            help=description)
Example #8
0
 def test_interface(self):
     self.assertTrue(IHandler.implementedBy(EventWriter))
     self.assertTrue(IPlugin.implementedBy(EventWriter))
     self.assertTrue(IHasOptions.implementedBy(EventWriter))
Example #9
0
        # We loop over all plugins, checking if the user supplied their name
        # on the command line and adding them to our list of handlers if so.
        for plugin in getPlugins(IHandler, comet.plugins):
            if self[plugin.name]:
                if IHasOptions.providedBy(plugin):
                    for name, _, _ in plugin.get_options():
                        plugin.set_option(name, self["%s-%s" % (plugin.name, name)])
                self['handlers'].append(plugin)


# Stub the options for all our plugins into the option handler
for plugin in getPlugins(IHandler, comet.plugins):
    Options.optFlags.append(
        [plugin.name, None, "Enable the %s plugin." % (plugin.name,)]
    )
    if IHasOptions.providedBy(plugin):
        for name, default, description in plugin.get_options():
            Options.optParameters.append(
                ["%s-%s" % (plugin.name, name), None, default, description]
            )


def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
Example #10
0
    def _configureParser(self):
        std_group = self.parser.add_argument_group("Standard arguments",
                                                   "Global options affecting "
                                                   "broker operation.")
        std_group.add_argument("--local-ivo",
                               type=valid_ivoid,
                               help="IVOA identifier for this system. "
                                    "Required if using --receive or --broadcast.")

        # Note that `Event_DB` fails gracefully(ish) if this isn't an
        # appopriate location, so we don't sanity check it here.
        std_group.add_argument("--eventdb", default=gettempdir(),
                               help="Event database root [default=%(default)s].")

        rcv_group = self.parser.add_argument_group("Event Receiver",
                                                   "Receive events submitted "
                                                   "by remote authors.")
        rcv_group.add_argument("--receive",
                               default=None,
                               const=f"tcp:{DEFAULT_SUBMIT_PORT}",
                               nargs="?",
                               action="append",
                               type=lambda ep: coerce_to_server_endpoint(reactor, ep),
                               help="Add an endpoint for receiving events.")
        rcv_group.add_argument("--receive-whitelist",
                               default=[ip_network("0.0.0.0/0")],
                               nargs="*",
                               type=ip_network,
                               help="Networks from which to accept "
                                    "event submissions [default=accept from "
                                    "everywhere].")

        bcast_group = self.parser.add_argument_group("Event Broadcaster",
                                                     "Broadcast events to "
                                                     "remote subscribers.")
        bcast_group.add_argument("--broadcast",
                                 default=None,
                                 const=f"tcp:{DEFAULT_SUBSCRIBE_PORT}",
                                 nargs="?",
                                 action="append",
                                 type=lambda ep: coerce_to_server_endpoint(reactor, ep),
                                 help="Add an endpoint for broadcasting events.")
        bcast_group.add_argument("--broadcast-test-interval",
                                 default=BCAST_TEST_INTERVAL,
                                 type=int,
                                 help="Interval between test event broadcasts "
                                      "(seconds) [default=%(default)s].")
        bcast_group.add_argument("--broadcast-whitelist",
                                 default=[ip_network("0.0.0.0/0")],
                                 nargs="*",
                                 type=ip_network,
                                 help="Networks from which to accept "
                                      "subscription requests [default=accept "
                                      "from everywhere].")

        sub_group = self.parser.add_argument_group("Event Subscriber",
                                                   "Subscribe to event streams"
                                                   " from remote brokers.")
        sub_group.add_argument("--subscribe",
                               default=None,
                               action="append",
                               type=lambda ep: coerce_to_client_endpoint(reactor, ep, DEFAULT_SUBSCRIBE_PORT),
                               help="Add a remote broker to which "
                                    "to subscribe.")
        sub_group.add_argument("--filter",
                                 default=None,
                                 action="append",
                                 dest="filters",
                                 type=valid_xpath,
                                 help="XPath filter to be applied to events "
                                      "received from remote brokers.")

        proc_group = self.parser.add_argument_group("Event Processors",
                                                    "Define 'event handlers' "
                                                    "which are applied to all "
                                                    "events processed by this "
                                                    "system.")
        proc_group.add_argument("--cmd",
                                default=None,
                                action="append",
                                dest="handlers",
                                type=SpawnCommand,
                                help="External command to spawn when an "
                                     "event is received.")

        for plugin in getPlugins(IHandler, comet.plugins):
            proc_group.add_argument(f"--{plugin.name}",
                                    help=f"Enable the {plugin.name} plugin.",
                                    action="append_const",
                                    const=plugin.name,
                                    dest="plugins")
            if IHasOptions.providedBy(plugin):
                for name, default, description in plugin.get_options():
                    proc_group.add_argument(f"--{plugin.name}-{name}",
                                            default=default,
                                            help=description)