1616from . import utils , logger , config , scheduler , units , storages , i18n
1717from .storages import File as SFile
1818import socketio
19+ """import cryptography.x509 as x509
20+ from cryptography.hazmat.backends import default_backend
21+ from cryptography.x509.oid import NameOID"""
1922
2023@dataclass
2124class Token :
@@ -521,15 +524,26 @@ async def start(self):
521524 def get_cluster_by_id (self , id : Optional [str ] = None ) -> Optional ['Cluster' ]:
522525 return self .cluster_id_tables .get (id or "" , None )
523526
527+ def byoc (self ):
528+ if config .const .ssl_cert and config .const .ssl_key :
529+ main = ClusterCertificate (
530+ config .const .host ,
531+ Path (config .const .ssl_cert ),
532+ Path (config .const .ssl_key )
533+ )
534+ if main .is_valid :
535+ return True
536+ return False
524537
525538 async def get_certificate (self ):
526- main = ClusterCertificate (
527- config .const .host ,
528- Path (config .const .ssl_cert ),
529- Path (config .const .ssl_key )
530- )
531- if main .is_valid :
532- return main
539+ if config .const .ssl_cert and config .const .ssl_key :
540+ main = ClusterCertificate (
541+ config .const .host ,
542+ Path (config .const .ssl_cert ),
543+ Path (config .const .ssl_key )
544+ )
545+ if main .is_valid :
546+ return main
533547 await asyncio .gather (* [cluster .request_cert () for cluster in self .clusters ])
534548 return [cluster .certificate for cluster in self .clusters ][0 ]
535549
@@ -627,6 +641,7 @@ async def request_cert(self):
627641 if not ssl_dir .exists ():
628642 ssl_dir .mkdir (parents = True , exist_ok = True )
629643 cert_file , key_file = ssl_dir / f"{ self .id } _cert.pem" , ssl_dir / f"{ self .id } _key.pem"
644+ logger .tinfo ("cluster.info.request_certing" , cluster = self .id )
630645 result = await self .socket_io .emit (
631646 "request-cert" ,
632647 )
@@ -648,9 +663,9 @@ async def enable(self):
648663 try :
649664 result = await self .socket_io .emit (
650665 "enable" , {
651- "host" : cert .host ,
666+ "host" : config . const .host ,
652667 "port" : config .const .public_port ,
653- "byoc" : True ,
668+ "byoc" : clusters . byoc () ,
654669 "version" : API_VERSION ,
655670 "noFastEnable" : True ,
656671 "flavor" : {
@@ -738,9 +753,8 @@ class ClusterSocketIO:
738753 def __init__ (self , cluster : Cluster ) -> None :
739754 self .cluster = cluster
740755 self .sio = socketio .AsyncClient (
741- logger = True ,
756+ logger = config . const . debug ,
742757 handle_sigint = False ,
743- engineio_logger = logger
744758 )
745759
746760 async def connect (self ):
@@ -819,6 +833,20 @@ class ClusterCertificate:
819833 @property
820834 def is_valid (self ):
821835 return self .host and self .cert .exists () and self .key .exists ()
836+
837+ """@property
838+ def get_domains(self):
839+ try:
840+ cert = x509.load_pem_x509_certificate(self.cert.read_bytes(), default_backend())
841+ domains = []
842+ for subject in cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME):
843+ if isinstance(subject.value, str):
844+ domains.append(subject.value)
845+ elif isinstance(subject.value, bytes):
846+ domains.append(subject.value.decode("utf-8"))
847+ return domains
848+ except:
849+ return []"""
822850
823851@dataclass
824852class SocketIOEmitResult :
0 commit comments