Skip to content

Commit

Permalink
Fix NFS database to usethe new super class
Browse files Browse the repository at this point in the history
  • Loading branch information
NeffIsBack committed Oct 6, 2024
1 parent a3bc425 commit dadeff9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
32 changes: 4 additions & 28 deletions nxc/protocols/nfs/database.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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 <SessionTransactionState.CLOSED: 5>
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())
1 change: 1 addition & 0 deletions nxc/protocols/ssh/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, db_engine):
self.LoggedinRelationsTable = None
self.AdminRelationsTable = None
self.KeysTable = None

super().__init__(db_engine)

@staticmethod
Expand Down

0 comments on commit dadeff9

Please sign in to comment.