|
4 | 4 | from threading import Thread |
5 | 5 | from time import sleep |
6 | 6 |
|
7 | | -import sqlite3 |
8 | | -import psycopg2 |
9 | 7 |
|
10 | 8 | import constants |
11 | 9 | from log import get_logger |
12 | 10 | from models.config import ( |
13 | 11 | Configuration, |
14 | 12 | QuotaHandlersConfiguration, |
15 | 13 | QuotaLimiterConfiguration, |
16 | | - PostgreSQLDatabaseConfiguration, |
17 | | - SQLiteDatabaseConfiguration, |
18 | 14 | ) |
19 | 15 |
|
| 16 | +from quota.connect_pg import connect_pg |
| 17 | +from quota.connect_sqlite import connect_sqlite |
| 18 | + |
20 | 19 | from quota.sql import ( |
21 | 20 | CREATE_QUOTA_TABLE, |
22 | 21 | INCREASE_QUOTA_STATEMENT_PG, |
@@ -211,41 +210,6 @@ def connect(config: QuotaHandlersConfiguration) -> Any: |
211 | 210 | return None |
212 | 211 |
|
213 | 212 |
|
214 | | -def connect_pg(config: PostgreSQLDatabaseConfiguration) -> Any: |
215 | | - """Initialize connection to PostgreSQL database.""" |
216 | | - logger.info("Connecting to PostgreSQL storage") |
217 | | - connection = psycopg2.connect( |
218 | | - host=config.host, |
219 | | - port=config.port, |
220 | | - user=config.user, |
221 | | - password=config.password.get_secret_value(), |
222 | | - dbname=config.db, |
223 | | - sslmode=config.ssl_mode, |
224 | | - # sslrootcert=config.ca_cert_path, |
225 | | - gssencmode=config.gss_encmode, |
226 | | - ) |
227 | | - if connection is not None: |
228 | | - connection.autocommit = True |
229 | | - return connection |
230 | | - |
231 | | - |
232 | | -def connect_sqlite(config: SQLiteDatabaseConfiguration) -> Any: |
233 | | - """Initialize connection to database.""" |
234 | | - logger.info("Connecting to SQLite storage") |
235 | | - # make sure the connection will have known state |
236 | | - # even if SQLite is not alive |
237 | | - connection = None |
238 | | - try: |
239 | | - connection = sqlite3.connect(database=config.db_path) |
240 | | - except sqlite3.Error as e: |
241 | | - if connection is not None: |
242 | | - connection.close() |
243 | | - logger.exception("Error initializing SQLite cache:\n%s", e) |
244 | | - raise |
245 | | - connection.autocommit = True |
246 | | - return connection |
247 | | - |
248 | | - |
249 | 213 | def init_tables(connection: Any) -> None: |
250 | 214 | """Initialize tables used by quota limiter.""" |
251 | 215 | logger.info("Initializing tables for quota limiter") |
|
0 commit comments