diff --git a/nxc/protocols/nfs/database.py b/nxc/protocols/nfs/database.py index 2f9a9a549..c95aad17f 100644 --- a/nxc/protocols/nfs/database.py +++ b/nxc/protocols/nfs/database.py @@ -1,31 +1,20 @@ -from pathlib import Path -from sqlalchemy.orm import sessionmaker, scoped_session -from sqlalchemy import MetaData, Table +from sqlalchemy import Table from sqlalchemy.exc import ( - IllegalStateChangeError, NoInspectionAvailable, NoSuchTableError, ) -from nxc.logger import nxc_logger +from nxc.database import BaseDB import sys -class database: +class database(BaseDB): def __init__(self, db_engine): self.CredentialsTable = None self.HostsTable = None self.LoggedinRelationsTable = None self.SharesTable = None - self.db_engine = db_engine - self.db_path = self.db_engine.url.database - self.protocol = Path(self.db_path).stem.upper() - self.metadata = MetaData() - self.reflect_tables() - - session_factory = sessionmaker(bind=self.db_engine, expire_on_commit=True) - Session = scoped_session(session_factory) - self.sess = Session() + super().__init__(db_engine) @staticmethod def db_schema(db_conn): @@ -79,16 +68,3 @@ def reflect_tables(self): [-] Then remove the {self.protocol} DB (`rm -f {self.db_path}`) and run nxc to initialize the new DB""" ) sys.exit() - - def shutdown_db(self): - try: - self.sess.close() - # due to the async nature of nxc, sometimes session state is a bit messy and this will throw: - # Method 'close()' can't be called here; method '_connection_for_bind()' is already in progress and - # this would cause an unexpected state change to - except IllegalStateChangeError as e: - nxc_logger.debug(f"Error while closing session db object: {e}") - - def clear_database(self): - for table in self.metadata.sorted_tables: - self.sess.execute(table.delete()) diff --git a/nxc/protocols/ssh/database.py b/nxc/protocols/ssh/database.py index 1de410c4e..e94704be3 100644 --- a/nxc/protocols/ssh/database.py +++ b/nxc/protocols/ssh/database.py @@ -26,6 +26,7 @@ def __init__(self, db_engine): self.LoggedinRelationsTable = None self.AdminRelationsTable = None self.KeysTable = None + super().__init__(db_engine) @staticmethod