From 7b6081ac2918ca8a6c3400a3284129e1329c1cac Mon Sep 17 00:00:00 2001 From: James Kasten Date: Mon, 15 Dec 2014 23:52:18 -0800 Subject: [PATCH] Move out Apache specific Objects --- letsencrypt/client/apache_obj.py | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 letsencrypt/client/apache_obj.py diff --git a/letsencrypt/client/apache_obj.py b/letsencrypt/client/apache_obj.py new file mode 100644 index 000000000..a43dadb7d --- /dev/null +++ b/letsencrypt/client/apache_obj.py @@ -0,0 +1,90 @@ +"""Module contains classes used by the Apache Configurator.""" + +class Addr(object): + """Represents an Apache VirtualHost address.""" + def __init__(self, addr): + """:param tuple addr: tuple of strings (ip, port)""" + self.tup = addr + + @classmethod + def fromstring(cls, str_addr): + """Initialize Addr from string.""" + tup = str_addr.partition(':') + return cls((tup[0], tup[2])) + + def __str__(self): + return ':'.join(self.tup) + + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.tup == other.tup + return False + + def set_port(self, port): + """Set the port of the address. + + :param str port: new port + """ + self.tup = (self.tup[0], port) + + 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_ssl_addr_obj(self): + return cls((self.tup[0], "443")) + + def get_80_addr_obj(self): + return cls((self.tup[0], "80")) + + def get_addr_obj(self, port): + return cls((self.tup[0], port)) + +class VH(object): + """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 + + """ + + def __init__(self, filep, path, addrs, ssl, enabled, names=None): + """Initialize a VH.""" + self.filep = filep + self.path = path + self.addrs = addrs + self.names = set() if names is None else names + self.ssl = ssl + self.enabled = enabled + + def add_name(self, name): + """Add name to vhost.""" + self.names.add(name) + + def __str__(self): + return ("file: %s\n" + "vh_path: %s\n" + "addrs: %s\n" + "names: %s\n" + "ssl: %s\n" + "enabled: %s" % (self.filep, self.path, self.addrs, + 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