Skip to content

Commit bdb6953

Browse files
authored
Doug/fix GitHub reported issues (#6)
* Fixed the issue with the Dependencies Overview being empty * Fixed invalid package purl links in comments. Centralized the source of truce to the Package class. * Fixed the call to the new property name for package * Added debug logging for do_request to track API errors * Changed pyproject.toml to get dynamic module version from package. Moved version to root for dyanmic support. * Fixed stuck for loop due to logic error * Build new version of cli for PyPi * Fixed an issue for Gitlab and Github that would break removing alerts from the detected alerts comment * Rev of new build version for Github/Gitlab comment fix * Fix 'duplicate alerts' for security issues in comments. Although these are unique alerts it isn't obvious from the UI and will be obvious if the package link is followed
1 parent 26277c1 commit bdb6953

File tree

7 files changed

+63
-41
lines changed

7 files changed

+63
-41
lines changed

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "socketsecurity"
7-
version = "0.0.77"
7+
dynamic = ["version"]
88
requires-python = ">= 3.9"
99
dependencies = [
1010
'requests',
@@ -40,4 +40,7 @@ Homepage = "https://socket.dev"
4040
include = [
4141
"socketsecurity",
4242
"socketsecurity.core"
43-
]
43+
]
44+
45+
[tool.setuptools.dynamic]
46+
version = {attr = "socketsecurity.__version__"}

socketsecurity/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import socketsecurity.core
2-
31
__author__ = 'socket.dev'
4-
__version = socketsecurity.core.__version__
2+
__version__ = '0.0.80'

socketsecurity/core/__init__.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from socketsecurity.core.exceptions import (
77
APIFailure, APIKeyMissing, APIAccessDenied, APIInsufficientQuota, APIResourceNotFound, APICloudflareError
88
)
9+
from socketsecurity import __version__
910
from socketsecurity.core.licenses import Licenses
1011
from socketsecurity.core.issues import AllIssues
1112
from socketsecurity.core.classes import (
@@ -23,9 +24,6 @@
2324
from glob import glob
2425
import time
2526

26-
27-
__author__ = 'socket.dev'
28-
__version__ = '0.0.77'
2927
__all__ = [
3028
"Core",
3129
"log",
@@ -93,6 +91,18 @@ def do_request(
9391
files=files,
9492
timeout=timeout
9593
)
94+
output_headers = headers
95+
output_headers['Authorization'] = "Basic API_KEY_REDACTED"
96+
output = {
97+
"url": url,
98+
"headers": output_headers,
99+
"status_code": response.status_code,
100+
"body": response.text,
101+
"payload": payload,
102+
"files": files,
103+
"timeout": timeout
104+
}
105+
log.debug(output)
96106
if response.status_code <= 399:
97107
return response
98108
elif response.status_code == 400:
@@ -672,7 +682,9 @@ def create_issue_alerts(package: Package, alerts: dict, packages: dict) -> dict:
672682
title=title,
673683
suggestion=suggestion,
674684
next_step_title=next_step_title,
675-
introduced_by=introduced_by
685+
introduced_by=introduced_by,
686+
purl=package.purl,
687+
url=package.url
676688
)
677689
if issue_alert.key not in alerts:
678690
alerts[issue_alert.key] = [issue_alert]
@@ -732,7 +744,9 @@ def create_purl(package_id: str, packages: dict) -> (Purl, Package):
732744
introduced_by=introduced_by,
733745
author=package.author or [],
734746
size=package.size,
735-
transitives=package.transitives
747+
transitives=package.transitives,
748+
url=package.url,
749+
purl=package.purl
736750
)
737751
return purl, package
738752

socketsecurity/core/classes.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Package:
8686
transitives: int
8787
license: str
8888
license_text: str
89+
purl: str
8990

9091
def __init__(self, **kwargs):
9192
if kwargs:
@@ -122,6 +123,8 @@ def __init__(self, **kwargs):
122123
self.license = "NoLicenseFound"
123124
if not hasattr(self, "license_text"):
124125
self.license_text = ""
126+
self.url = f"https://socket.dev/{self.type}/package/{self.name}/overview/{self.version}"
127+
self.purl = f"{self.type}/{self.name}@{self.version}"
125128

126129
def __str__(self):
127130
return json.dumps(self.__dict__)
@@ -159,8 +162,6 @@ def __init__(self, **kwargs):
159162
self.introduced_by = []
160163
if not hasattr(self, "manifests"):
161164
self.manifests = ""
162-
self.url = f"https://socket.dev/{self.pkg_type}/{self.pkg_name}/overview/{self.pkg_version}"
163-
self.purl = f"{self.pkg_type}/{self.pkg_name}@{self.pkg_version}"
164165

165166
def __str__(self):
166167
return json.dumps(self.__dict__)
@@ -324,12 +325,15 @@ class Purl:
324325
version: str
325326
ecosystem: str
326327
direct: bool
327-
author: str
328+
author: list
328329
size: int
329330
transitives: int
330331
introduced_by: list
331332
capabilities: dict
332333
is_new: bool
334+
author_url: str
335+
url: str
336+
purl: str
333337

334338
def __init__(self, **kwargs):
335339
if kwargs:
@@ -341,6 +345,22 @@ def __init__(self, **kwargs):
341345
self.capabilities = {}
342346
if not hasattr(self, "is_new"):
343347
self.is_new = False
348+
self.author_url = Purl.generate_author_data(self.author, self.ecosystem)
349+
350+
@staticmethod
351+
def generate_author_data(authors: list, ecosystem: str) -> str:
352+
"""
353+
Creates the Author links for the package
354+
:param authors:
355+
:param ecosystem:
356+
:return:
357+
"""
358+
authors_str = ""
359+
for author in authors:
360+
author_url = f"https://socket.dev/{ecosystem}/user/{author}"
361+
authors_str += f"[{author}]({author_url}),"
362+
authors_str = authors_str.rstrip(",")
363+
return authors_str
344364

345365
def __str__(self):
346366
return json.dumps(self.__dict__)

socketsecurity/core/github.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def process_security_comment(comment: GithubComment, comments) -> str:
324324
line = line.strip()
325325
if "start-socket-alerts-table" in line:
326326
start = True
327+
lines.append(line)
327328
elif start and "end-socket-alerts-table" not in line and not Github.is_heading_line(line) and line != '':
328329
title, package, introduced_by, manifest = line.strip("|").split("|")
329330
details, _ = package.split("](")

socketsecurity/core/gitlab.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def process_security_comment(comment: GitlabComment, comments) -> str:
303303
line = line.strip()
304304
if "start-socket-alerts-table" in line:
305305
start = True
306+
lines.append(line)
306307
elif start and "end-socket-alerts-table" not in line and not Gitlab.is_heading_line(line) and line != '':
307308
title, package, introduced_by, manifest = line.lstrip("|").rstrip("|").split("|")
308309
details, _ = package.split("](")

socketsecurity/core/messages.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def create_security_alert_table(diff: Diff, md: MdUtils) -> (MdUtils, list, dict
153153
", ".join(sources),
154154
manifest_str
155155
]
156-
alert_table.extend(row)
156+
if row not in alert_table:
157+
alert_table.extend(row)
157158
num_of_alert_rows = len(diff.new_alerts) + 1
158159
md.new_table(
159160
columns=num_of_alert_columns,
@@ -220,17 +221,16 @@ def create_added_table(diff: Diff, md: MdUtils) -> MdUtils:
220221
added: Purl
221222
package_url = Messages.create_purl_link(added)
222223
capabilities = ", ".join(added.capabilities)
223-
if capabilities is not None and capabilities != "":
224-
row = [
225-
package_url,
226-
added.direct,
227-
capabilities,
228-
added.transitives,
229-
f"{added.size} KB",
230-
Messages.generate_author_data(added)
231-
]
232-
overview_table.extend(row)
233-
count += 1
224+
row = [
225+
package_url,
226+
added.direct,
227+
capabilities,
228+
added.transitives,
229+
f"{added.size} KB",
230+
added.author_url
231+
]
232+
overview_table.extend(row)
233+
count += 1
234234
num_of_overview_rows = count + 1
235235
md.new_table(
236236
columns=num_of_overview_columns,
@@ -240,29 +240,14 @@ def create_added_table(diff: Diff, md: MdUtils) -> MdUtils:
240240
)
241241
return md
242242

243-
@staticmethod
244-
def generate_author_data(package: Purl):
245-
"""
246-
Creates the Author links for the Dependency Overview Template
247-
:param package:
248-
:return:
249-
"""
250-
authors = ""
251-
for author in package.author:
252-
author_url = f"https://socket.dev/{package.ecosystem}/user/{author}"
253-
authors += f"[{author}]({author_url}),"
254-
authors = authors.rstrip(",")
255-
return authors
256-
257243
@staticmethod
258244
def create_purl_link(details: Purl) -> str:
259245
"""
260246
Creates the Purl link for the Dependency Overview Comment for the added packages
261247
:param details: Purl - Details about the package needed to create the URLs
262248
:return:
263249
"""
264-
purl = f"{details.ecosystem}/{details.name}@{details.version}"
265-
package_url = f"[{purl}](https://socket.dev/{details.ecosystem}/{details.name}/overview/{details.version})"
250+
package_url = f"[{details.purl}]({details.url})"
266251
return package_url
267252

268253
@staticmethod

0 commit comments

Comments
 (0)