-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
from CveXplore.database.connection.base.db_connection_base import DatabaseConnectionBase | ||
from CveXplore.database.connection.sqlbase.sql_client import SQLClient | ||
from CveXplore.database_models.models import CveXploreBase | ||
from CveXplore.errors import DatabaseConnectionException | ||
|
||
|
||
class SQLBaseConnection(DatabaseConnectionBase): | ||
def __init__(self, **kwargs): | ||
super().__init__(logger_name=__name__) | ||
if self.config.DATASOURCE_TYPE != "mongodb": | ||
from CveXplore.database.connection.sqlbase.sql_client import SQLClient | ||
|
||
self._dbclient = { | ||
"info": SQLClient("info"), | ||
"cpe": SQLClient("cpe"), | ||
"cves": SQLClient("cves"), | ||
"schema": SQLClient("schema"), | ||
"cwe": SQLClient("cwe"), | ||
"capec": SQLClient("capec"), | ||
"via4": SQLClient("via4"), | ||
} | ||
|
||
try: | ||
collections = list(CveXploreBase.metadata.tables.keys()) | ||
except ConnectionError as err: | ||
raise DatabaseConnectionException( | ||
f"Connection to the database failed: {err}" | ||
) | ||
|
||
if len(collections) != 0: | ||
for each in collections: | ||
self.__setattr__(f"store_{each}", SQLClient(each)) | ||
self._dbclient = { | ||
"info": SQLClient("info"), | ||
"cpe": SQLClient("cpe"), | ||
"cves": SQLClient("cves"), | ||
"schema": SQLClient("schema"), | ||
"cwe": SQLClient("cwe"), | ||
"capec": SQLClient("capec"), | ||
"via4": SQLClient("via4"), | ||
} | ||
|
||
try: | ||
collections = list(CveXploreBase.metadata.tables.keys()) | ||
except ConnectionError as err: | ||
raise DatabaseConnectionException( | ||
f"Connection to the database failed: {err}" | ||
) | ||
|
||
if len(collections) != 0: | ||
for each in collections: | ||
self.__setattr__(f"store_{each}", SQLClient(each)) | ||
|
||
@property | ||
def dbclient(self): | ||
return self._dbclient | ||
|
||
def set_handlers_for_collections(self): | ||
for each in list(CveXploreBase.metadata.tables.keys()): | ||
if not hasattr(self, each): | ||
setattr(self, f"store_{each}", SQLClient(each)) | ||
if self.config.DATASOURCE_TYPE != "mongodb": | ||
from CveXplore.database.connection.sqlbase.sql_client import SQLClient | ||
|
||
for each in list(CveXploreBase.metadata.tables.keys()): | ||
if not hasattr(self, each): | ||
setattr(self, f"store_{each}", SQLClient(each)) |