forked from Hay1tsme/artemis
allow alembic to also connect with tls
This commit is contained in:
@ -41,48 +41,14 @@ class Data:
|
||||
self.__url = f"{self.config.database.protocol}+aiomysql://{self.config.database.username}:{self.config.database.password}@{self.config.database.host}:{self.config.database.port}/{self.config.database.name}"
|
||||
|
||||
if Data.engine is MISSING:
|
||||
connect_args: dict[str, Any] = {
|
||||
"charset": "utf8mb4",
|
||||
}
|
||||
|
||||
if self.config.database.ssl_enabled:
|
||||
no_ca = (
|
||||
self.config.database.ssl_cafile is None
|
||||
and self.config.database.ssl_capath is None
|
||||
)
|
||||
|
||||
ctx = ssl.create_default_context(
|
||||
cafile=self.config.database.ssl_cafile,
|
||||
capath=self.config.database.ssl_capath,
|
||||
)
|
||||
ctx.check_hostname = self.config.database.ssl_verify_identity
|
||||
|
||||
if self.config.database.ssl_verify_cert is None:
|
||||
ctx.verify_mode = ssl.CERT_NONE if no_ca else ssl.CERT_REQUIRED
|
||||
else:
|
||||
ctx.verify_mode = (
|
||||
ssl.CERT_REQUIRED
|
||||
if self.config.database.ssl_verify_cert
|
||||
else ssl.CERT_NONE
|
||||
)
|
||||
|
||||
if self.config.database.ssl_cert:
|
||||
ctx.load_cert_chain(
|
||||
self.config.database.ssl_cert,
|
||||
self.config.database.ssl_key,
|
||||
self.config.database.ssl_key_password,
|
||||
)
|
||||
|
||||
if self.config.database.ssl_ciphers:
|
||||
ctx.set_ciphers(self.config.database.ssl_ciphers)
|
||||
|
||||
connect_args["ssl"] = ctx
|
||||
|
||||
Data.engine = create_async_engine(
|
||||
self.__url,
|
||||
pool_recycle=3600,
|
||||
isolation_level="AUTOCOMMIT",
|
||||
connect_args=connect_args,
|
||||
connect_args={
|
||||
"charset": "utf8mb4",
|
||||
"ssl": self.config.database.create_ssl_context_if_enabled(),
|
||||
},
|
||||
)
|
||||
self.__engine = Data.engine
|
||||
|
||||
|
Reference in New Issue
Block a user