Automatically requests Let's Encrypt certificates for containers with a vhost label
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fetcher.py 949B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import etcd
  3. import time
  4. class Fetcher:
  5. def __init__(self, host, port, prefix):
  6. self._client = etcd.Client(host=host, port=port)
  7. self._prefix = prefix
  8. def _read_recursive(self, key):
  9. try:
  10. return self._client.read(self._prefix + key, recursive=True)
  11. except etcd.EtcdKeyNotFound:
  12. return None
  13. def get_label(self, label):
  14. node = self._read_recursive('/labels/%s' % label)
  15. if node:
  16. return {child.key.split('/')[-1]: child.value for child in node.children}
  17. else:
  18. return {}
  19. def wait_for_update(self):
  20. original_time = self._client.read(self._prefix + '/_updated').value
  21. new_time = original_time
  22. while new_time == original_time:
  23. try:
  24. new_time = self._client.read(self._prefix + '/_updated', wait=True).value
  25. except etcd.EtcdWatchTimedOut:
  26. new_time = self._client.read(self._prefix + '/_updated').value
  27. time.sleep(10)