How to use the certbot.errors.MisconfigurationError function in certbot

To help you get started, we’ve selected a few certbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github certbot / certbot / certbot-nginx / certbot_nginx / configurator.py View on Github external
def config_test(self):  # pylint: disable=no-self-use
        """Check the configuration of Nginx for errors.

        :raises .errors.MisconfigurationError: If config_test fails

        """
        try:
            util.run_script([self.conf('ctl'), "-c", self.nginx_conf, "-t"])
        except errors.SubprocessError as err:
            raise errors.MisconfigurationError(str(err))
github certbot / certbot / certbot-apache / certbot_apache / _internal / configurator.py View on Github external
def config_test(self):  # pylint: disable=no-self-use
        """Check the configuration of Apache for errors.

        :raises .errors.MisconfigurationError: If config_test fails

        """
        try:
            util.run_script(self.option("conftest_cmd"))
        except errors.SubprocessError as err:
            raise errors.MisconfigurationError(str(err))
github EFForg / starttls-everywhere / certbot-postfix / certbot_postfix / util.py View on Github external
def test(self):
        """Make sure the configuration is valid.

        :raises .MisconfigurationError: if the config is invalid
        """
        try:
            self._call(["check"])
        except subprocess.CalledProcessError as e:
            print e
            raise errors.MisconfigurationError(
                "Postfix failed internal configuration check.")
github certbot / certbot / certbot-nginx / certbot_nginx / configurator.py View on Github external
for vhost in vhost_list:
            for addr in vhost.addrs:
                if addr.default:
                    all_default_vhosts.append(vhost)
                    if self._port_matches(port, addr.get_port()):
                        port_matching_vhosts.append(vhost)
                    break

        if len(port_matching_vhosts) == 1:
            return port_matching_vhosts[0]
        elif len(all_default_vhosts) == 1 and allow_port_mismatch:
            return all_default_vhosts[0]

        # TODO: present a list of vhosts for user to choose from

        raise errors.MisconfigurationError("Could not automatically find a matching server"
            " block for %s. Set the `server_name` directive to use the Nginx installer." % domain)
github certbot / certbot / certbot-nginx / certbot_nginx / _internal / parser.py View on Github external
def _modify_server_directives(self, vhost, block_func):
        filename = vhost.filep
        try:
            result = self.parsed[filename]
            for index in vhost.path:
                result = result[index]
            if not isinstance(result, list) or len(result) != 2:
                raise errors.MisconfigurationError("Not a server block.")
            result = result[1]
            block_func(result)

            self._update_vhost_based_on_new_directives(vhost, result)
        except errors.MisconfigurationError as err:
            raise errors.MisconfigurationError("Problem in %s: %s" % (filename, str(err)))
github certbot / certbot / certbot-apache / certbot_apache / configurator.py View on Github external
self.option("restart_cmd"))
            alt_restart = self.option("restart_cmd_alt")
            if alt_restart:
                logger.debug("Trying alternative restart command: %s",
                             alt_restart)
                # There is an alternative restart command available
                # This usually is "restart" verb while original is "graceful"
                try:
                    util.run_script(self.option(
                        "restart_cmd_alt"))
                    return
                except errors.SubprocessError as secerr:
                    error = str(secerr)
            else:
                error = str(err)
            raise errors.MisconfigurationError(error)
github EFForg / starttls-everywhere / certbot / certbot-nginx / certbot_nginx / parser.py View on Github external
'expected directive for %s in the Nginx '
                'config but did not find it.' % directive[0])
        block[location] = directive
    else:
        # Append directive. Fail if the name is not a repeatable directive name,
        # and there is already a copy of that directive with a different value
        # in the config file.
        directive_name = directive[0]
        directive_value = directive[1]
        if location != -1 and directive_name.__str__() not in repeatable_directives:
            if block[location][1] == directive_value:
                # There's a conflict, but the existing value matches the one we
                # want to insert, so it's fine.
                pass
            else:
                raise errors.MisconfigurationError(
                    'tried to insert directive "%s" but found conflicting "%s".' % (
                    directive, block[location]))
        else:
            block.append(directive)
github certbot / certbot / certbot-nginx / certbot_nginx / configurator.py View on Github external
try:
        proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf, "-s", "reload"])
        proc.communicate()

        if proc.returncode != 0:
            # Maybe Nginx isn't running
            # Write to temporary files instead of piping because of communication issues on Arch
            # https://github.com/certbot/certbot/issues/4324
            with tempfile.TemporaryFile() as out:
                with tempfile.TemporaryFile() as err:
                    nginx_proc = subprocess.Popen([nginx_ctl, "-c", nginx_conf],
                        stdout=out, stderr=err)
                    nginx_proc.communicate()
                    if nginx_proc.returncode != 0:
                        # Enter recovery routine...
                        raise errors.MisconfigurationError(
                            "nginx restart failed:\n%s\n%s" % (out.read(), err.read()))

    except (OSError, ValueError):
        raise errors.MisconfigurationError("nginx restart failed")
    # Nginx can take a moment to recognize a newly added TLS SNI servername, so sleep
    # for a second. TODO: Check for expected servername and loop until it
    # appears or return an error if looping too long.
    time.sleep(1)