glclient.tls

 1from . import glclient as native
 2from typing import Optional, Union
 3import logging
 4
 5logger = logging.getLogger("glclientpy.tls.TlsConfig")
 6
 7class TlsConfig(object):
 8    def __init__(self):
 9        logger.debug("Constructing nobody identity")
10        # We wrap the TlsConfig since some calls cannot yet be routed
11        # through the rust library (streaming calls)
12        self.inner = native.TlsConfig()
13        self.ca: Optional[bytes] = None
14        self.authenticated = False
15
16    def identity(self, cert_pem: Union[str, bytes], key_pem: Union[str, bytes]) -> "TlsConfig":
17        if isinstance(cert_pem, str):
18            cert_pem = cert_pem.encode('ASCII')
19
20        if isinstance(key_pem, str):
21            key_pem = key_pem.encode('ASCII')
22
23        c = TlsConfig()  # Create a copy of ourselves
24        c.inner = self.inner.identity(cert_pem, key_pem)
25        c.ca = self.ca
26        logger.debug("Authenticating TLS identity")
27        c.authenticated = True
28        return c
29
30    @classmethod
31    def identity_from_path(cls, path : str) -> "TlsConfig":
32        c = TlsConfig()
33        c.inner = c.inner.identity_from_path(path)
34        c.ca = c.ca
35        logger.debug("Authenticating TLS identity")
36        c.authenticated = True
37        return c
38    
39    def with_ca_certificate(self, ca: Union[str, bytes]) -> "TlsConfig":
40        logger.debug("Customizing greenlight CA")
41        if isinstance(ca, str):
42            ca = ca.encode('ASCII')
43
44        c = TlsConfig()
45        c.inner = self.inner.with_ca_certificate(ca)
46        c.ca = ca
47        c.authenticated = self.authenticated
48        return c
class TlsConfig:
 8class TlsConfig(object):
 9    def __init__(self):
10        logger.debug("Constructing nobody identity")
11        # We wrap the TlsConfig since some calls cannot yet be routed
12        # through the rust library (streaming calls)
13        self.inner = native.TlsConfig()
14        self.ca: Optional[bytes] = None
15        self.authenticated = False
16
17    def identity(self, cert_pem: Union[str, bytes], key_pem: Union[str, bytes]) -> "TlsConfig":
18        if isinstance(cert_pem, str):
19            cert_pem = cert_pem.encode('ASCII')
20
21        if isinstance(key_pem, str):
22            key_pem = key_pem.encode('ASCII')
23
24        c = TlsConfig()  # Create a copy of ourselves
25        c.inner = self.inner.identity(cert_pem, key_pem)
26        c.ca = self.ca
27        logger.debug("Authenticating TLS identity")
28        c.authenticated = True
29        return c
30
31    @classmethod
32    def identity_from_path(cls, path : str) -> "TlsConfig":
33        c = TlsConfig()
34        c.inner = c.inner.identity_from_path(path)
35        c.ca = c.ca
36        logger.debug("Authenticating TLS identity")
37        c.authenticated = True
38        return c
39    
40    def with_ca_certificate(self, ca: Union[str, bytes]) -> "TlsConfig":
41        logger.debug("Customizing greenlight CA")
42        if isinstance(ca, str):
43            ca = ca.encode('ASCII')
44
45        c = TlsConfig()
46        c.inner = self.inner.with_ca_certificate(ca)
47        c.ca = ca
48        c.authenticated = self.authenticated
49        return c
def identity( self, cert_pem: Union[str, bytes], key_pem: Union[str, bytes]) -> glclient.tls.TlsConfig:
17    def identity(self, cert_pem: Union[str, bytes], key_pem: Union[str, bytes]) -> "TlsConfig":
18        if isinstance(cert_pem, str):
19            cert_pem = cert_pem.encode('ASCII')
20
21        if isinstance(key_pem, str):
22            key_pem = key_pem.encode('ASCII')
23
24        c = TlsConfig()  # Create a copy of ourselves
25        c.inner = self.inner.identity(cert_pem, key_pem)
26        c.ca = self.ca
27        logger.debug("Authenticating TLS identity")
28        c.authenticated = True
29        return c
@classmethod
def identity_from_path(cls, path: str) -> glclient.tls.TlsConfig:
31    @classmethod
32    def identity_from_path(cls, path : str) -> "TlsConfig":
33        c = TlsConfig()
34        c.inner = c.inner.identity_from_path(path)
35        c.ca = c.ca
36        logger.debug("Authenticating TLS identity")
37        c.authenticated = True
38        return c
def with_ca_certificate(self, ca: Union[str, bytes]) -> glclient.tls.TlsConfig:
40    def with_ca_certificate(self, ca: Union[str, bytes]) -> "TlsConfig":
41        logger.debug("Customizing greenlight CA")
42        if isinstance(ca, str):
43            ca = ca.encode('ASCII')
44
45        c = TlsConfig()
46        c.inner = self.inner.with_ca_certificate(ca)
47        c.ca = ca
48        c.authenticated = self.authenticated
49        return c