import platform from myTools import DBConnector as db import myTools.ModuleInstaller as mi #This will install the necessary library needed to run the project try: import pyodbc except: mi.installModule("pyodbc") import pyodbc class MSSQL_DBConnector(db.DBConnector): """This class inherits from the abstract class _DBConnector and implements _selectBestDBDriverAvailable for a MSSQL server connection""" #Constructor def __init__(self: object, DSN, dbserver: str, dbname: str, dbusername: str, \ dbpassword: str, trustedmode: bool = False, viewname: str = "", isPasswordObfuscated:bool = True): super().__init__(DSN = DSN, dbserver = dbserver, dbname= dbname, dbusername = dbusername, \ dbpassword = dbpassword, trustedmode = trustedmode, viewname = viewname, isPasswordObfuscated = isPasswordObfuscated) self._selectBestDBDriverAvailable() #Choose the best available driver to establish a connection def _selectBestDBDriverAvailable(self: object) -> None: lstAvailableDrivers: list[str] = pyodbc.drivers() identifiedOS: str = platform.system()
import base64 #This will install the necessary library needed to run the project import myTools.ModuleInstaller as mi try: import cryptography.fernet as f except: mi.installModule("cryptography") import cryptography.fernet as f class ContentObfuscation: """This class should be taken as-is: it's not providing strong encryption, but merely obfuscate data to avoid having plaintext values in the RAM and displayed in a debugger This is not a safe way of doing content encryption. """ fernetK: bytes = b'M0tSMzdyZ083eEhkOXF3MGtydkd1Vlo0UUJwYVhlRzdlRWptQW1QbmlDbz0=' def __init__(self: object): self._cipher_suite = f.Fernet( base64.b64decode(ContentObfuscation.fernetK)) #Function to encode the clear text def obfuscate(self: object, clearText: str) -> str: return (self._cipher_suite.encrypt(clearText.encode())).decode() #Function to decode the clear text def deObfuscate(self: object, obfuscatedText: str) -> str: return (self._cipher_suite.decrypt(obfuscatedText.encode())).decode()
from abc import ABC, abstractmethod import platform import myTools.ContentObfuscation as ce import myTools.ModuleInstaller as mi try: import pandas as pd except: mi.installModule("pandas") import pandas as pd try: import pyodbc except: mi.installModule("pyodbc") import pyodbc class DBConnector(ABC): """This abstract class, inheriting from the ABC class in abc package, allows to factor all the methods required to manage a DB connection, execute queries and retrieve resultsets in Pandas DataFrame. It has one abstract method _selectBestDBDriverAvailable, which needs implemented for each specific derived class. (see MSSQL_DBConnector)""" def __init__(self: object, dbserver: str, dbname: str, dbusername: str, \ dbpassword: str, DSN: str = None, trustedmode: bool = False, viewname: str = "", isPasswordObfuscated:bool = True): try: #Instance of an ContentObfuscator object self._obfuscator: ce.ContentObfuscation = ce.ContentObfuscation() self._m_dbserver: str = str(dbserver)