Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/backend.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import collections | import collections | ||||
from email.mime.text import MIMEText | from email.mime.text import MIMEText | ||||
import smtplib | import smtplib | ||||
from typing import Any, Dict, List, Optional, Tuple | from typing import Any, Dict, List, Optional, Tuple | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | class VaultBackend: | ||||
def __init__(self, **config): | def __init__(self, **config): | ||||
self.config = config | self.config = config | ||||
self.cache = VaultCache(**config["cache"]) | self.cache = VaultCache(**config["cache"]) | ||||
self.scheduler = get_scheduler(**config["scheduler"]) | self.scheduler = get_scheduler(**config["scheduler"]) | ||||
self.storage = get_storage(**config["storage"]) | self.storage = get_storage(**config["storage"]) | ||||
self.smtp_server = smtplib.SMTP(**config.get("smtp", {})) | self.smtp_server = smtplib.SMTP(**config.get("smtp", {})) | ||||
if "db" not in self.config: | |||||
raise ValueError( | |||||
"The 'db' configuration entry is missing " | |||||
"in the vault configuration file" | |||||
) | |||||
db_conn = config["db"] | db_conn = config["db"] | ||||
self._pool = psycopg2.pool.ThreadedConnectionPool( | self._pool = psycopg2.pool.ThreadedConnectionPool( | ||||
config.get("min_pool_conns", 1), | config.get("min_pool_conns", 1), | ||||
config.get("max_pool_conns", 10), | config.get("max_pool_conns", 10), | ||||
db_conn, | db_conn, | ||||
cursor_factory=psycopg2.extras.RealDictCursor, | cursor_factory=psycopg2.extras.RealDictCursor, | ||||
) | ) | ||||
self._db = None | self._db = None | ||||
▲ Show 20 Lines • Show All 444 Lines • Show Last 20 Lines |