25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

52 satır
1.7 KiB

  1. import os
  2. import subprocess
  3. from dockersible.files import copy, template
  4. def get_ssl_context(environ):
  5. domain = environ['DOMAIN']
  6. nginx_info = {
  7. 'domain': domain,
  8. 'dhparam': False,
  9. 'ssl_trusted_certificate': False
  10. }
  11. dhparam = os.path.join('/certificates', domain + '.dhparam.pem')
  12. if os.path.exists(dhparam):
  13. nginx_info['dhparam'] = True
  14. copy(source=dhparam, destination='/etc/ssl/certs', basename='dhparam.pem', mode='0644')
  15. trusted_certificates = os.path.join('/certificates', domain + '.ca.crt')
  16. if os.path.exists(trusted_certificates):
  17. nginx_info['ssl_trusted_certificate'] = True
  18. copy(source=trusted_certificates, destination='/etc/ssl/certs', basename='ca.crt', mode='0644')
  19. return nginx_info
  20. def get_certificates(domain):
  21. private_key = os.path.join('/certificates', domain + '.key')
  22. certificate = os.path.join('/certificates', domain + '.crt')
  23. if not os.path.exists(private_key) or not os.path.exists(certificate):
  24. cmd = """openssl req \
  25. -new \
  26. -newkey rsa:4096 \
  27. -days 365 \
  28. -nodes \
  29. -x509 \
  30. -subj "/C=US/ST=State/L=City/O=Company/CN={}" \
  31. -keyout {} \
  32. -out {}""".format(domain, private_key, certificate)
  33. subprocess.call(cmd, shell=True)
  34. return private_key, certificate
  35. if __name__ == "__main__":
  36. pk, crt = get_certificates(os.environ['DOMAIN'])
  37. copy(source=pk, destination='/etc/ssl/private', basename='private.key', mode='0600')
  38. copy(source=crt, destination='/etc/ssl/certs', basename='certificate.crt', mode='0644')
  39. template('/backend.conf.j2', get_ssl_context(os.environ), '/etc/nginx/conf.d/default.conf')