socketsecurity 0.0.43__tar.gz → 0.0.44__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.
- {socketsecurity-0.0.43 → socketsecurity-0.0.44}/PKG-INFO +1 -1
- {socketsecurity-0.0.43 → socketsecurity-0.0.44}/setup.py +1 -1
- socketsecurity-0.0.44/socketsecurity/__init__.py +2 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/__init__.py +1 -1
- socketsecurity-0.0.44/socketsecurity/socketcli.py +176 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44}/socketsecurity.egg-info/PKG-INFO +1 -1
- socketsecurity-0.0.44/socketsecurity.egg-info/SOURCES.txt +17 -0
- socketsecurity-0.0.44/socketsecurity.egg-info/top_level.txt +1 -0
- socketsecurity-0.0.43/socketsecurity.egg-info/SOURCES.txt +0 -15
- socketsecurity-0.0.43/socketsecurity.egg-info/top_level.txt +0 -1
- {socketsecurity-0.0.43 → socketsecurity-0.0.44}/setup.cfg +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/classes.py +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/exceptions.py +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/github.py +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/glitlab.py +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/issues.py +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/licenses.py +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44/socketsecurity}/core/messages.py +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44}/socketsecurity.egg-info/dependency_links.txt +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44}/socketsecurity.egg-info/entry_points.txt +0 -0
- {socketsecurity-0.0.43 → socketsecurity-0.0.44}/socketsecurity.egg-info/requires.txt +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from core import Core, version
|
|
5
|
+
from core.classes import FullScanParams, Diff, Package
|
|
6
|
+
from core.messages import Messages
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
parser = argparse.ArgumentParser(
|
|
12
|
+
prog="socketcli",
|
|
13
|
+
description="Socket Security CLI"
|
|
14
|
+
)
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
'--api_token',
|
|
17
|
+
help='The Socket API token can be set via SOCKET_SECURITY_API_KEY',
|
|
18
|
+
required=False
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
'--repo',
|
|
22
|
+
help='The name of the repository',
|
|
23
|
+
required=False
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
'--branch',
|
|
27
|
+
default='main',
|
|
28
|
+
help='The name of the branch',
|
|
29
|
+
required=False
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
|
|
33
|
+
'--committer',
|
|
34
|
+
help='The name of the person or bot running this',
|
|
35
|
+
action="append",
|
|
36
|
+
required=False
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
'--pr_number',
|
|
40
|
+
default=0,
|
|
41
|
+
help='The pr or build number',
|
|
42
|
+
required=False
|
|
43
|
+
)
|
|
44
|
+
parser.add_argument(
|
|
45
|
+
'--commit_message',
|
|
46
|
+
help='Commit or build message for the run',
|
|
47
|
+
required=False
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
'--default_branch',
|
|
51
|
+
default=1,
|
|
52
|
+
help='Whether this is the default/head for run'
|
|
53
|
+
)
|
|
54
|
+
parser.add_argument(
|
|
55
|
+
'--target_path',
|
|
56
|
+
default='./',
|
|
57
|
+
help='Path to look for manifest files',
|
|
58
|
+
required=False
|
|
59
|
+
)
|
|
60
|
+
parser.add_argument(
|
|
61
|
+
'--mode',
|
|
62
|
+
default='diff',
|
|
63
|
+
help='Integration mode choices are api, github, gitlab, and bitbucket',
|
|
64
|
+
choices=["diff", "new", "license"],
|
|
65
|
+
required=False
|
|
66
|
+
)
|
|
67
|
+
parser.add_argument(
|
|
68
|
+
'--scm',
|
|
69
|
+
default='api',
|
|
70
|
+
help='Integration mode choices are api, github, gitlab, and bitbucket',
|
|
71
|
+
choices=["api", "github"],
|
|
72
|
+
required=False
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
parser.add_argument(
|
|
76
|
+
'--generate-license',
|
|
77
|
+
default=False,
|
|
78
|
+
help='Run in license mode to generate license output',
|
|
79
|
+
required=False
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def output_console_comments(diff_report) -> None:
|
|
84
|
+
console_security_comment = Messages.create_console_security_alert_table(diff_report)
|
|
85
|
+
if len(diff_report.new_alerts) > 0:
|
|
86
|
+
print("Security issues detected by Socket Security")
|
|
87
|
+
print(console_security_comment)
|
|
88
|
+
sys.exit(1)
|
|
89
|
+
else:
|
|
90
|
+
print("No New Security issues detected by Socket Security")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == '__main__':
|
|
94
|
+
arguments = parser.parse_args()
|
|
95
|
+
repo = arguments.repo
|
|
96
|
+
branch = arguments.branch
|
|
97
|
+
commit_message = arguments.commit_message
|
|
98
|
+
committer = arguments.committer
|
|
99
|
+
default_branch_int = arguments.default_branch
|
|
100
|
+
default_branch = False
|
|
101
|
+
if default_branch_int == 1:
|
|
102
|
+
default_branch = True
|
|
103
|
+
mode = arguments.mode
|
|
104
|
+
pr_number = arguments.pr_number
|
|
105
|
+
target_path = arguments.target_path
|
|
106
|
+
scm_type = arguments.scm
|
|
107
|
+
license_mode = arguments.generate_license
|
|
108
|
+
license_file = f"{repo}"
|
|
109
|
+
if branch is not None:
|
|
110
|
+
license_file += f"_{branch}"
|
|
111
|
+
license_file += ".json"
|
|
112
|
+
api_token = os.getenv("SOCKET_SECURITY_API_KEY") or arguments.api_token
|
|
113
|
+
if api_token is None:
|
|
114
|
+
print("Unable to find Socket API Token")
|
|
115
|
+
sys.exit(3)
|
|
116
|
+
if repo is None:
|
|
117
|
+
print("Repo name needs to be set")
|
|
118
|
+
sys.exit(2)
|
|
119
|
+
print(f"Starting Socket Security Scan version {version}")
|
|
120
|
+
scm = None
|
|
121
|
+
if scm_type == "github":
|
|
122
|
+
from core.github import Github
|
|
123
|
+
scm = Github()
|
|
124
|
+
base_api_url = os.getenv("BASE_API_URL") or None
|
|
125
|
+
core = Core(token=api_token, request_timeout=6000, base_api_url=base_api_url)
|
|
126
|
+
set_as_pending_head = False
|
|
127
|
+
if default_branch:
|
|
128
|
+
set_as_pending_head = True
|
|
129
|
+
params = FullScanParams(
|
|
130
|
+
repo=repo,
|
|
131
|
+
branch=branch,
|
|
132
|
+
commit_message=commit_message,
|
|
133
|
+
commit_hash="",
|
|
134
|
+
pull_request=pr_number,
|
|
135
|
+
committers=committer,
|
|
136
|
+
make_default_branch=default_branch,
|
|
137
|
+
set_as_pending_head=set_as_pending_head
|
|
138
|
+
)
|
|
139
|
+
diff = None
|
|
140
|
+
if scm is not None and scm.check_event_type() == "comment":
|
|
141
|
+
print("Comment initiated flow")
|
|
142
|
+
comments = scm.get_comments_for_pr(scm.repository, str(scm.pr_number))
|
|
143
|
+
scm.remove_comment_alerts(comments)
|
|
144
|
+
elif scm is not None and scm.check_event_type() != "comment":
|
|
145
|
+
print("Push initiated flow")
|
|
146
|
+
diff: Diff
|
|
147
|
+
diff = core.create_new_diff(target_path, params, workspace=target_path)
|
|
148
|
+
if scm.check_event_type() == "diff":
|
|
149
|
+
comments = scm.get_comments_for_pr(repo, str(pr_number))
|
|
150
|
+
diff.new_alerts = scm.remove_alerts(comments, diff.new_alerts)
|
|
151
|
+
overview_comment = Messages.dependency_overview_template(diff)
|
|
152
|
+
security_comment = Messages.security_comment_template(diff)
|
|
153
|
+
scm.add_socket_comments(security_comment, overview_comment, comments)
|
|
154
|
+
output_console_comments(diff)
|
|
155
|
+
else:
|
|
156
|
+
print("API Mode")
|
|
157
|
+
diff: Diff
|
|
158
|
+
diff = core.create_new_diff(target_path, params, workspace=target_path)
|
|
159
|
+
output_console_comments(diff)
|
|
160
|
+
if diff is not None and license_mode:
|
|
161
|
+
all_packages = {}
|
|
162
|
+
for package_id in diff.packages:
|
|
163
|
+
package: Package
|
|
164
|
+
package = diff.packages[package_id]
|
|
165
|
+
output = {
|
|
166
|
+
"id": package_id,
|
|
167
|
+
"name": package.name,
|
|
168
|
+
"version": package.version,
|
|
169
|
+
"ecosystem": package.type,
|
|
170
|
+
"direct": package.direct,
|
|
171
|
+
"url": package.url,
|
|
172
|
+
"license": package.license,
|
|
173
|
+
"license_text": package.license_text
|
|
174
|
+
}
|
|
175
|
+
all_packages[package_id] = output
|
|
176
|
+
core.save_file(license_file, json.dumps(all_packages))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
socketsecurity/__init__.py
|
|
3
|
+
socketsecurity/socketcli.py
|
|
4
|
+
socketsecurity.egg-info/PKG-INFO
|
|
5
|
+
socketsecurity.egg-info/SOURCES.txt
|
|
6
|
+
socketsecurity.egg-info/dependency_links.txt
|
|
7
|
+
socketsecurity.egg-info/entry_points.txt
|
|
8
|
+
socketsecurity.egg-info/requires.txt
|
|
9
|
+
socketsecurity.egg-info/top_level.txt
|
|
10
|
+
socketsecurity/core/__init__.py
|
|
11
|
+
socketsecurity/core/classes.py
|
|
12
|
+
socketsecurity/core/exceptions.py
|
|
13
|
+
socketsecurity/core/github.py
|
|
14
|
+
socketsecurity/core/glitlab.py
|
|
15
|
+
socketsecurity/core/issues.py
|
|
16
|
+
socketsecurity/core/licenses.py
|
|
17
|
+
socketsecurity/core/messages.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
socketsecurity
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
setup.py
|
|
2
|
-
core/__init__.py
|
|
3
|
-
core/classes.py
|
|
4
|
-
core/exceptions.py
|
|
5
|
-
core/github.py
|
|
6
|
-
core/glitlab.py
|
|
7
|
-
core/issues.py
|
|
8
|
-
core/licenses.py
|
|
9
|
-
core/messages.py
|
|
10
|
-
socketsecurity.egg-info/PKG-INFO
|
|
11
|
-
socketsecurity.egg-info/SOURCES.txt
|
|
12
|
-
socketsecurity.egg-info/dependency_links.txt
|
|
13
|
-
socketsecurity.egg-info/entry_points.txt
|
|
14
|
-
socketsecurity.egg-info/requires.txt
|
|
15
|
-
socketsecurity.egg-info/top_level.txt
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
core
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{socketsecurity-0.0.43 → socketsecurity-0.0.44}/socketsecurity.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|