Add ability to use self-signed certificate, refactor config.py
This commit is contained in:
parent
3b12868201
commit
6e8238243a
@ -28,7 +28,8 @@ def create_bot(config: Config, i18n: I18N, engine):
|
|||||||
bot.set_webhook(config.webhook.url,
|
bot.set_webhook(config.webhook.url,
|
||||||
drop_pending_updates=config.webhook.drop_pending_updates,
|
drop_pending_updates=config.webhook.drop_pending_updates,
|
||||||
max_connections=config.webhook.max_connections,
|
max_connections=config.webhook.max_connections,
|
||||||
secret_token=config.webhook.secret_token)
|
secret_token=config.webhook.secret_token,
|
||||||
|
certificate=config.webhook.cert_path)
|
||||||
return bot
|
return bot
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -24,12 +25,17 @@ class BotConfig:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WebhookConfig:
|
class WebhookConfig:
|
||||||
domain: str
|
domain: Optional[str]
|
||||||
url_path: str
|
url_path: str
|
||||||
max_connections: int
|
max_connections: int
|
||||||
drop_pending_updates: bool
|
drop_pending_updates: bool
|
||||||
|
|
||||||
|
# secret token
|
||||||
use_secret_token: bool
|
use_secret_token: bool
|
||||||
secret_token: str
|
secret_token: Optional[str]
|
||||||
|
|
||||||
|
# self-signed certificate
|
||||||
|
cert_path: Optional[str]
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
if self.use_secret_token and not self.secret_token:
|
if self.use_secret_token and not self.secret_token:
|
||||||
@ -37,7 +43,7 @@ class WebhookConfig:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
return f"https://{self.domain}/{self.url_path}"
|
return f"https://{self.domain}{self.url_path}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_env(cls):
|
def from_env(cls):
|
||||||
@ -46,7 +52,8 @@ class WebhookConfig:
|
|||||||
int(os.getenv("WEBHOOK_MAX_CONNECTIONS", 40)),
|
int(os.getenv("WEBHOOK_MAX_CONNECTIONS", 40)),
|
||||||
bool(int(os.getenv("WEBHOOK_DROP_PENDING", True))),
|
bool(int(os.getenv("WEBHOOK_DROP_PENDING", True))),
|
||||||
bool(int(os.getenv("WEBHOOK_USE_SECRET_TOKEN", True))),
|
bool(int(os.getenv("WEBHOOK_USE_SECRET_TOKEN", True))),
|
||||||
os.getenv("WEBHOOK_SECRET_TOKEN"))
|
os.getenv("WEBHOOK_SECRET_TOKEN"),
|
||||||
|
os.getenv("WEBHOOK_CERT_PATH"))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user