diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..74ab854 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "certonly", + "letsencrypt" + ] +} \ No newline at end of file diff --git a/docs/docker-environment.md b/docs/docker-environment.md index fd41020..a8f8393 100644 --- a/docs/docker-environment.md +++ b/docs/docker-environment.md @@ -5,7 +5,7 @@ | EASYHAPROXY_DISCOVER | How the services will be discovered to create `haproxy.cfg`: `static`, `docker`, `swarm` or `kubernetes` | **required** | | EASYHAPROXY_LABEL_PREFIX | (Optional) The key will search for matching resources. | `easyhaproxy` | | EASYHAPROXY_LETSENCRYPT_EMAIL | (Optional) The email will be used to request the certificate to Letsencrypt | *empty* | -| EASYHAPROXY_LETSENCRYPT_STAGING | (Optional) If true, will try to connect to the Letsencrypt test server | false | +| EASYHAPROXY_LETSENCRYPT_SERVER | (Optional) Can be true or 'schema://domain.tld'. If set, will try to connect to the Letsencrypt test server | false | | EASYHAPROXY_SSL_MODE | (Optional) `strict` supports only the most recent TLS version; `default` good SSL integration with recent browsers; `loose` supports all old SSL protocols for old browsers (not recommended). | `default`| | EASYHAPROXY_REFRESH_CONF | (Optional) Check configuration every N seconds. | 10 | | EASYHAPROXY_LOG_LEVEL | (Optional) The log level for EasyHAproxy messages. Available: TRACE,DEBUG,INFO,WARN,ERROR,FATAL | DEBUG | diff --git a/src/functions/__init__.py b/src/functions/__init__.py index 3438086..387a870 100644 --- a/src/functions/__init__.py +++ b/src/functions/__init__.py @@ -174,10 +174,19 @@ class DaemonizeHAProxy: class Certbot: - def __init__(self, certs, email, staging): + def __init__(self, certs, email, test_server): self.certs = certs self.email = email - self.staging = staging + self.test_server = self.set_test_server(test_server) + + def set_test_server(self, test_server): + if not test_server: + return "" + + if test_server.lower() in ["true", "1", "yes"]: + return "--staging" + else: + return "--server " + test_server def check_certificates(self, hosts): if self.email == "" or len(hosts) == 0: @@ -202,7 +211,7 @@ class Certbot: Functions.log(Functions.CERTBOT_LOG, Functions.DEBUG, "Renew certificate for %s" % (host)) renew_certs.append(host_arg) - certbot_certonly = ('/usr/bin/certbot certonly {staging}' + certbot_certonly = ('/usr/bin/certbot certonly {test_server}' ' --standalone' ' --preferred-challenges http' ' --http-01-port 2080' @@ -213,7 +222,7 @@ class Certbot: ' --max-log-backups=0' ' {certs} --email {email}'.format(certs = ' '.join(request_certs), email = self.email, - staging = '--staging' if self.staging else '') + test_server = self.test_server) ) ret_reload = False diff --git a/src/main.py b/src/main.py index b9017a5..0631ef6 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def start(): haproxy.haproxy("start") haproxy.sleep() - certbot = Certbot(Consts.certs_letsencrypt, os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL"), os.getenv("EASYHAPROXY_LETSENCRYPT_STAGING", "false").lower() in ["true", "1", "yes"]) + certbot = Certbot(Consts.certs_letsencrypt, os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL"), os.getenv("EASYHAPROXY_LETSENCRYPT_SERVER", "false").lower()) while True: if old_haproxy is not None: diff --git a/src/processor/__init__.py b/src/processor/__init__.py index c58e608..1ad8db7 100644 --- a/src/processor/__init__.py +++ b/src/processor/__init__.py @@ -29,7 +29,7 @@ class ContainerEnv: if (os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL")): env_vars["letsencrypt"] = { "email": os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL"), - "staging": os.getenv("EASYHAPROXY_LETSENCRYPT_STAGING", "false").lower() in ["true", "1", "yes"] + "server": os.getenv("EASYHAPROXY_LETSENCRYPT_SERVER", "false").lower() in ["true", "1", "yes"] } return env_vars diff --git a/src/tests/test_containerenv.py b/src/tests/test_containerenv.py index afc5be0..c338871 100644 --- a/src/tests/test_containerenv.py +++ b/src/tests/test_containerenv.py @@ -95,7 +95,7 @@ def test_container_env_stats_password(): "lookup_label": "easyhaproxy", "letsencrypt": { "email": "acme@example.org", - "staging": False + "server": False } } == ContainerEnv.read() finally: @@ -103,7 +103,7 @@ def test_container_env_stats_password(): def test_container_env_letsencrypt(): os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = 'acme@example.org' - os.environ['EASYHAPROXY_LETSENCRYPT_STAGING'] = 'true' + os.environ['EASYHAPROXY_LETSENCRYPT_SERVER'] = 'true' try: assert { "customerrors": False, @@ -111,7 +111,7 @@ def test_container_env_letsencrypt(): "lookup_label": "easyhaproxy", "letsencrypt": { "email": "acme@example.org", - "staging": True + "server": True } } == ContainerEnv.read() finally: