1
0
Fork 0

Issue #32 renaming letsencrypt test server env var

This commit is contained in:
Joao Gilberto 2022-11-10 18:43:50 -03:00
parent 607470a122
commit f7969c2deb
6 changed files with 25 additions and 10 deletions

6
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,6 @@
{
"cSpell.words": [
"certonly",
"letsencrypt"
]
}

View file

@ -5,7 +5,7 @@
| EASYHAPROXY_DISCOVER | How the services will be discovered to create `haproxy.cfg`: `static`, `docker`, `swarm` or `kubernetes` | **required** | | 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_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_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_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_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 | | EASYHAPROXY_LOG_LEVEL | (Optional) The log level for EasyHAproxy messages. Available: TRACE,DEBUG,INFO,WARN,ERROR,FATAL | DEBUG |

View file

@ -174,10 +174,19 @@ class DaemonizeHAProxy:
class Certbot: class Certbot:
def __init__(self, certs, email, staging): def __init__(self, certs, email, test_server):
self.certs = certs self.certs = certs
self.email = email 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): def check_certificates(self, hosts):
if self.email == "" or len(hosts) == 0: 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)) Functions.log(Functions.CERTBOT_LOG, Functions.DEBUG, "Renew certificate for %s" % (host))
renew_certs.append(host_arg) renew_certs.append(host_arg)
certbot_certonly = ('/usr/bin/certbot certonly {staging}' certbot_certonly = ('/usr/bin/certbot certonly {test_server}'
' --standalone' ' --standalone'
' --preferred-challenges http' ' --preferred-challenges http'
' --http-01-port 2080' ' --http-01-port 2080'
@ -213,7 +222,7 @@ class Certbot:
' --max-log-backups=0' ' --max-log-backups=0'
' {certs} --email {email}'.format(certs = ' '.join(request_certs), ' {certs} --email {email}'.format(certs = ' '.join(request_certs),
email = self.email, email = self.email,
staging = '--staging' if self.staging else '') test_server = self.test_server)
) )
ret_reload = False ret_reload = False

View file

@ -22,7 +22,7 @@ def start():
haproxy.haproxy("start") haproxy.haproxy("start")
haproxy.sleep() 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: while True:
if old_haproxy is not None: if old_haproxy is not None:

View file

@ -29,7 +29,7 @@ class ContainerEnv:
if (os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL")): if (os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL")):
env_vars["letsencrypt"] = { env_vars["letsencrypt"] = {
"email": os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL"), "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 return env_vars

View file

@ -95,7 +95,7 @@ def test_container_env_stats_password():
"lookup_label": "easyhaproxy", "lookup_label": "easyhaproxy",
"letsencrypt": { "letsencrypt": {
"email": "acme@example.org", "email": "acme@example.org",
"staging": False "server": False
} }
} == ContainerEnv.read() } == ContainerEnv.read()
finally: finally:
@ -103,7 +103,7 @@ def test_container_env_stats_password():
def test_container_env_letsencrypt(): def test_container_env_letsencrypt():
os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = 'acme@example.org' os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = 'acme@example.org'
os.environ['EASYHAPROXY_LETSENCRYPT_STAGING'] = 'true' os.environ['EASYHAPROXY_LETSENCRYPT_SERVER'] = 'true'
try: try:
assert { assert {
"customerrors": False, "customerrors": False,
@ -111,7 +111,7 @@ def test_container_env_letsencrypt():
"lookup_label": "easyhaproxy", "lookup_label": "easyhaproxy",
"letsencrypt": { "letsencrypt": {
"email": "acme@example.org", "email": "acme@example.org",
"staging": True "server": True
} }
} == ContainerEnv.read() } == ContainerEnv.read()
finally: finally: