How to use certbot-apache - 10 common examples

To help you get started, we’ve selected a few certbot-apache 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-apache / certbot_apache / obj.py View on Github external
def get_names(self):
        """Return a set of all names."""
        all_names = set()
        all_names.update(self.aliases)
        # Strip out any scheme:// and  field from servername
        if self.name is not None:
            all_names.add(VirtualHost.strip_name.findall(self.name)[0])

        return all_names
github certbot / certbot / certbot-apache / certbot_apache / obj.py View on Github external
def get_names(self):
        """Return a set of all names."""
        all_names = set()
        all_names.update(self.aliases)
        # Strip out any scheme:// and  field from servername
        if self.name is not None:
            all_names.add(VirtualHost.strip_name.findall(self.name)[0])

        return all_names
github certbot / certbot / certbot-apache / certbot_apache / _internal / obj.py View on Github external
def get_names(self):
        """Return a set of all names."""
        all_names = set()  # type: Set[str]
        all_names.update(self.aliases)
        # Strip out any scheme:// and  field from servername
        if self.name is not None:
            all_names.add(VirtualHost.strip_name.findall(self.name)[0])

        return all_names
github certbot / certbot / certbot-apache / certbot_apache / _internal / interfaces.py View on Github external
to ensure that the Reverter checkpoints are created properly.

        Note: this approach of keeping internal structure of the configuration
        within the ParserNode tree does not represent the file inclusion structure
        of actual configuration files that reside in the filesystem. To handle
        file writes properly, the file specific temporary trees should be extracted
        from the full ParserNode tree where necessary when writing to disk.

        :param str msg: Message describing the reason for the save.

        """


# Linter rule exclusion done because of https://github.com/PyCQA/pylint/issues/179
@six.add_metaclass(abc.ABCMeta)  # pylint: disable=abstract-method
class CommentNode(ParserNode):
    """
    CommentNode class is used for representation of comments within the parsed
    configuration structure. Because of the nature of comments, it is not able
    to have child nodes and hence it is always treated as a leaf node.

    CommentNode stores its contents in class variable 'comment' and does not
    have a specific name.

    CommentNode objects should have the following attributes in addition to
    the ones described in ParserNode:

    # Contains the contents of the comment without the directive notation
    # (typically # or /* ... */).
    comment: str

    """
github certbot / certbot / certbot-apache / certbot_apache / _internal / parser.py View on Github external
arg = os.path.normpath(os.path.join(self.root, arg))
        else:
            arg = os.path.normpath(arg)

        # Attempts to add a transform to the file if one does not already exist
        if os.path.isdir(arg):
            self.parse_file(os.path.join(arg, "*"))
        else:
            self.parse_file(arg)

        # Argument represents an fnmatch regular expression, convert it
        # Split up the path and convert each into an Augeas accepted regex
        # then reassemble
        split_arg = arg.split("/")
        for idx, split in enumerate(split_arg):
            if any(char in ApacheParser.fnmatch_chars for char in split):
                # Turn it into a augeas regex
                # TODO: Can this instead be an augeas glob instead of regex
                split_arg[idx] = ("* [label()=~regexp('%s')]" %
                                  self.fnmatch_to_re(split))
        # Reassemble the argument
        # Note: This also normalizes the argument /serverroot/ -> /serverroot
        arg = "/".join(split_arg)

        return get_aug_path(arg)
github certbot / certbot / certbot-apache / certbot_apache / _internal / augeasparser.py View on Github external
def _create_directivenode(self, path):
        """Helper function to create a DirectiveNode from Augeas path"""

        name = self.parser.get_arg(path)
        metadata = {"augeasparser": self.parser, "augeaspath": path}

        # Because of the dynamic nature, and the fact that we're not populating
        # the complete ParserNode tree, we use the search parent as ancestor
        return AugeasDirectiveNode(name=name,
                                   ancestor=assertions.PASS,
                                   filepath=apache_util.get_file_path(path),
                                   metadata=metadata)
github certbot / certbot / certbot-apache / certbot_apache / _internal / augeasparser.py View on Github external
if not parameters:
            raise errors.PluginError("Directive requires parameters and none were set.")

        insertpath, realpath, before = self._aug_resolve_child_position(
            "directive",
            position
        )
        new_metadata = {"augeasparser": self.parser, "augeaspath": realpath}

        # Create the new directive
        self.parser.aug.insert(insertpath, "directive", before)
        # Set the directive key
        self.parser.aug.set(realpath, name)

        new_dir = AugeasDirectiveNode(name=name,
                                      parameters=parameters,
                                      ancestor=assertions.PASS,
                                      filepath=apache_util.get_file_path(realpath),
                                      metadata=new_metadata)
        return new_dir
github certbot / certbot / certbot-apache / certbot_apache / _internal / augeasparser.py View on Github external
)
        elif position == 0:
            # Insert as the first child, before the current first one.
            insert_path = all_children[0]
            before = True
        else:
            insert_path = "{}/*[{}]".format(
                self.metadata["augeaspath"],
                position
            )

        return (insert_path, resulting_path, before)


interfaces.CommentNode.register(AugeasCommentNode)
interfaces.DirectiveNode.register(AugeasDirectiveNode)
interfaces.BlockNode.register(AugeasBlockNode)
github certbot / certbot / certbot-apache / certbot_apache / _internal / augeasparser.py View on Github external
def __init__(self, **kwargs):
        name, parameters, enabled, kwargs = util.directivenode_kwargs(kwargs)
        super(AugeasDirectiveNode, self).__init__(**kwargs)
        self.name = name
        self.enabled = enabled
        if parameters:
            self.set_parameters(parameters)
github certbot / certbot / certbot-apache / certbot_apache / _internal / augeasparser.py View on Github external
Fetches the parameters from Augeas tree, ensuring that the sequence always
        represents the current state

        :returns: Tuple of parameters for this DirectiveNode
        :rtype: tuple:
        """
        return tuple(self._aug_get_params(self.metadata["augeaspath"]))

    def _aug_get_params(self, path):
        """Helper function to get parameters for DirectiveNodes and BlockNodes"""

        arg_paths = self.parser.aug.match(path + "/arg")
        return [self.parser.get_arg(apath) for apath in arg_paths]


class AugeasBlockNode(AugeasDirectiveNode):
    """ Augeas implementation of BlockNode interface """

    def __init__(self, **kwargs):
        super(AugeasBlockNode, self).__init__(**kwargs)
        self.children = ()

    def __eq__(self, other):
        if isinstance(other, self.__class__):
            return (self.name == other.name and
                    self.filepath == other.filepath and
                    self.parameters == other.parameters and
                    self.children == other.children and
                    self.enabled == other.enabled and
                    self.dirty == other.dirty and
                    self.ancestor == other.ancestor and
                    self.metadata == other.metadata)