socketsecurity 0.0.82__tar.gz → 0.0.83__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 (23) hide show
  1. {socketsecurity-0.0.82/socketsecurity.egg-info → socketsecurity-0.0.83}/PKG-INFO +1 -1
  2. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/__init__.py +1 -1
  3. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/__init__.py +12 -14
  4. socketsecurity-0.0.83/socketsecurity/core/git_interface.py +25 -0
  5. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/socketcli.py +39 -7
  6. {socketsecurity-0.0.82 → socketsecurity-0.0.83/socketsecurity.egg-info}/PKG-INFO +1 -1
  7. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity.egg-info/SOURCES.txt +1 -0
  8. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/LICENSE +0 -0
  9. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/README.md +0 -0
  10. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/pyproject.toml +0 -0
  11. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/setup.cfg +0 -0
  12. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/classes.py +0 -0
  13. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/exceptions.py +0 -0
  14. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/github.py +0 -0
  15. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/gitlab.py +0 -0
  16. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/issues.py +0 -0
  17. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/licenses.py +0 -0
  18. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/messages.py +0 -0
  19. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity/core/scm_comments.py +0 -0
  20. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity.egg-info/dependency_links.txt +0 -0
  21. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity.egg-info/entry_points.txt +0 -0
  22. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/socketsecurity.egg-info/requires.txt +0 -0
  23. {socketsecurity-0.0.82 → socketsecurity-0.0.83}/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.82
3
+ Version: 0.0.83
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>
@@ -1,2 +1,2 @@
1
1
  __author__ = 'socket.dev'
2
- __version__ = '0.0.82'
2
+ __version__ = '0.0.83'
@@ -22,6 +22,7 @@ from socketsecurity.core.classes import (
22
22
  )
23
23
  import platform
24
24
  from glob import glob
25
+ import fnmatch
25
26
  import time
26
27
 
27
28
  __all__ = [
@@ -306,25 +307,15 @@ class Core:
306
307
  return sbom
307
308
 
308
309
  @staticmethod
309
- def find_files(path: str) -> list:
310
+ def find_files(path: str, new_files: list = None) -> list:
310
311
  """
311
312
  Globs the path for supported manifest files.
312
313
  Note: Might move the source to a JSON file
313
314
  :param path: Str - path to where the manifest files are located
315
+ :param new_files:
314
316
  :return:
315
317
  """
316
318
  socket_globs = {
317
- "general": {
318
- "readme": {
319
- "pattern": "*readme*"
320
- },
321
- "notice": {
322
- "pattern": "*notice*"
323
- },
324
- "license": {
325
- "pattern": "{licen{s,c}e{,-*},copying}"
326
- }
327
- },
328
319
  "npm": {
329
320
  "package.json": {
330
321
  "pattern": "package.json"
@@ -399,6 +390,12 @@ class Core:
399
390
  file_path = f"{path}/**/{pattern}"
400
391
  files = glob(file_path, recursive=True)
401
392
  for file in files:
393
+ if "/" in file:
394
+ _, base_name = file.rsplit("/", 1)
395
+ else:
396
+ base_name = file
397
+ if new_files is not None and base_name not in new_files:
398
+ continue
402
399
  if platform.system() == "Windows":
403
400
  file = file.replace("\\", "/")
404
401
  found_path, file_name = file.rsplit("/", 1)
@@ -478,7 +475,7 @@ class Core:
478
475
  return full_scan
479
476
 
480
477
  @staticmethod
481
- def create_new_diff(path: str, params: FullScanParams, workspace: str) -> Diff:
478
+ def create_new_diff(path: str, params: FullScanParams, workspace: str, new_files: list = None) -> Diff:
482
479
  """
483
480
  1. Get the head full scan. If it isn't present because this repo doesn't exist yet return an Empty full scan.
484
481
  2. Create a new Full scan for the current run
@@ -487,9 +484,10 @@ class Core:
487
484
  :param path: Str - path of where to look for manifest files for the new Full Scan
488
485
  :param params: FullScanParams - Query params for the Full Scan endpoint
489
486
  :param workspace: str - Path for workspace
487
+ :param new_files:
490
488
  :return:
491
489
  """
492
- files = Core.find_files(path)
490
+ files = Core.find_files(path, new_files)
493
491
  try:
494
492
  head_full_scan_id = Core.get_head_scan_for_repo(params.repo)
495
493
  if head_full_scan_id is None or head_full_scan_id == "":
@@ -0,0 +1,25 @@
1
+ from git import Repo
2
+
3
+
4
+ class Git:
5
+ repo: Repo
6
+ path: str
7
+
8
+ def __init__(self, path: str):
9
+ self.path = path
10
+ self.repo = Repo(path)
11
+ assert self.repo
12
+ self.head = self.repo.head
13
+ self.reference = self.head.reference
14
+ self.commit = self.reference.commit
15
+ self.repo_name = self.repo.remotes.origin.url.split('.git')[0].split('/')[-1]
16
+ self.branch = self.repo.active_branch
17
+ self.author = self.commit.author
18
+ self.commit_sha = self.commit.binsha
19
+ self.commit_message = self.commit.message
20
+ self.committer = self.commit.committer
21
+ self.show_files = self.repo.git.show(self.commit, name_only=True, format="%n").splitlines()
22
+ self.changed_files = []
23
+ for item in self.show_files:
24
+ if item != "":
25
+ self.changed_files.append(item)
@@ -4,6 +4,8 @@ from socketsecurity.core import Core, __version__
4
4
  from socketsecurity.core.classes import FullScanParams, Diff, Package
5
5
  from socketsecurity.core.messages import Messages
6
6
  from socketsecurity.core.scm_comments import Comments
7
+ from socketsecurity.core.git_interface import Git
8
+ from git import InvalidGitRepositoryError
7
9
  import os
8
10
  import sys
9
11
  import logging
@@ -27,7 +29,7 @@ parser.add_argument(
27
29
  )
28
30
  parser.add_argument(
29
31
  '--branch',
30
- default='main',
32
+ default='',
31
33
  help='The name of the branch',
32
34
  required=False
33
35
  )
@@ -113,6 +115,12 @@ parser.add_argument(
113
115
  default=False
114
116
  )
115
117
 
118
+ parser.add_argument(
119
+ '--files',
120
+ help='Specify a list of files in the format of ["file1", "file2"]',
121
+ default="[]"
122
+ )
123
+
116
124
 
117
125
  def output_console_comments(diff_report) -> None:
118
126
  console_security_comment = Messages.create_console_security_alert_table(diff_report)
@@ -160,17 +168,41 @@ def main_code():
160
168
  sbom_file = arguments.sbom_file
161
169
  license_mode = arguments.generate_license
162
170
  enable_json = arguments.enable_json
163
- license_file = f"{repo}"
164
- if branch is not None:
165
- license_file += f"_{branch}"
166
- license_file += ".json"
171
+ files = arguments.files
167
172
  api_token = os.getenv("SOCKET_SECURITY_API_KEY") or arguments.api_token
173
+ try:
174
+ files = json.loads(files)
175
+ except Exception as error:
176
+ log.error(f"Unable to parse {files}")
177
+ log.error(error)
178
+ sys.exit(3)
168
179
  if api_token is None:
169
180
  log.info("Unable to find Socket API Token")
170
181
  sys.exit(3)
182
+ try:
183
+ git_repo = Git(target_path)
184
+ if repo is None:
185
+ repo = git_repo.repo_name
186
+ if commit_sha is None or commit_sha == '':
187
+ commit_sha = git_repo.commit
188
+ if branch is None or branch == '':
189
+ branch = git_repo.branch
190
+ if committer is None or committer == '':
191
+ committer = git_repo.committer
192
+ if commit_message is None or commit_message == '':
193
+ commit_message = git_repo.commit_message
194
+ if len(files) == 0:
195
+ files = git_repo.changed_files
196
+ except InvalidGitRepositoryError:
197
+ pass
198
+ # git_repo = None
171
199
  if repo is None:
172
200
  log.info("Repo name needs to be set")
173
201
  sys.exit(2)
202
+ license_file = f"{repo}"
203
+ if branch is not None:
204
+ license_file += f"_{branch}"
205
+ license_file += ".json"
174
206
  log.info(f"Starting Socket Security Scan version {__version__}")
175
207
  scm = None
176
208
  if scm_type == "github":
@@ -205,7 +237,7 @@ def main_code():
205
237
  elif scm is not None and scm.check_event_type() != "comment":
206
238
  log.info("Push initiated flow")
207
239
  diff: Diff
208
- diff = core.create_new_diff(target_path, params, workspace=target_path)
240
+ diff = core.create_new_diff(target_path, params, workspace=target_path, new_files=files)
209
241
  if scm.check_event_type() == "diff":
210
242
  comments = scm.get_comments_for_pr(repo, str(pr_number))
211
243
  diff.new_alerts = Comments.remove_alerts(comments, diff.new_alerts)
@@ -231,7 +263,7 @@ def main_code():
231
263
  else:
232
264
  log.info("API Mode")
233
265
  diff: Diff
234
- diff = core.create_new_diff(target_path, params, workspace=target_path)
266
+ diff = core.create_new_diff(target_path, params, workspace=target_path, new_files=files)
235
267
  if enable_json:
236
268
  output_console_json(diff)
237
269
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: socketsecurity
3
- Version: 0.0.82
3
+ Version: 0.0.83
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>
@@ -12,6 +12,7 @@ socketsecurity.egg-info/top_level.txt
12
12
  socketsecurity/core/__init__.py
13
13
  socketsecurity/core/classes.py
14
14
  socketsecurity/core/exceptions.py
15
+ socketsecurity/core/git_interface.py
15
16
  socketsecurity/core/github.py
16
17
  socketsecurity/core/gitlab.py
17
18
  socketsecurity/core/issues.py
File without changes