Fixing errors / reformating code
This commit is contained in:
parent
078cb31eb7
commit
3b2e9a43fd
11 changed files with 368 additions and 316 deletions
|
|
@ -1,12 +1,13 @@
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
|
|
||||||
class DockerLabelHandler:
|
class DockerLabelHandler:
|
||||||
def __init__(self, label):
|
def __init__(self, label):
|
||||||
|
self.__data = None
|
||||||
self.__label_base = label
|
self.__label_base = label
|
||||||
|
|
||||||
def get_lookup_label(self):
|
def get_lookup_label(self):
|
||||||
|
|
@ -18,13 +19,11 @@ class DockerLabelHandler:
|
||||||
|
|
||||||
return "{}.{}".format(self.__label_base, ".".join(key))
|
return "{}.{}".format(self.__label_base, ".".join(key))
|
||||||
|
|
||||||
|
|
||||||
def get(self, label, default_value=""):
|
def get(self, label, default_value=""):
|
||||||
if self.has_label(label):
|
if self.has_label(label):
|
||||||
return self.__data[label]
|
return self.__data[label]
|
||||||
return default_value
|
return default_value
|
||||||
|
|
||||||
|
|
||||||
def get_bool(self, label, default_value=False):
|
def get_bool(self, label, default_value=False):
|
||||||
if self.has_label(label):
|
if self.has_label(label):
|
||||||
return self.__data[label].lower() in ["true", "1", "yes"]
|
return self.__data[label].lower() in ["true", "1", "yes"]
|
||||||
|
|
@ -38,7 +37,6 @@ class DockerLabelHandler:
|
||||||
def set_data(self, data):
|
def set_data(self, data):
|
||||||
self.__data = data
|
self.__data = data
|
||||||
|
|
||||||
|
|
||||||
def has_label(self, label):
|
def has_label(self, label):
|
||||||
if label in self.__data:
|
if label in self.__data:
|
||||||
return True
|
return True
|
||||||
|
|
@ -70,7 +68,6 @@ class HaproxyConfigGenerator:
|
||||||
template = env.get_template('haproxy.cfg.j2')
|
template = env.get_template('haproxy.cfg.j2')
|
||||||
return template.render(data=self.mapping)
|
return template.render(data=self.mapping)
|
||||||
|
|
||||||
|
|
||||||
def parse(self, container_metadata):
|
def parse(self, container_metadata):
|
||||||
easymapping = dict()
|
easymapping = dict()
|
||||||
|
|
||||||
|
|
@ -163,8 +160,8 @@ class HaproxyConfigGenerator:
|
||||||
easymapping["443"]["hosts"][hostname]["certbot"] = False
|
easymapping["443"]["hosts"][hostname]["certbot"] = False
|
||||||
easymapping["443"]["hosts"][hostname]["redirect_ssl"] = False
|
easymapping["443"]["hosts"][hostname]["redirect_ssl"] = False
|
||||||
easymapping["443"]["ssl"] = True
|
easymapping["443"]["ssl"] = True
|
||||||
self.certbot_hosts.append(hostname) if certbot and hostname not in self.certbot_hosts else self.certbot_hosts
|
self.certbot_hosts.append(
|
||||||
|
hostname) if certbot and hostname not in self.certbot_hosts else self.certbot_hosts
|
||||||
|
|
||||||
# handle SSL
|
# handle SSL
|
||||||
ssl_label = self.label.create([definition, "sslcert"])
|
ssl_label = self.label.create([definition, "sslcert"])
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,41 @@
|
||||||
from datetime import datetime
|
|
||||||
from multiprocessing import Process, Lock
|
|
||||||
import subprocess
|
|
||||||
import shlex
|
|
||||||
import time
|
|
||||||
import os
|
import os
|
||||||
import re
|
import shlex
|
||||||
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
from multiprocessing import Process
|
||||||
|
|
||||||
from OpenSSL import crypto
|
from OpenSSL import crypto
|
||||||
|
|
||||||
|
|
||||||
|
class ContainerEnv:
|
||||||
|
@staticmethod
|
||||||
|
def read():
|
||||||
|
env_vars = {
|
||||||
|
"customerrors": True if os.getenv("HAPROXY_CUSTOMERRORS") == "true" else False,
|
||||||
|
"ssl_mode": os.getenv("EASYHAPROXY_SSL_MODE").lower() if os.getenv("EASYHAPROXY_SSL_MODE") else 'default'
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.getenv("HAPROXY_PASSWORD"):
|
||||||
|
env_vars["stats"] = {
|
||||||
|
"username": os.getenv("HAPROXY_USERNAME") if os.getenv("HAPROXY_USERNAME") else "admin",
|
||||||
|
"password": os.getenv("HAPROXY_PASSWORD"),
|
||||||
|
"port": os.getenv("HAPROXY_STATS_PORT") if os.getenv("HAPROXY_STATS_PORT") else "1936",
|
||||||
|
}
|
||||||
|
|
||||||
|
env_vars["lookup_label"] = os.getenv("EASYHAPROXY_LABEL_PREFIX") if os.getenv(
|
||||||
|
"EASYHAPROXY_LABEL_PREFIX") else "easyhaproxy"
|
||||||
|
|
||||||
|
env_vars["certbot"] = {
|
||||||
|
"email": os.getenv("EASYHAPROXY_CERTBOT_EMAIL", ""),
|
||||||
|
"server": os.getenv("EASYHAPROXY_CERTBOT_SERVER", False),
|
||||||
|
"eab_kid": os.getenv("EASYHAPROXY_CERTBOT_EAB_KID", ""),
|
||||||
|
"eab_hmac_key": os.getenv("EASYHAPROXY_CERTBOT_EAB_HMAC_KEY", ""),
|
||||||
|
}
|
||||||
|
|
||||||
|
return env_vars
|
||||||
|
|
||||||
|
|
||||||
class Functions:
|
class Functions:
|
||||||
HAPROXY_LOG = "HAPROXY"
|
HAPROXY_LOG = "HAPROXY"
|
||||||
EASYHAPROXY_LOG = "EASYHAPROXY"
|
EASYHAPROXY_LOG = "EASYHAPROXY"
|
||||||
|
|
@ -119,8 +146,8 @@ class DaemonizeHAProxy:
|
||||||
else:
|
else:
|
||||||
pid = "".join(Functions().run_bash(Functions.HAPROXY_LOG, "cat /run/haproxy.pid", log_output=False))
|
pid = "".join(Functions().run_bash(Functions.HAPROXY_LOG, "cat /run/haproxy.pid", log_output=False))
|
||||||
self.__prepare(
|
self.__prepare(
|
||||||
"/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -x /var/run/haproxy.sock -sf %s" % (
|
"/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -x /var/run/haproxy.sock -sf %s" %
|
||||||
pid))
|
pid)
|
||||||
|
|
||||||
if self.process is None:
|
if self.process is None:
|
||||||
return
|
return
|
||||||
|
|
@ -151,8 +178,8 @@ class DaemonizeHAProxy:
|
||||||
for line in iter(self.process.stdout.readline, b''):
|
for line in iter(self.process.stdout.readline, b''):
|
||||||
Functions.log(source, Functions.INFO, line)
|
Functions.log(source, Functions.INFO, line)
|
||||||
|
|
||||||
returncode = self.process.wait()
|
return_code = self.process.wait()
|
||||||
Functions.log(source, Functions.DEBUG, "Return code %s" % (returncode))
|
Functions.log(source, Functions.DEBUG, "Return code %s" % return_code)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Functions.log(source, Functions.ERROR, "%s" % e)
|
Functions.log(source, Functions.ERROR, "%s" % e)
|
||||||
|
|
@ -188,7 +215,8 @@ class Certbot:
|
||||||
self.eab_kid = self.set_eab_kid(env["certbot"]["eab_kid"])
|
self.eab_kid = self.set_eab_kid(env["certbot"]["eab_kid"])
|
||||||
self.eab_hmac_key = self.set_eab_hmac_key(env["certbot"]["eab_hmac_key"])
|
self.eab_hmac_key = self.set_eab_hmac_key(env["certbot"]["eab_hmac_key"])
|
||||||
|
|
||||||
def set_acme_server(self, acme_server):
|
@staticmethod
|
||||||
|
def set_acme_server(acme_server):
|
||||||
if acme_server.lower() == "staging":
|
if acme_server.lower() == "staging":
|
||||||
return "--staging"
|
return "--staging"
|
||||||
elif acme_server.lower().startswith("http"):
|
elif acme_server.lower().startswith("http"):
|
||||||
|
|
@ -196,13 +224,15 @@ class Certbot:
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def set_eab_kid(self, eab_kid):
|
@staticmethod
|
||||||
|
def set_eab_kid(eab_kid):
|
||||||
if eab_kid != "":
|
if eab_kid != "":
|
||||||
return "--eab-kid \"%s\"" % eab_kid
|
return "--eab-kid \"%s\"" % eab_kid
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def set_eab_hmac_key(self, eab_hmac_key):
|
@staticmethod
|
||||||
|
def set_eab_hmac_key(eab_hmac_key):
|
||||||
if eab_hmac_key != "":
|
if eab_hmac_key != "":
|
||||||
return "--eab-hmac-key \"%s\"" % eab_hmac_key
|
return "--eab-hmac-key \"%s\"" % eab_hmac_key
|
||||||
else:
|
else:
|
||||||
|
|
@ -274,7 +304,8 @@ class Certbot:
|
||||||
Functions.log(Functions.CERTBOT_LOG, Functions.ERROR, "%s" % e)
|
Functions.log(Functions.CERTBOT_LOG, Functions.ERROR, "%s" % e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def merge_certificate(self, cert, key, filename):
|
@staticmethod
|
||||||
|
def merge_certificate(cert, key, filename):
|
||||||
Functions.save(filename, cert + key)
|
Functions.save(filename, cert + key)
|
||||||
|
|
||||||
def find_live_certificates(self):
|
def find_live_certificates(self):
|
||||||
|
|
|
||||||
24
src/main.py
24
src/main.py
|
|
@ -1,7 +1,10 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from deepdiff import DeepDiff
|
||||||
|
|
||||||
from functions import Functions, DaemonizeHAProxy, Certbot, Consts
|
from functions import Functions, DaemonizeHAProxy, Certbot, Consts
|
||||||
from processor import ProcessorInterface
|
from processor import ProcessorInterface
|
||||||
import os
|
|
||||||
from deepdiff import DeepDiff
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
processor_obj = ProcessorInterface.factory(os.getenv("EASYHAPROXY_DISCOVER"))
|
processor_obj = ProcessorInterface.factory(os.getenv("EASYHAPROXY_DISCOVER"))
|
||||||
|
|
@ -14,7 +17,8 @@ def start():
|
||||||
processor_obj.save_config(Consts.haproxy_config)
|
processor_obj.save_config(Consts.haproxy_config)
|
||||||
processor_obj.save_certs(Consts.certs_haproxy)
|
processor_obj.save_certs(Consts.certs_haproxy)
|
||||||
certbot_certs_found = processor_obj.get_certbot_hosts()
|
certbot_certs_found = processor_obj.get_certbot_hosts()
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to run after save_config
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG,
|
||||||
|
'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to run after save_config
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.TRACE, 'Object Found: %s' % (processor_obj.get_parsed_object()))
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.TRACE, 'Object Found: %s' % (processor_obj.get_parsed_object()))
|
||||||
|
|
||||||
old_haproxy = None
|
old_haproxy = None
|
||||||
|
|
@ -31,27 +35,28 @@ def start():
|
||||||
try:
|
try:
|
||||||
old_parsed = processor_obj.get_parsed_object()
|
old_parsed = processor_obj.get_parsed_object()
|
||||||
processor_obj.refresh()
|
processor_obj.refresh()
|
||||||
if certbot.check_certificates(certbot_certs_found) or DeepDiff(old_parsed, processor_obj.get_parsed_object()) != {} or not haproxy.is_alive():
|
if certbot.check_certificates(certbot_certs_found) or DeepDiff(old_parsed,
|
||||||
|
processor_obj.get_parsed_object()) != {} or not haproxy.is_alive():
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'New configuration found. Reloading...')
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'New configuration found. Reloading...')
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.TRACE, 'Object Found: %s' % (processor_obj.get_parsed_object()))
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.TRACE,
|
||||||
|
'Object Found: %s' % (processor_obj.get_parsed_object()))
|
||||||
processor_obj.save_config(Consts.haproxy_config)
|
processor_obj.save_config(Consts.haproxy_config)
|
||||||
processor_obj.save_certs(Consts.certs_haproxy)
|
processor_obj.save_certs(Consts.certs_haproxy)
|
||||||
certbot_certs_found = processor_obj.get_certbot_hosts()
|
certbot_certs_found = processor_obj.get_certbot_hosts()
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to after save_config
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG,
|
||||||
|
'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to after save_config
|
||||||
old_haproxy = haproxy
|
old_haproxy = haproxy
|
||||||
haproxy = DaemonizeHAProxy()
|
haproxy = DaemonizeHAProxy()
|
||||||
haproxy.haproxy("reload")
|
haproxy.haproxy("reload")
|
||||||
old_haproxy.terminate()
|
old_haproxy.terminate()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.FATAL, "Err: %s" % (e))
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.FATAL, "Err: %s" % e)
|
||||||
|
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'Heartbeat')
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'Heartbeat')
|
||||||
haproxy.sleep()
|
haproxy.sleep()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
Functions.run_bash(Functions.INIT_LOG, '/usr/sbin/haproxy -v')
|
Functions.run_bash(Functions.INIT_LOG, '/usr/sbin/haproxy -v')
|
||||||
|
|
||||||
|
|
@ -69,5 +74,6 @@ def main():
|
||||||
|
|
||||||
start()
|
start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,26 @@
|
||||||
from easymapping import HaproxyConfigGenerator
|
|
||||||
from functions import Functions, Consts
|
|
||||||
import yaml
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import base64
|
import base64
|
||||||
import docker
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
import docker
|
||||||
|
import yaml
|
||||||
from kubernetes import client, config
|
from kubernetes import client, config
|
||||||
from kubernetes.client.rest import ApiException
|
from kubernetes.client.rest import ApiException
|
||||||
|
|
||||||
class ContainerEnv:
|
from easymapping import HaproxyConfigGenerator
|
||||||
@staticmethod
|
from functions import Functions, Consts, ContainerEnv
|
||||||
def read():
|
|
||||||
env_vars = {
|
|
||||||
"customerrors": True if os.getenv("HAPROXY_CUSTOMERRORS") == "true" else False,
|
|
||||||
"ssl_mode": os.getenv("EASYHAPROXY_SSL_MODE").lower() if os.getenv("EASYHAPROXY_SSL_MODE") else 'default'
|
|
||||||
}
|
|
||||||
|
|
||||||
if os.getenv("HAPROXY_PASSWORD"):
|
|
||||||
env_vars["stats"] = {
|
|
||||||
"username": os.getenv("HAPROXY_USERNAME") if os.getenv("HAPROXY_USERNAME") else "admin",
|
|
||||||
"password": os.getenv("HAPROXY_PASSWORD"),
|
|
||||||
"port": os.getenv("HAPROXY_STATS_PORT") if os.getenv("HAPROXY_STATS_PORT") else "1936",
|
|
||||||
}
|
|
||||||
|
|
||||||
env_vars["lookup_label"] = os.getenv("EASYHAPROXY_LABEL_PREFIX") if os.getenv("EASYHAPROXY_LABEL_PREFIX") else "easyhaproxy"
|
|
||||||
|
|
||||||
env_vars["certbot"] = {
|
|
||||||
"email": os.getenv("EASYHAPROXY_CERTBOT_EMAIL", ""),
|
|
||||||
"server": os.getenv("EASYHAPROXY_CERTBOT_SERVER", False),
|
|
||||||
"eab_kid": os.getenv("EASYHAPROXY_CERTBOT_EAB_KID", ""),
|
|
||||||
"eab_hmac_key": os.getenv("EASYHAPROXY_CERTBOT_EAB_HMAC_KEY", ""),
|
|
||||||
}
|
|
||||||
|
|
||||||
return env_vars
|
|
||||||
|
|
||||||
|
|
||||||
class ProcessorInterface:
|
class ProcessorInterface:
|
||||||
static_file = Consts.easyhaproxy_config
|
static_file = Consts.easyhaproxy_config
|
||||||
|
|
||||||
def __init__(self, filename=None):
|
def __init__(self, filename=None):
|
||||||
|
self.certbot_hosts = None
|
||||||
|
self.parsed_object = None
|
||||||
|
self.cfg = None
|
||||||
|
self.hosts = None
|
||||||
|
self.cfg = None
|
||||||
|
self.certbot_hosts = None
|
||||||
|
self.hosts = None
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
|
|
@ -55,7 +35,8 @@ class ProcessorInterface:
|
||||||
elif mode == "kubernetes":
|
elif mode == "kubernetes":
|
||||||
return Kubernetes()
|
return Kubernetes()
|
||||||
else:
|
else:
|
||||||
Functions.log("EASYHAPROXY", Functions.FATAL, "Expected mode to be 'static', 'docker', 'swarm' or 'kubernetes'. I got '%s'" % (mode))
|
Functions.log("EASYHAPROXY", Functions.FATAL,
|
||||||
|
"Expected mode to be 'static', 'docker', 'swarm' or 'kubernetes'. I got '%s'" % mode)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
|
|
@ -103,6 +84,13 @@ class ProcessorInterface:
|
||||||
|
|
||||||
|
|
||||||
class Static(ProcessorInterface):
|
class Static(ProcessorInterface):
|
||||||
|
def __init__(self, filename=None):
|
||||||
|
self.parsed_object = None
|
||||||
|
self.static_content = None
|
||||||
|
self.static_content = None
|
||||||
|
self.cfg = None
|
||||||
|
super().__init__(filename)
|
||||||
|
|
||||||
def inspect_network(self):
|
def inspect_network(self):
|
||||||
self.parsed_object = {}
|
self.parsed_object = {}
|
||||||
self.static_content = None
|
self.static_content = None
|
||||||
|
|
@ -112,11 +100,11 @@ class Static(ProcessorInterface):
|
||||||
|
|
||||||
def get_hosts(self):
|
def get_hosts(self):
|
||||||
hosts = []
|
hosts = []
|
||||||
for object in self.get_parsed_object():
|
for obj in self.get_parsed_object():
|
||||||
if "hosts" not in object:
|
if "hosts" not in obj:
|
||||||
continue
|
continue
|
||||||
for host in object["hosts"].keys():
|
for host in obj["hosts"].keys():
|
||||||
hosts.append("%s:%s" % (host, object["port"]))
|
hosts.append("%s:%s" % (host, obj["port"]))
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
|
|
@ -126,17 +114,20 @@ class Static(ProcessorInterface):
|
||||||
|
|
||||||
class Docker(ProcessorInterface):
|
class Docker(ProcessorInterface):
|
||||||
def __init__(self, filename=None):
|
def __init__(self, filename=None):
|
||||||
|
self.parsed_object = None
|
||||||
self.client = docker.from_env()
|
self.client = docker.from_env()
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def inspect_network(self):
|
def inspect_network(self):
|
||||||
try:
|
try:
|
||||||
ha_proxy_network_name = next(iter(self.client.containers.get(socket.gethostname()).attrs["NetworkSettings"]["Networks"]))
|
ha_proxy_network_name = next(
|
||||||
|
iter(self.client.containers.get(socket.gethostname()).attrs["NetworkSettings"]["Networks"]))
|
||||||
except:
|
except:
|
||||||
# HAProxy is not running in a container, get first container network
|
# HAProxy is not running in a container, get first container network
|
||||||
if len(self.client.containers.list()) == 0:
|
if len(self.client.containers.list()) == 0:
|
||||||
return
|
return
|
||||||
ha_proxy_network_name = next(iter(self.client.containers.get(self.client.containers.list()[0].name).attrs["NetworkSettings"]["Networks"]))
|
ha_proxy_network_name = next(iter(
|
||||||
|
self.client.containers.get(self.client.containers.list()[0].name).attrs["NetworkSettings"]["Networks"]))
|
||||||
|
|
||||||
ha_proxy_network = self.client.networks.get(ha_proxy_network_name)
|
ha_proxy_network = self.client.networks.get(ha_proxy_network_name)
|
||||||
|
|
||||||
|
|
@ -153,16 +144,21 @@ class Docker(ProcessorInterface):
|
||||||
|
|
||||||
class Swarm(ProcessorInterface):
|
class Swarm(ProcessorInterface):
|
||||||
def __init__(self, filename=None):
|
def __init__(self, filename=None):
|
||||||
|
self.parsed_object = None
|
||||||
self.client = docker.from_env()
|
self.client = docker.from_env()
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def inspect_network(self):
|
def inspect_network(self):
|
||||||
ha_proxy_service_name = self.client.containers.get(socket.gethostname()).name.split('.')[0]
|
ha_proxy_service_name = self.client.containers.get(socket.gethostname()).name.split('.')[0]
|
||||||
|
ha_proxy_network_id = None
|
||||||
for endpoint in self.client.services.get(ha_proxy_service_name).attrs['Endpoint']["VirtualIPs"]:
|
for endpoint in self.client.services.get(ha_proxy_service_name).attrs['Endpoint']["VirtualIPs"]:
|
||||||
ha_proxy_network_id = endpoint["NetworkID"]
|
ha_proxy_network_id = endpoint["NetworkID"]
|
||||||
if self.client.networks.get(ha_proxy_network_id).name != 'ingress':
|
if self.client.networks.get(ha_proxy_network_id).name != 'ingress':
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if ha_proxy_network_id is None:
|
||||||
|
raise "Could not find ingress network"
|
||||||
|
|
||||||
self.parsed_object = {}
|
self.parsed_object = {}
|
||||||
for service in self.client.services.list():
|
for service in self.client.services.list():
|
||||||
ip_address = None
|
ip_address = None
|
||||||
|
|
@ -183,6 +179,7 @@ class Swarm(ProcessorInterface):
|
||||||
|
|
||||||
class Kubernetes(ProcessorInterface):
|
class Kubernetes(ProcessorInterface):
|
||||||
def __init__(self, filename=None):
|
def __init__(self, filename=None):
|
||||||
|
self.parsed_object = None
|
||||||
config.load_incluster_config()
|
config.load_incluster_config()
|
||||||
config.verify_ssl = False
|
config.verify_ssl = False
|
||||||
self.api_instance = client.CoreV1Api()
|
self.api_instance = client.CoreV1Api()
|
||||||
|
|
@ -190,7 +187,8 @@ class Kubernetes(ProcessorInterface):
|
||||||
self.cert_cache = {}
|
self.cert_cache = {}
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def _check_annotation(self, annotations, key):
|
@staticmethod
|
||||||
|
def _check_annotation(annotations, key):
|
||||||
if key not in annotations:
|
if key not in annotations:
|
||||||
return None
|
return None
|
||||||
return annotations[key]
|
return annotations[key]
|
||||||
|
|
@ -216,10 +214,8 @@ class Kubernetes(ProcessorInterface):
|
||||||
if listen_port is None:
|
if listen_port is None:
|
||||||
listen_port = 80
|
listen_port = 80
|
||||||
|
|
||||||
data = {}
|
data = {"creation_timestamp": ingress.metadata.creation_timestamp.strftime("%x %X"),
|
||||||
data["creation_timestamp"] = ingress.metadata.creation_timestamp.strftime("%x %X")
|
"resource_version": ingress.metadata.resource_version, "namespace": ingress.metadata.namespace}
|
||||||
data["resource_version"] = ingress.metadata.resource_version
|
|
||||||
data["namespace"] = ingress.metadata.namespace
|
|
||||||
|
|
||||||
ingress_name = ingress.metadata.namespace
|
ingress_name = ingress.metadata.namespace
|
||||||
|
|
||||||
|
|
@ -234,32 +230,35 @@ class Kubernetes(ProcessorInterface):
|
||||||
self.cert_cache[tls.secret_name] = secret.data
|
self.cert_cache[tls.secret_name] = secret.data
|
||||||
Functions.save(
|
Functions.save(
|
||||||
"{0}/{1}.pem".format(Consts.certs_haproxy, tls.secret_name),
|
"{0}/{1}.pem".format(Consts.certs_haproxy, tls.secret_name),
|
||||||
base64.b64decode(secret.data["tls.crt"]).decode('ascii') + "\n" + base64.b64decode(secret.data["tls.key"]).decode('ascii')
|
base64.b64decode(secret.data["tls.crt"]).decode('ascii') + "\n" + base64.b64decode(
|
||||||
|
secret.data["tls.key"]).decode('ascii')
|
||||||
)
|
)
|
||||||
|
|
||||||
ssl_hosts.extend(tls.hosts)
|
ssl_hosts.extend(tls.hosts)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Functions.log("EASYHAPROXY", Functions.WARN, "Ingress %s - Get secret failed: '%s'" % (ingress_name, e))
|
Functions.log("EASYHAPROXY", Functions.WARN,
|
||||||
|
"Ingress %s - Get secret failed: '%s'" % (ingress_name, e))
|
||||||
|
|
||||||
Functions.log("EASYHAPROXY", Functions.TRACE, "Ingress %s - SSL Hosts found '%s'" % (ingress_name, ssl_hosts))
|
Functions.log("EASYHAPROXY", Functions.TRACE,
|
||||||
|
"Ingress %s - SSL Hosts found '%s'" % (ingress_name, ssl_hosts))
|
||||||
|
|
||||||
for rule in ingress.spec.rules:
|
for rule in ingress.spec.rules:
|
||||||
rule_data = {}
|
rule_data = {}
|
||||||
port_number = rule.http.paths[0].backend.service.port.number
|
port_number = rule.http.paths[0].backend.service.port.number
|
||||||
definition = "easyhaproxy.%s_%s" % (rule.host.replace(".", "-"), port_number)
|
definition = "easyhaproxy.%s_%s" % (rule.host.replace(".", "-"), port_number)
|
||||||
rule_data["%s.host" % (definition)] = rule.host
|
rule_data["%s.host" % definition] = rule.host
|
||||||
rule_data["%s.port" % (definition)] = listen_port
|
rule_data["%s.port" % definition] = listen_port
|
||||||
rule_data["%s.localport" % (definition)] = port_number
|
rule_data["%s.localport" % definition] = port_number
|
||||||
if rule.host in ssl_hosts:
|
if rule.host in ssl_hosts:
|
||||||
rule_data["%s.clone_to_ssl" % (definition)] = 'true'
|
rule_data["%s.clone_to_ssl" % definition] = 'true'
|
||||||
if redirect_ssl is not None:
|
if redirect_ssl is not None:
|
||||||
rule_data["%s.redirect_ssl" % (definition)] = redirect_ssl
|
rule_data["%s.redirect_ssl" % definition] = redirect_ssl
|
||||||
if certbot is not None:
|
if certbot is not None:
|
||||||
rule_data["%s.certbot" % (definition)] = certbot
|
rule_data["%s.certbot" % definition] = certbot
|
||||||
if redirect is not None:
|
if redirect is not None:
|
||||||
rule_data["%s.redirect" % (definition)] = redirect
|
rule_data["%s.redirect" % definition] = redirect
|
||||||
if mode is not None:
|
if mode is not None:
|
||||||
rule_data["%s.mode" % (definition)] = mode
|
rule_data["%s.mode" % definition] = mode
|
||||||
|
|
||||||
service_name = rule.http.paths[0].backend.service.name
|
service_name = rule.http.paths[0].backend.service.name
|
||||||
try:
|
try:
|
||||||
|
|
@ -267,13 +266,10 @@ class Kubernetes(ProcessorInterface):
|
||||||
cluster_ip = api_response.spec.cluster_ip
|
cluster_ip = api_response.spec.cluster_ip
|
||||||
except ApiException as e:
|
except ApiException as e:
|
||||||
cluster_ip = None
|
cluster_ip = None
|
||||||
Functions.log("EASYHAPROXY", Functions.WARN, "Ingress %s - Service %s - Failed: '%s'" % (ingress_name, service_name, e))
|
Functions.log("EASYHAPROXY", Functions.WARN,
|
||||||
|
"Ingress %s - Service %s - Failed: '%s'" % (ingress_name, service_name, e))
|
||||||
|
|
||||||
if cluster_ip is not None:
|
if cluster_ip is not None:
|
||||||
if cluster_ip not in self.parsed_object.keys():
|
if cluster_ip not in self.parsed_object.keys():
|
||||||
self.parsed_object[cluster_ip] = data
|
self.parsed_object[cluster_ip] = data
|
||||||
self.parsed_object[cluster_ip].update(rule_data)
|
self.parsed_object[cluster_ip].update(rule_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
||||||
|
|
||||||
import easymapping
|
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import pytest
|
|
||||||
import os
|
import os
|
||||||
from processor import ContainerEnv
|
|
||||||
|
from functions import ContainerEnv
|
||||||
|
|
||||||
|
|
||||||
def test_container_env_empty():
|
def test_container_env_empty():
|
||||||
assert {
|
assert {
|
||||||
|
|
@ -15,6 +16,7 @@ def test_container_env_empty():
|
||||||
|
|
||||||
# os.environ['CERTBOT_LOG_LEVEL'] = 'warn'
|
# os.environ['CERTBOT_LOG_LEVEL'] = 'warn'
|
||||||
|
|
||||||
|
|
||||||
def test_container_env_customerrors():
|
def test_container_env_customerrors():
|
||||||
os.environ['HAPROXY_CUSTOMERRORS'] = 'true'
|
os.environ['HAPROXY_CUSTOMERRORS'] = 'true'
|
||||||
try:
|
try:
|
||||||
|
|
@ -30,6 +32,7 @@ def test_container_env_customerrors():
|
||||||
finally:
|
finally:
|
||||||
os.environ['HAPROXY_CUSTOMERRORS'] = ''
|
os.environ['HAPROXY_CUSTOMERRORS'] = ''
|
||||||
|
|
||||||
|
|
||||||
def test_container_env_sslmode():
|
def test_container_env_sslmode():
|
||||||
os.environ['EASYHAPROXY_SSL_MODE'] = 'STRICT'
|
os.environ['EASYHAPROXY_SSL_MODE'] = 'STRICT'
|
||||||
try:
|
try:
|
||||||
|
|
@ -45,6 +48,7 @@ def test_container_env_sslmode():
|
||||||
finally:
|
finally:
|
||||||
os.environ['EASYHAPROXY_SSL_MODE'] = ''
|
os.environ['EASYHAPROXY_SSL_MODE'] = ''
|
||||||
|
|
||||||
|
|
||||||
def test_container_env_stats():
|
def test_container_env_stats():
|
||||||
os.environ['HAPROXY_USERNAME'] = 'abc'
|
os.environ['HAPROXY_USERNAME'] = 'abc'
|
||||||
os.environ['HAPROXY_STATS_PORT'] = '2101'
|
os.environ['HAPROXY_STATS_PORT'] = '2101'
|
||||||
|
|
@ -62,6 +66,7 @@ def test_container_env_stats():
|
||||||
os.environ['HAPROXY_USERNAME'] = ''
|
os.environ['HAPROXY_USERNAME'] = ''
|
||||||
os.environ['HAPROXY_STATS_PORT'] = ''
|
os.environ['HAPROXY_STATS_PORT'] = ''
|
||||||
|
|
||||||
|
|
||||||
def test_container_env_stats_password():
|
def test_container_env_stats_password():
|
||||||
os.environ['HAPROXY_PASSWORD'] = 'xyz'
|
os.environ['HAPROXY_PASSWORD'] = 'xyz'
|
||||||
try:
|
try:
|
||||||
|
|
@ -84,7 +89,7 @@ def test_container_env_stats_password():
|
||||||
os.environ['HAPROXY_PASSWORD'] = ''
|
os.environ['HAPROXY_PASSWORD'] = ''
|
||||||
|
|
||||||
|
|
||||||
def test_container_env_stats_password():
|
def test_container_env_stats_password_2():
|
||||||
os.environ['HAPROXY_USERNAME'] = 'abc'
|
os.environ['HAPROXY_USERNAME'] = 'abc'
|
||||||
os.environ['HAPROXY_STATS_PORT'] = '2101'
|
os.environ['HAPROXY_STATS_PORT'] = '2101'
|
||||||
os.environ['HAPROXY_PASSWORD'] = 'xyz'
|
os.environ['HAPROXY_PASSWORD'] = 'xyz'
|
||||||
|
|
@ -126,6 +131,7 @@ def test_container_env_certbot_email():
|
||||||
finally:
|
finally:
|
||||||
os.environ['EASYHAPROXY_CERTBOT_EMAIL'] = ''
|
os.environ['EASYHAPROXY_CERTBOT_EMAIL'] = ''
|
||||||
|
|
||||||
|
|
||||||
def test_container_env_certbot_full():
|
def test_container_env_certbot_full():
|
||||||
os.environ['EASYHAPROXY_CERTBOT_EMAIL'] = 'acme@example.org'
|
os.environ['EASYHAPROXY_CERTBOT_EMAIL'] = 'acme@example.org'
|
||||||
os.environ['EASYHAPROXY_CERTBOT_SERVER'] = 'schema://url/a'
|
os.environ['EASYHAPROXY_CERTBOT_SERVER'] = 'schema://url/a'
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import pytest
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
|
import pytest
|
||||||
|
|
||||||
from functions import Functions
|
from functions import Functions
|
||||||
from processor import ProcessorInterface
|
from processor import ProcessorInterface
|
||||||
from processor import Docker
|
|
||||||
|
|
||||||
|
|
||||||
def _get_hydrated_object(parsed_objects, lookup_key):
|
def _get_hydrated_object(parsed_objects, lookup_key):
|
||||||
|
|
@ -17,7 +18,6 @@ def _get_hydrated_object(parsed_objects, lookup_key):
|
||||||
|
|
||||||
|
|
||||||
def _get_ip_host(parsed_objects, lookup_key):
|
def _get_ip_host(parsed_objects, lookup_key):
|
||||||
hydrated_object = {}
|
|
||||||
for key in parsed_objects:
|
for key in parsed_objects:
|
||||||
for keys in parsed_objects[key]:
|
for keys in parsed_objects[key]:
|
||||||
if lookup_key in keys:
|
if lookup_key in keys:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import json
|
|
||||||
import pytest
|
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from functions import Functions
|
from functions import Functions
|
||||||
|
|
||||||
|
|
||||||
def test_functions_check_local_level():
|
def test_functions_check_local_level():
|
||||||
assert Functions.skip_log('CERTBOT', Functions.INFO) == False
|
assert Functions.skip_log('CERTBOT', Functions.INFO) == False
|
||||||
assert Functions.skip_log('HAPOROXY', Functions.INFO) == False
|
assert Functions.skip_log('HAPOROXY', Functions.INFO) == False
|
||||||
|
|
@ -23,6 +23,7 @@ def test_functions_check_local_level():
|
||||||
assert Functions.skip_log('EASYHAPROXY', Functions.INFO) == True
|
assert Functions.skip_log('EASYHAPROXY', Functions.INFO) == True
|
||||||
os.environ['EASYHAPROXY_LOG_LEVEL'] = ''
|
os.environ['EASYHAPROXY_LOG_LEVEL'] = ''
|
||||||
|
|
||||||
|
|
||||||
def test_function_load_and_save():
|
def test_function_load_and_save():
|
||||||
filename = '/tmp/x.txt'
|
filename = '/tmp/x.txt'
|
||||||
try:
|
try:
|
||||||
|
|
@ -34,6 +35,7 @@ def test_function_load_and_save():
|
||||||
finally:
|
finally:
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
|
|
||||||
|
|
||||||
def test_functions_check_log_sanity():
|
def test_functions_check_log_sanity():
|
||||||
print()
|
print()
|
||||||
Functions.log(Functions.EASYHAPROXY_LOG, Functions.INFO, "Test 1")
|
Functions.log(Functions.EASYHAPROXY_LOG, Functions.INFO, "Test 1")
|
||||||
|
|
@ -58,37 +60,44 @@ def test_functions_check_log_sanity():
|
||||||
os.environ['EASYHAPROXY_LOG_LEVEL'] = ''
|
os.environ['EASYHAPROXY_LOG_LEVEL'] = ''
|
||||||
Functions.debug_log = None
|
Functions.debug_log = None
|
||||||
|
|
||||||
|
|
||||||
def test_functions_run_bash_log_output():
|
def test_functions_run_bash_log_output():
|
||||||
print()
|
print()
|
||||||
Functions.debug_log = []
|
Functions.debug_log = []
|
||||||
try:
|
try:
|
||||||
result = Functions.run_bash(Functions.EASYHAPROXY_LOG, "echo 'test run 1'", log_output=True, return_result=False)
|
result = Functions.run_bash(Functions.EASYHAPROXY_LOG, "echo 'test run 1'", log_output=True,
|
||||||
|
return_result=False)
|
||||||
assert result == []
|
assert result == []
|
||||||
assert len(Functions.debug_log) == 1
|
assert len(Functions.debug_log) == 1
|
||||||
assert re.match("\[EASYHAPROXY\] .* \[INFO\]: test run 1", Functions.debug_log[0])
|
assert re.match("\[EASYHAPROXY\] .* \[INFO\]: test run 1", Functions.debug_log[0])
|
||||||
finally:
|
finally:
|
||||||
Functions.debug_log = None
|
Functions.debug_log = None
|
||||||
|
|
||||||
|
|
||||||
def test_functions_run_bash_no_log_output():
|
def test_functions_run_bash_no_log_output():
|
||||||
print()
|
print()
|
||||||
Functions.debug_log = []
|
Functions.debug_log = []
|
||||||
try:
|
try:
|
||||||
result = Functions.run_bash(Functions.EASYHAPROXY_LOG, "echo 'test run 2'", log_output=False, return_result=False)
|
result = Functions.run_bash(Functions.EASYHAPROXY_LOG, "echo 'test run 2'", log_output=False,
|
||||||
|
return_result=False)
|
||||||
assert result == []
|
assert result == []
|
||||||
assert len(Functions.debug_log) == 0
|
assert len(Functions.debug_log) == 0
|
||||||
finally:
|
finally:
|
||||||
Functions.debug_log = None
|
Functions.debug_log = None
|
||||||
|
|
||||||
|
|
||||||
def test_functions_run_bash_return():
|
def test_functions_run_bash_return():
|
||||||
print()
|
print()
|
||||||
Functions.debug_log = []
|
Functions.debug_log = []
|
||||||
try:
|
try:
|
||||||
result = Functions.run_bash(Functions.EASYHAPROXY_LOG, "echo 'test run 3'", log_output=False, return_result=True)
|
result = Functions.run_bash(Functions.EASYHAPROXY_LOG, "echo 'test run 3'", log_output=False,
|
||||||
|
return_result=True)
|
||||||
assert len(Functions.debug_log) == 0
|
assert len(Functions.debug_log) == 0
|
||||||
assert "".join(result) == 'test run 3'
|
assert "".join(result) == 'test run 3'
|
||||||
finally:
|
finally:
|
||||||
Functions.debug_log = None
|
Functions.debug_log = None
|
||||||
|
|
||||||
|
|
||||||
def test_functions_run_bash_log_and_return_output():
|
def test_functions_run_bash_log_and_return_output():
|
||||||
print()
|
print()
|
||||||
Functions.debug_log = []
|
Functions.debug_log = []
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
from .context import easymapping
|
|
||||||
import json
|
import json
|
||||||
import pytest
|
|
||||||
|
from easymapping import DockerLabelHandler
|
||||||
|
|
||||||
|
|
||||||
def test_label_generation():
|
def test_label_generation():
|
||||||
label = easymapping.DockerLabelHandler("foo")
|
label = DockerLabelHandler("foo")
|
||||||
|
|
||||||
assert label.create("bar") == "foo.bar"
|
assert label.create("bar") == "foo.bar"
|
||||||
assert label.create(["bar", "foobar"]) == "foo.bar.foobar"
|
assert label.create(["bar", "foobar"]) == "foo.bar.foobar"
|
||||||
|
|
||||||
|
|
||||||
def test_label_data():
|
def test_label_data():
|
||||||
label = easymapping.DockerLabelHandler("base")
|
label = DockerLabelHandler("base")
|
||||||
label.set_data(json.loads('{"base.definitions":"h2"}'))
|
label.set_data(json.loads('{"base.definitions":"h2"}'))
|
||||||
|
|
||||||
label_name = label.create("definitions")
|
label_name = label.create("definitions")
|
||||||
|
|
@ -20,7 +21,7 @@ def test_label_data():
|
||||||
|
|
||||||
|
|
||||||
def test_label_complex_key():
|
def test_label_complex_key():
|
||||||
label = easymapping.DockerLabelHandler("till")
|
label = DockerLabelHandler("till")
|
||||||
|
|
||||||
data = dict()
|
data = dict()
|
||||||
data["till.definitions"] = "h2"
|
data["till.definitions"] = "h2"
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
import easymapping
|
|
||||||
import pytest
|
|
||||||
import os
|
|
||||||
import yaml
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
import easymapping
|
||||||
|
|
||||||
CERTS_FOLDER = "/tmp/certs"
|
CERTS_FOLDER = "/tmp/certs"
|
||||||
CERT_FILE = "/tmp/certs/haproxy/www.somehost.com.br.pem"
|
CERT_FILE = "/tmp/certs/haproxy/www.somehost.com.br.pem"
|
||||||
CERTBOT_EMAIL = "some@email.com"
|
CERTBOT_EMAIL = "some@email.com"
|
||||||
|
|
||||||
|
|
||||||
def load_fixture(file):
|
def load_fixture(file):
|
||||||
path = os.path.dirname(os.path.realpath(__file__))
|
path = os.path.dirname(os.path.realpath(__file__))
|
||||||
with open(path + "/fixtures/" + file, 'r') as content_file:
|
with open(path + "/fixtures/" + file, 'r') as content_file:
|
||||||
|
|
@ -35,6 +37,7 @@ def test_parser_doesnt_crash():
|
||||||
assert expected_file.read() == haproxy_config
|
assert expected_file.read() == haproxy_config
|
||||||
assert [] == cfg.certbot_hosts
|
assert [] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
def test_parser_finds_services():
|
def test_parser_finds_services():
|
||||||
line_list = load_fixture("services")
|
line_list = load_fixture("services")
|
||||||
|
|
||||||
|
|
@ -60,6 +63,7 @@ def test_parser_finds_services():
|
||||||
|
|
||||||
assert ['node-exporter.quantum.example.org'] == cfg.certbot_hosts
|
assert ['node-exporter.quantum.example.org'] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
def test_parser_finds_services_changed_label():
|
def test_parser_finds_services_changed_label():
|
||||||
line_list = load_fixture("services-changed-label")
|
line_list = load_fixture("services-changed-label")
|
||||||
|
|
||||||
|
|
@ -89,6 +93,7 @@ def test_parser_finds_services_changed_label():
|
||||||
|
|
||||||
assert ['node-exporter.quantum.example.org'] == cfg.certbot_hosts
|
assert ['node-exporter.quantum.example.org'] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
def test_parser_finds_services_raw():
|
def test_parser_finds_services_raw():
|
||||||
line_list = load_fixture("services")
|
line_list = load_fixture("services")
|
||||||
|
|
||||||
|
|
@ -207,7 +212,6 @@ def test_parser_finds_services_raw():
|
||||||
assert ['node-exporter.quantum.example.org'] == cfg.certbot_hosts
|
assert ['node-exporter.quantum.example.org'] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_parser_static():
|
def test_parser_static():
|
||||||
path = os.path.dirname(os.path.realpath(__file__))
|
path = os.path.dirname(os.path.realpath(__file__))
|
||||||
with open(path + "/fixtures/static.yml", 'r') as content_file:
|
with open(path + "/fixtures/static.yml", 'r') as content_file:
|
||||||
|
|
@ -221,6 +225,7 @@ def test_parser_static():
|
||||||
assert expected_file.read() == haproxy_config
|
assert expected_file.read() == haproxy_config
|
||||||
assert [] == cfg.certbot_hosts
|
assert [] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
def test_parser_static_raw():
|
def test_parser_static_raw():
|
||||||
path = os.path.dirname(os.path.realpath(__file__))
|
path = os.path.dirname(os.path.realpath(__file__))
|
||||||
with open(path + "/fixtures/static.yml", 'r') as content_file:
|
with open(path + "/fixtures/static.yml", 'r') as content_file:
|
||||||
|
|
@ -280,7 +285,6 @@ def test_parser_static_raw():
|
||||||
assert expected == parsed
|
assert expected == parsed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_parser_tcp():
|
def test_parser_tcp():
|
||||||
line_list = load_fixture("services-tcp")
|
line_list = load_fixture("services-tcp")
|
||||||
|
|
||||||
|
|
@ -301,6 +305,7 @@ def test_parser_tcp():
|
||||||
assert expected_file.read() == haproxy_config
|
assert expected_file.read() == haproxy_config
|
||||||
assert [] == cfg.certbot_hosts
|
assert [] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
def test_parser_multi_containers():
|
def test_parser_multi_containers():
|
||||||
line_list = load_fixture("services-multi-containers")
|
line_list = load_fixture("services-multi-containers")
|
||||||
|
|
||||||
|
|
@ -384,6 +389,7 @@ def test_parser_ssl_strict():
|
||||||
assert expected_file.read() == haproxy_config
|
assert expected_file.read() == haproxy_config
|
||||||
assert [] == cfg.certbot_hosts
|
assert [] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
def test_parser_ssl_loose():
|
def test_parser_ssl_loose():
|
||||||
line_list = load_fixture("no-services")
|
line_list = load_fixture("no-services")
|
||||||
|
|
||||||
|
|
@ -401,6 +407,7 @@ def test_parser_ssl_loose():
|
||||||
assert expected_file.read() == haproxy_config
|
assert expected_file.read() == haproxy_config
|
||||||
assert [] == cfg.certbot_hosts
|
assert [] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
def test_parser_ssl_letsencrypt():
|
def test_parser_ssl_letsencrypt():
|
||||||
line_list = load_fixture("services-letsencrypt")
|
line_list = load_fixture("services-letsencrypt")
|
||||||
|
|
||||||
|
|
@ -498,8 +505,6 @@ def test_parser_finds_services_clone_to_ssl_raw():
|
||||||
assert parsed_object == processed
|
assert parsed_object == processed
|
||||||
assert [] == cfg.certbot_hosts
|
assert [] == cfg.certbot_hosts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# test_parser_finds_services_raw()
|
# test_parser_finds_services_raw()
|
||||||
# test_parser_tcp()
|
# test_parser_tcp()
|
||||||
# test_parser_multiple_hosts()
|
# test_parser_multiple_hosts()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import pytest
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from functions import Functions
|
from functions import Functions
|
||||||
from processor import ProcessorInterface
|
from processor import ProcessorInterface
|
||||||
from processor import Static
|
|
||||||
|
|
||||||
def test_processor_static():
|
def test_processor_static():
|
||||||
ProcessorInterface.static_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "./fixtures/static.yml")
|
ProcessorInterface.static_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "./fixtures/static.yml")
|
||||||
|
|
@ -63,7 +63,8 @@ def test_processor_static():
|
||||||
|
|
||||||
haproxy_cfg = static.get_haproxy_conf()
|
haproxy_cfg = static.get_haproxy_conf()
|
||||||
|
|
||||||
assert haproxy_cfg == Functions.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "./expected/static.txt"))
|
assert haproxy_cfg == Functions.load(
|
||||||
|
os.path.join(os.path.dirname(os.path.realpath(__file__)), "./expected/static.txt"))
|
||||||
|
|
||||||
# @todo: Static doesnt populate this fields
|
# @todo: Static doesnt populate this fields
|
||||||
assert static.get_certbot_hosts() == []
|
assert static.get_certbot_hosts() == []
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue