Skip to content

Commit 030f5d0

Browse files
authored
allow using ssl for db connection (#432)
* optionally specify SSL usage for db engine * re-trigger
1 parent b7c352f commit 030f5d0

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

configs/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ db:
1818
charset: utf8
1919
echo: True
2020
str: "%(scheme)s://%(user)s:%(password)s@%(host)s:%(port)s/%(database)s?charset=%(charset)s"
21+
use_ssl: False
2122
kwargs:
2223
pool_recycle: 3600
2324
healthcheck_path: /tmp/status

src/oncall/db.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license.
2-
# See LICENSE in the project root for license information.
3-
41
from sqlalchemy import create_engine
2+
import ssl
53

64
connect = None
75
DictCursor = None
@@ -13,8 +11,17 @@ def init(config):
1311
global DictCursor
1412
global IntegrityError
1513

16-
engine = create_engine(config['conn']['str'] % config['conn']['kwargs'],
17-
**config['kwargs'])
14+
connect_args = {}
15+
if config['conn'].get('use_ssl'):
16+
ssl_ctx = ssl.create_default_context()
17+
connect_args["ssl"] = ssl_ctx
18+
19+
engine = create_engine(
20+
config['conn']['str'] % config['conn']['kwargs'],
21+
connect_args=connect_args,
22+
**config['kwargs']
23+
)
24+
1825
dbapi = engine.dialect.dbapi
1926
IntegrityError = dbapi.IntegrityError
2027

0 commit comments

Comments
 (0)