certbot/letsencrypt/client/plugins/apache/obj.py

92 lines
2.7 KiB
Python
Raw Normal View History

2014-12-16 02:52:18 -05:00
"""Module contains classes used by the Apache Configurator."""
2014-12-16 04:35:46 -05:00
2014-12-16 02:52:18 -05:00
class Addr(object):
2015-01-24 08:12:45 -05:00
r"""Represents an Apache VirtualHost address.
2014-12-19 18:49:29 -05:00
:param str addr: addr part of vhost address
2014-12-23 05:59:33 -05:00
:param str port: port number or \*, or ""
2014-12-19 18:49:29 -05:00
"""
def __init__(self, tup):
self.tup = tup
2014-12-16 04:35:46 -05:00
2014-12-16 02:52:18 -05:00
@classmethod
def fromstring(cls, str_addr):
"""Initialize Addr from string."""
tup = str_addr.partition(':')
return cls((tup[0], tup[2]))
def __str__(self):
2014-12-19 18:49:29 -05:00
if self.tup[1]:
return "%s:%s" % self.tup
return self.tup[0]
2014-12-16 02:52:18 -05:00
def __eq__(self, other):
2014-12-20 06:43:39 -05:00
if isinstance(other, self.__class__):
return self.tup == other.tup
2014-12-16 02:52:18 -05:00
return False
2014-12-16 04:35:46 -05:00
def __hash__(self):
return hash(self.tup)
2014-12-16 02:52:18 -05:00
def get_addr(self):
"""Return addr part of Addr object."""
return self.tup[0]
def get_port(self):
"""Return port."""
return self.tup[1]
def get_addr_obj(self, port):
"""Return new address object with same addr and new port."""
2014-12-16 04:35:46 -05:00
return self.__class__((self.tup[0], port))
2014-12-16 02:52:18 -05:00
2015-01-25 05:23:21 -05:00
class VirtualHost(object): # pylint: disable=too-few-public-methods
2014-12-16 02:52:18 -05:00
"""Represents an Apache Virtualhost.
:ivar str filep: file path of VH
:ivar str path: Augeas path to virtual host
:ivar set addrs: Virtual Host addresses (:class:`set` of :class:`Addr`)
:ivar set names: Server names/aliases of vhost
(:class:`list` of :class:`str`)
:ivar bool ssl: SSLEngine on in vhost
:ivar bool enabled: Virtual host is enabled
"""
2015-01-25 05:23:21 -05:00
def __init__(self, filep, path, addrs, ssl, enabled, names=None):
# pylint: disable=too-many-arguments
2014-12-16 02:52:18 -05:00
"""Initialize a VH."""
self.filep = filep
self.path = path
self.addrs = addrs
2014-12-19 18:49:29 -05:00
self.names = set() if names is None else set(names)
2014-12-16 02:52:18 -05:00
self.ssl = ssl
self.enabled = enabled
def add_name(self, name):
"""Add name to vhost."""
self.names.add(name)
def __str__(self):
2014-12-19 18:49:29 -05:00
addr_str = ", ".join(str(addr) for addr in self.addrs)
2014-12-16 02:52:18 -05:00
return ("file: %s\n"
"vh_path: %s\n"
"addrs: %s\n"
"names: %s\n"
"ssl: %s\n"
2014-12-19 18:49:29 -05:00
"enabled: %s" % (self.filep, self.path, addr_str,
2014-12-16 02:52:18 -05:00
self.names, self.ssl, self.enabled))
def __eq__(self, other):
if isinstance(other, self.__class__):
return (self.filep == other.filep and self.path == other.path and
self.addrs == other.addrs and
self.names == other.names and
self.ssl == other.ssl and self.enabled == other.enabled)
return False