Skip to content

Commit ba9b91c

Browse files
committed
fix: 修复了一些东西
1 parent a78cff6 commit ba9b91c

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

core/cluster.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from . import utils, logger, config, scheduler, units, storages, i18n
1717
from .storages import File as SFile
1818
import 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
2124
class 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
824852
class SocketIOEmitResult:

i18n/zh_cn.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
"web.warning.server_down": "当前 [${port}] 端口已重新开启",
3939
"web.traceback.check_server": "当前 [${port}] 端口没有通过检查,原因是:",
4040
"cluster.error.download_hash": "通过主控下载文件出错,本来的哈希是 [${hash}],获取到的哈希是 [${got_hash}],内容为 [${content}]",
41-
"cluster.error.download.report": "上报 [${file_path} ${file_hash}(${file_size})] 错误次数 [${failed}] 地址是:${urls}"
41+
"cluster.error.download.report": "上报 [${file_path} ${file_hash}(${file_size})] 错误次数 [${failed}] 地址是:${urls}",
42+
"cluster.info.request_certing": "节点 [${cluster}] 正在请求证书……",
4243
}

0 commit comments

Comments
 (0)