diff sat/tools/common/tls.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 7550ae9cfbac
children
line wrap: on
line diff
--- a/sat/tools/common/tls.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/tools/common/tls.py	Sat Apr 08 13:54:42 2023 +0200
@@ -33,14 +33,14 @@
 log = getLogger(__name__)
 
 
-def getOptionsFromConfig(config, section=""):
+def get_options_from_config(config, section=""):
     options = {}
     for option in ('tls_certificate', 'tls_private_key', 'tls_chain'):
-        options[option] = tools_config.getConfig(config, section, option)
+        options[option] = tools_config.config_get(config, section, option)
     return options
 
 
-def TLSOptionsCheck(options):
+def tls_options_check(options):
     """Check options coherence if TLS is activated, and update missing values
 
     Must be called only if TLS is activated
@@ -52,7 +52,7 @@
         options["tls_private_key"] = options["tls_certificate"]
 
 
-def loadCertificates(f):
+def load_certificates(f):
     """Read a .pem file with a list of certificates
 
     @param f (file): file obj (opened .pem file)
@@ -78,7 +78,7 @@
             return certificates
 
 
-def loadPKey(f):
+def load_p_key(f):
     """Read a private key from a .pem file
 
     @param f (file): file obj (opened .pem file)
@@ -88,7 +88,7 @@
     return OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, f.read())
 
 
-def loadCertificate(f):
+def load_certificate(f):
     """Read a public certificate from a .pem file
 
     @param f (file): file obj (opened .pem file)
@@ -98,7 +98,7 @@
     return OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, f.read())
 
 
-def getTLSContextFactory(options):
+def get_tls_context_factory(options):
     """Load TLS certificate and build the context factory needed for listenSSL"""
     if ssl is None:
         raise ImportError("Python module pyOpenSSL is not installed!")
@@ -106,9 +106,9 @@
     cert_options = {}
 
     for name, option, method in [
-        ("privateKey", "tls_private_key", loadPKey),
-        ("certificate", "tls_certificate", loadCertificate),
-        ("extraCertChain", "tls_chain", loadCertificates),
+        ("privateKey", "tls_private_key", load_p_key),
+        ("certificate", "tls_certificate", load_certificate),
+        ("extraCertChain", "tls_chain", load_certificates),
     ]:
         path = options[option]
         if not path: