How to use the letsencrypt.errors.PluginError function in letsencrypt

To help you get started, we’ve selected a few letsencrypt 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 / letsencrypt-apache / letsencrypt_apache / configurator.py View on Github external
"""
        avail_fp = nonssl_vhost.filep
        ssl_fp = self._get_ssl_vhost_path(avail_fp)

        self._copy_create_ssl_vhost_skeleton(avail_fp, ssl_fp)

        # Reload augeas to take into account the new vhost
        self.aug.load()
        #TODO: add line to write vhost name
        # Get Vhost augeas path for new vhost
        vh_p = self.aug.match("/files%s//* [label()=~regexp('%s')]" %
                              (ssl_fp, parser.case_i("VirtualHost")))
        if len(vh_p) != 1:
            logger.error("Error: should only be one vhost in %s", avail_fp)
            raise errors.PluginError("Currently, we only support "
                                     "configurations with one vhost per file")
        else:
            # This simplifies the process
            vh_p = vh_p[0]

        # Update Addresses
        self._update_ssl_vhosts_addrs(vh_p)

        # Add directives
        self._add_dummy_ssl_directives(vh_p)
        self.save()

        # Log actions and create save notes
        logger.info("Created an SSL vhost at %s", ssl_fp)
        self.save_notes += "Created ssl vhost at %s\n" % ssl_fp
        self.save()
github certbot / certbot / letsencrypt-compatibility-test / letsencrypt_compatibility_test / test_driver.py View on Github external
def test_enhancements(plugin, domains):
    """Tests supported enhancements returning True if successful"""
    supported = plugin.supported_enhancements()

    if "redirect" not in supported:
        logger.error("The plugin and this program support no common "
                     "enhancements")
        return False

    for domain in domains:
        try:
            plugin.enhance(domain, "redirect")
        except le_errors.PluginError as error:
            # Don't immediately fail because a redirect may already be enabled
            logger.warning("Plugin failed to enable redirect for %s:", domain)
            logger.warning("%s", error)
        except le_errors.Error as error:
            logger.error("An error occurred while enabling redirect for %s:",
                         domain)
            logger.exception(error)

    if not _save_and_restart(plugin, "enhanced"):
        return False

    success = True
    for domain in domains:
        verify = functools.partial(validator.Validator().redirect, "localhost",
                                   plugin.http_port, headers={"Host": domain})
        if not _try_until_true(verify):
github sjerdo / letsencrypt-directadmin / letsencrypt_directadmin / configurator.py View on Github external
raise PluginError('User did not supply a DirectAdmin server url.')
        parsed_url = urlsplit(self.conf('server'))

        if self.conf('username') is not None:
            username = self.conf('username')
        elif parsed_url.username is not None:
            username = parsed_url.username
        else:
            raise PluginError('User did not supply a DirectAdmin username')

        if self.conf('login-key') is not None:
            loginkey = self.conf('login-key')
        elif parsed_url.password is not None:
            loginkey = parsed_url.password
        else:
            raise PluginError('User did not supply a DirectAdmin login key')

        self.da_api_client = directadmin.Api(
            https=(False if parsed_url.scheme == 'http' else True),
            hostname=(parsed_url.hostname if parsed_url.hostname else 'localhost'),
            port=(parsed_url.port if parsed_url.port else 2222),
            username=username,
            password=loginkey)
github certbot / certbot / letsencrypt-apache / letsencrypt_apache / configurator.py View on Github external
:raises .PluginError: if unable to find Apache version

        """
        try:
            stdout, _ = le_util.run_script(
                constants.os_constant("version_cmd"))
        except errors.SubprocessError:
            raise errors.PluginError(
                "Unable to run %s -v" %
                constants.os_constant("version_cmd"))

        regex = re.compile(r"Apache/([0-9\.]*)", re.IGNORECASE)
        matches = regex.findall(stdout)

        if len(matches) != 1:
            raise errors.PluginError("Unable to find Apache version")

        return tuple([int(i) for i in matches[0].split(".")])
github sjerdo / letsencrypt-directadmin / letsencrypt_directadmin / configurator.py View on Github external
def prepare_da_client(self):
        """ Prepare the DirectAdmin Web API Client """
        if self.conf('server') is None:
            # TODO: check if there is a local server at https://localhost:2222 (with non-ssl fallback?)
            raise PluginError('User did not supply a DirectAdmin server url.')
        parsed_url = urlsplit(self.conf('server'))

        if self.conf('username') is not None:
            username = self.conf('username')
        elif parsed_url.username is not None:
            username = parsed_url.username
        else:
            raise PluginError('User did not supply a DirectAdmin username')

        if self.conf('login-key') is not None:
            loginkey = self.conf('login-key')
        elif parsed_url.password is not None:
            loginkey = parsed_url.password
        else:
            raise PluginError('User did not supply a DirectAdmin login key')

        self.da_api_client = directadmin.Api(
            https=(False if parsed_url.scheme == 'http' else True),
            hostname=(parsed_url.hostname if parsed_url.hostname else 'localhost'),
            port=(parsed_url.port if parsed_url.port else 2222),
            username=username,
            password=loginkey)
github certbot / certbot / letsencrypt-apache / letsencrypt_apache / configurator.py View on Github external
def get_version(self):
        """Return version of Apache Server.

        Version is returned as tuple. (ie. 2.4.7 = (2, 4, 7))

        :returns: version
        :rtype: tuple

        :raises .PluginError: if unable to find Apache version

        """
        try:
            stdout, _ = le_util.run_script(
                constants.os_constant("version_cmd"))
        except errors.SubprocessError:
            raise errors.PluginError(
                "Unable to run %s -v" %
                constants.os_constant("version_cmd"))

        regex = re.compile(r"Apache/([0-9\.]*)", re.IGNORECASE)
        matches = regex.findall(stdout)

        if len(matches) != 1:
            raise errors.PluginError("Unable to find Apache version")

        return tuple([int(i) for i in matches[0].split(".")])
github Gandi / letsencrypt-gandi / letsencrypt_gandi / shs.py View on Github external
def prepare(self):
        """Prepare the plugin

        Get apikey and store in config
        """

        self.api_key = self._api_key_from_args() or\
            self._api_key_from_env() or\
            self._api_key_from_gandi_cli()

        if not self.api_key:
            raise errors.PluginError("Api key is missing, couldn't found from "
                                     "neither gandi.cli, environment"
                                     "(GANDI_API_KEY), nor --{0}"
                                     .format(self.option_name('api-key')))

        self.shs_name = self.conf('name')
        if not self.shs_name:
            raise errors.PluginError("--{0} is a required parameter,"
                                     "please provide a valid simple hosting "
                                     "name".format(self.option_name('name')))

        self.vhost = self.conf('vhost')
github certbot / certbot / letsencrypt / client.py View on Github external
:raises .errors.PluginError: If Enhancement is not supported, or if
            there is any other problem with the enhancement.


        """
        msg = ("We were unable to set up enhancement %s for your server, "
               "however, we successfully installed your certificate."
               % (enhancement))
        with error_handler.ErrorHandler(self._recovery_routine_with_msg, msg):
            for dom in domains:
                try:
                    self.installer.enhance(dom, enhancement, options)
                except errors.PluginEnhancementAlreadyPresent:
                    logger.warn("Enhancement %s was already set.",
                            enhancement)
                except errors.PluginError:
                    logger.warn("Unable to set enhancement %s for %s",
                            enhancement, dom)
                    raise

            self.installer.save("Add enhancement %s" % (enhancement))
github Gandi / letsencrypt-gandi / letsencrypt_gandi / shs.py View on Github external
def enhance(self, domain, enhancement, options=None):
        """Perform a configuration enhancement.

        :param str domain: domain for which to provide enhancement
        :param str enhancement: An enhancement as defined in
            :const:`~letsencrypt.constants.ENHANCEMENTS`
        :param options: Flexible options parameter for enhancement.
            Check documentation of
            :const:`~letsencrypt.constants.ENHANCEMENTS`
            for expected options for each enhancement.

        :raises .PluginError: If Enhancement is not supported, or if
            an error occurs during the enhancement.

        """
        raise errors.PluginError(
            "Unsupported enhancement: {0}".format(enhancement))