socketsecurity 0.0.69__tar.gz → 0.0.71__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {socketsecurity-0.0.69/socketsecurity.egg-info → socketsecurity-0.0.71}/PKG-INFO +1 -1
  2. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/pyproject.toml +1 -1
  3. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/__init__.py +52 -3
  4. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/github.py +19 -11
  5. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/gitlab.py +19 -11
  6. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/socketcli.py +33 -2
  7. {socketsecurity-0.0.69 → socketsecurity-0.0.71/socketsecurity.egg-info}/PKG-INFO +1 -1
  8. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/LICENSE +0 -0
  9. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/README.md +0 -0
  10. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/setup.cfg +0 -0
  11. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/__init__.py +0 -0
  12. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/classes.py +0 -0
  13. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/exceptions.py +0 -0
  14. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/issues.py +0 -0
  15. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/licenses.py +0 -0
  16. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity/core/messages.py +0 -0
  17. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity.egg-info/SOURCES.txt +0 -0
  18. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity.egg-info/dependency_links.txt +0 -0
  19. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity.egg-info/entry_points.txt +0 -0
  20. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity.egg-info/requires.txt +0 -0
  21. {socketsecurity-0.0.69 → socketsecurity-0.0.71}/socketsecurity.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: socketsecurity
3
- Version: 0.0.69
3
+ Version: 0.0.71
4
4
  Summary: Socket Security CLI for CI/CD
5
5
  Author-email: Douglas Coburn <douglas@socket.dev>
6
6
  Maintainer-email: Douglas Coburn <douglas@socket.dev>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "socketsecurity"
7
- version = "0.0.69"
7
+ version = "0.0.71"
8
8
  requires-python = ">= 3.9"
9
9
  dependencies = [
10
10
  'requests',
@@ -25,7 +25,7 @@ import time
25
25
 
26
26
 
27
27
  __author__ = 'socket.dev'
28
- __version__ = '0.0.69'
28
+ __version__ = '0.0.71'
29
29
  __all__ = [
30
30
  "Core",
31
31
  "log",
@@ -246,6 +246,55 @@ class Core:
246
246
  }
247
247
  return org_rules
248
248
 
249
+ # @staticmethod
250
+ # def get_supported_file_types() -> dict:
251
+ # path = "report/supported"
252
+
253
+ @staticmethod
254
+ def get_manifest_files(package: Package, packages: dict) -> str:
255
+ if package.direct:
256
+ manifests = []
257
+ for manifest_item in package.manifestFiles:
258
+ manifest = manifest_item["file"]
259
+ manifests.append(manifest)
260
+ manifest_files = ";".join(manifests)
261
+ else:
262
+ manifests = []
263
+ for top_id in package.topLevelAncestors:
264
+ top_package: Package
265
+ top_package = packages[top_id]
266
+ for manifest_item in top_package.manifestFiles:
267
+ manifest = manifest_item["file"]
268
+ new_string = f"{package.name}@{package.version}({manifest})"
269
+ manifests.append(new_string)
270
+ manifest_files = ";".join(manifests)
271
+ return manifest_files
272
+
273
+ @staticmethod
274
+ def create_sbom_output(diff: Diff) -> list:
275
+ sbom = []
276
+ for package_id in diff.packages:
277
+ package: Package
278
+ package = diff.packages[package_id]
279
+ manifest_files = Core.get_manifest_files(package, diff.packages)
280
+ item = {
281
+ "id": package.id,
282
+ "license": package.license,
283
+ "license_text": package.license_text,
284
+ "manifestFiles": manifest_files,
285
+ "score": package.score,
286
+ "size": package.size,
287
+ "ecosystem": package.type,
288
+ "alerts": package.alerts,
289
+ "direct": package.direct,
290
+ "name": package.name,
291
+ "version": package.version,
292
+ "author": package.author,
293
+ "url": package.url
294
+ }
295
+ sbom.append(item)
296
+ return sbom
297
+
249
298
  @staticmethod
250
299
  def find_files(path: str) -> list:
251
300
  """
@@ -314,8 +363,8 @@ class Core:
314
363
  "requirements.frozen": {
315
364
  "pattern": "requirements.frozen"
316
365
  },
317
- "setup.py.old": {
318
- "pattern": "setup.py.old"
366
+ "setup.py": {
367
+ "pattern": "setup.py"
319
368
  }
320
369
  },
321
370
  "golang": {
@@ -163,19 +163,27 @@ class Github:
163
163
  return event_type
164
164
 
165
165
  @staticmethod
166
- def add_socket_comments(security_comment: str, overview_comment: str, comments: dict) -> None:
166
+ def add_socket_comments(
167
+ security_comment: str,
168
+ overview_comment: str,
169
+ comments: dict,
170
+ new_security_comment: bool = True,
171
+ new_overview_comment: bool = True
172
+ ) -> None:
167
173
  existing_overview_comment = comments.get("overview")
168
174
  existing_security_comment = comments.get("security")
169
- if existing_overview_comment is not None:
170
- existing_overview_comment: GithubComment
171
- Github.update_comment(overview_comment, str(existing_overview_comment.id))
172
- else:
173
- Github.post_comment(overview_comment)
174
- if existing_security_comment is not None:
175
- existing_security_comment: GithubComment
176
- Github.update_comment(security_comment, str(existing_security_comment.id))
177
- else:
178
- Github.post_comment(security_comment)
175
+ if new_overview_comment:
176
+ if existing_overview_comment is not None:
177
+ existing_overview_comment: GithubComment
178
+ Github.update_comment(overview_comment, str(existing_overview_comment.id))
179
+ else:
180
+ Github.post_comment(overview_comment)
181
+ if new_security_comment:
182
+ if existing_security_comment is not None:
183
+ existing_security_comment: GithubComment
184
+ Github.update_comment(security_comment, str(existing_security_comment.id))
185
+ else:
186
+ Github.post_comment(security_comment)
179
187
 
180
188
  @staticmethod
181
189
  def post_comment(body: str) -> None:
@@ -159,19 +159,27 @@ class Gitlab:
159
159
  return event_type
160
160
 
161
161
  @staticmethod
162
- def add_socket_comments(security_comment: str, overview_comment: str, comments: dict) -> None:
162
+ def add_socket_comments(
163
+ security_comment: str,
164
+ overview_comment: str,
165
+ comments: dict,
166
+ new_security_comment: bool = True,
167
+ new_overview_comment: bool = True
168
+ ) -> None:
163
169
  existing_overview_comment = comments.get("overview")
164
170
  existing_security_comment = comments.get("security")
165
- if existing_overview_comment is not None:
166
- existing_overview_comment: GitlabComment
167
- Gitlab.update_comment(overview_comment, str(existing_overview_comment.id))
168
- else:
169
- Gitlab.post_comment(overview_comment)
170
- if existing_security_comment is not None:
171
- existing_security_comment: GitlabComment
172
- Gitlab.update_comment(security_comment, str(existing_security_comment.id))
173
- else:
174
- Gitlab.post_comment(security_comment)
171
+ if new_overview_comment:
172
+ if existing_overview_comment is not None:
173
+ existing_overview_comment: GitlabComment
174
+ Gitlab.update_comment(overview_comment, str(existing_overview_comment.id))
175
+ else:
176
+ Gitlab.post_comment(overview_comment)
177
+ if new_security_comment:
178
+ if existing_security_comment is not None:
179
+ existing_security_comment: GitlabComment
180
+ Gitlab.update_comment(security_comment, str(existing_security_comment.id))
181
+ else:
182
+ Gitlab.post_comment(security_comment)
175
183
 
176
184
  @staticmethod
177
185
  def post_comment(body: str) -> None:
@@ -69,6 +69,20 @@ parser.add_argument(
69
69
  required=False
70
70
  )
71
71
 
72
+ parser.add_argument(
73
+ '--sbom-file',
74
+ default=None,
75
+ help='If soecified save the SBOM details to the specified file',
76
+ required=False
77
+ )
78
+
79
+ parser.add_argument(
80
+ '--commit-sha',
81
+ default="",
82
+ help='Optional git commit sha',
83
+ required=False
84
+ )
85
+
72
86
  parser.add_argument(
73
87
  '--generate-license',
74
88
  default=False,
@@ -115,6 +129,8 @@ def cli():
115
129
  pr_number = arguments.pr_number
116
130
  target_path = arguments.target_path
117
131
  scm_type = arguments.scm
132
+ commit_sha = arguments.commit_sha
133
+ sbom_file = arguments.sbom_file
118
134
  license_mode = arguments.generate_license
119
135
  license_file = f"{repo}"
120
136
  if branch is not None:
@@ -137,6 +153,7 @@ def cli():
137
153
  scm = Gitlab()
138
154
  if scm is not None:
139
155
  default_branch = scm.is_default_branch
156
+
140
157
  base_api_url = os.getenv("BASE_API_URL") or None
141
158
  core = Core(token=api_token, request_timeout=6000, base_api_url=base_api_url)
142
159
  set_as_pending_head = False
@@ -146,7 +163,7 @@ def cli():
146
163
  repo=repo,
147
164
  branch=branch,
148
165
  commit_message=commit_message,
149
- commit_hash="",
166
+ commit_hash=commit_sha,
150
167
  pull_request=pr_number,
151
168
  committers=committer,
152
169
  make_default_branch=default_branch,
@@ -166,7 +183,19 @@ def cli():
166
183
  diff.new_alerts = scm.remove_alerts(comments, diff.new_alerts)
167
184
  overview_comment = Messages.dependency_overview_template(diff)
168
185
  security_comment = Messages.security_comment_template(diff)
169
- scm.add_socket_comments(security_comment, overview_comment, comments)
186
+ new_security_comment = True
187
+ new_overview_comment = True
188
+ if len(diff.new_alerts) == 0:
189
+ new_security_comment = False
190
+ if len(diff.new_packages) == 0 and diff.removed_packages == 0:
191
+ new_overview_comment = False
192
+ scm.add_socket_comments(
193
+ security_comment,
194
+ overview_comment,
195
+ comments,
196
+ new_security_comment,
197
+ new_overview_comment
198
+ )
170
199
  output_console_comments(diff)
171
200
  else:
172
201
  log.info("API Mode")
@@ -190,6 +219,8 @@ def cli():
190
219
  }
191
220
  all_packages[package_id] = output
192
221
  core.save_file(license_file, json.dumps(all_packages))
222
+ if diff is not None and sbom_file is not None:
223
+ core.save_file(sbom_file, json.dumps(core.create_sbom_output(diff)))
193
224
 
194
225
 
195
226
  if __name__ == '__main__':
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: socketsecurity
3
- Version: 0.0.69
3
+ Version: 0.0.71
4
4
  Summary: Socket Security CLI for CI/CD
5
5
  Author-email: Douglas Coburn <douglas@socket.dev>
6
6
  Maintainer-email: Douglas Coburn <douglas@socket.dev>
File without changes