Skip to content

Commit

Permalink
moved general functions to data_source_connection class
Browse files Browse the repository at this point in the history
  • Loading branch information
P-T-I committed Oct 13, 2023
1 parent 476df89 commit 63e8967
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 72 deletions.
16 changes: 0 additions & 16 deletions CveXplore/objects/capec.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ def iter_related_capecs(self):

yield capec_doc

def to_dict(self):
"""
Method to convert the entire object to a dictionary
:return: Data from object
:rtype: dict
"""

return {k: v for (k, v) in self.__dict__.items() if not k.startswith("_")}

def __eq__(self, other):
return self.__dict__ == other.__dict__

def __ne__(self, other):
return self.__dict__ != other.__dict__

def __repr__(self):
"""String representation of object"""
return "<< Capec:{} >>".format(self.id)
24 changes: 11 additions & 13 deletions CveXplore/objects/cpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,19 @@ def iter_cves_matching_cpe(self, vuln_prod_search: bool = False):
else:
yield None

def to_dict(self):
def to_cve_summary(self) -> dict:
"""
Method to convert the entire object to a dictionary
:return: Data from object
:rtype: dict
Method to request all cve's from the database based on this cpe object
"""

return {k: v for (k, v) in self.__dict__.items() if not k.startswith("_")}

def __eq__(self, other):
return self.__dict__ == other.__dict__

def __ne__(self, other):
return self.__dict__ != other.__dict__
all_cves = list(self.iter_cves_matching_cpe())
data_cves = [
d.to_dict("id", "cvss", "cvss3", "published", "modified", "summary")
for d in all_cves
]
data_cpe = self.to_dict()
data_cpe["cvecount"] = len(data_cves)
data_cpe["cves"] = data_cves
return data_cpe

def __repr__(self):
"""String representation of object"""
Expand Down
22 changes: 11 additions & 11 deletions CveXplore/objects/cves.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,21 @@ def iter_capec(self):
for each in self.capec:
yield each

def to_dict(self):
def to_dict(self, *print_keys: str) -> dict:
"""
Method to convert the entire object to a dictionary
:return: Data from object
:rtype: dict
"""

full_dict = {k: v for (k, v) in self.__dict__.items() if not k.startswith("_")}
if len(print_keys) != 0:
full_dict = {
k: v
for (k, v) in self.__dict__.items()
if not k.startswith("_") and k in print_keys
}
else:
full_dict = {
k: v for (k, v) in self.__dict__.items() if not k.startswith("_")
}

for k, v in full_dict.items():
if isinstance(v, DatasourceConnection):
Expand All @@ -106,12 +112,6 @@ def to_dict(self):

return full_dict

def __eq__(self, other):
return self.__dict__ == other.__dict__

def __ne__(self, other):
return self.__dict__ != other.__dict__

def __repr__(self):
"""String representation of object"""
return "<< Cves:{} >>".format(self.id)
16 changes: 0 additions & 16 deletions CveXplore/objects/cwe.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,6 @@ def iter_related_capecs(self):
for each in related_capecs:
yield each

def to_dict(self):
"""
Method to convert the entire object to a dictionary
:return: Data from object
:rtype: dict
"""

return {k: v for (k, v) in self.__dict__.items() if not k.startswith("_")}

def __eq__(self, other):
return self.__dict__ == other.__dict__

def __ne__(self, other):
return self.__dict__ != other.__dict__

def __repr__(self):
"""String representation of object"""
return "<< Cwe:{} >>".format(self.id)
16 changes: 0 additions & 16 deletions CveXplore/objects/via4.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ def __init__(self, **kwargs):
for each in kwargs:
setattr(self, each, kwargs[each])

def to_dict(self):
"""
Method to convert the entire object to a dictionary
:return: Data from object
:rtype: dict
"""

return {k: v for (k, v) in self.__dict__.items() if not k.startswith("_")}

def __eq__(self, other):
return self.__dict__ == other.__dict__

def __ne__(self, other):
return self.__dict__ != other.__dict__

def __repr__(self):
"""String representation of object"""
return "<< Via4:{} >>".format(self.id)

0 comments on commit 63e8967

Please sign in to comment.