Esempio n. 1
0
def handle_error(msg):
    """Handle an error."""
    lg().disabled = False
    lg().error(msg)
    from jomiel_kore.app import exit_error

    exit_error()
Esempio n. 2
0
        def generate_keypair(filename):
            """Generate a new key-pair."""

            from os.path import abspath, dirname, basename

            fpath = abspath(filename)
            basedir = dirname(fpath)

            from zmq.auth import create_certificates

            try:
                name = basename(fpath)
                (
                    public_key_file,
                    secret_key_file,
                ) = create_certificates(basedir, name)
            except OSError as message:
                print("error: %s" % message)
                from jomiel_kore.app import exit_error

                exit_error()

            from os import chmod

            chmod(public_key_file, 0o644)
            chmod(secret_key_file, 0o400)

            print("Created:\n  %s\n  %s" %
                  (public_key_file, secret_key_file), )
Esempio n. 3
0
    def run(self):
        """Application entry point; executes the app."""
        from configargparse import get_parser

        parser = get_parser()

        parser.add(
            "filename",
            help="""Name for the authentication key-pair files for use
                    with jomiel""",
            nargs="*",
        )

        opts = super().parse_opts(parser)

        if len(opts.filename) == 0:
            from sys import stderr
            from jomiel_kore.app import exit_error

            print(
                "error: the following arguments are required: filename",
                file=stderr,
            )

            exit_error()

        def generate_keypair(filename):
            """Generate a new key-pair."""

            from os.path import abspath, dirname, basename

            fpath = abspath(filename)
            basedir = dirname(fpath)

            from zmq.auth import create_certificates

            try:
                name = basename(fpath)
                (
                    public_key_file,
                    secret_key_file,
                ) = create_certificates(basedir, name)
            except OSError as message:
                print("error: %s" % message)
                from jomiel_kore.app import exit_error

                exit_error()

            from os import chmod

            chmod(public_key_file, 0o644)
            chmod(secret_key_file, 0o400)

            print("Created:\n  %s\n  %s" %
                  (public_key_file, secret_key_file), )

        for filename in opts.filename:
            generate_keypair(filename)
Esempio n. 4
0
    def bind_endpoint(device, endpoint, setup_curve=False):
        """Bind the device to the endpoint."""
        sck = ctx.socket(device)
        auth = None
        if opts.curve_enable and setup_curve:
            log("setup curve support")
            from jomiel.curve import setup

            auth = setup(sck)  # Must come before bind.
        try:
            sck.bind(endpoint)
        except ZMQError as error:
            log(f"{error}: {endpoint}", "error")
            exit_error()
        return (sck, auth)
Esempio n. 5
0
    def new_socket(self):
        """Returns a new socket that is connected to the broker (via the
        dealer endpoint).

        """
        sck = self.context.socket(REP)
        try:
            sck.connect(self.dealer_endpoint)
        except ZMQError as error:
            self.log(
                f"{error} ({self.dealer_endpoint})",
                "error",
            )
            exit_error()
        self.log("connected to <%s>" % self.dealer_endpoint)
        return sck