socketsecurity 0.0.92__tar.gz → 0.0.94__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.92/socketsecurity.egg-info → socketsecurity-0.0.94}/PKG-INFO +1 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/__init__.py +1 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/__init__.py +17 -15
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/github.py +6 -7
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/gitlab.py +7 -8
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/scm_comments.py +18 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/socketcli.py +3 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.94/socketsecurity.egg-info}/PKG-INFO +1 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/LICENSE +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/README.md +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/pyproject.toml +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/setup.cfg +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/classes.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/exceptions.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/git_interface.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/issues.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/licenses.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity/core/messages.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity.egg-info/SOURCES.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity.egg-info/dependency_links.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity.egg-info/entry_points.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity.egg-info/requires.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.94}/socketsecurity.egg-info/top_level.txt +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
__author__ = 'socket.dev'
|
|
2
|
-
__version__ = '0.0.
|
|
2
|
+
__version__ = '0.0.94'
|
|
@@ -22,7 +22,6 @@ from socketsecurity.core.classes import (
|
|
|
22
22
|
)
|
|
23
23
|
import platform
|
|
24
24
|
from glob import glob
|
|
25
|
-
import fnmatch
|
|
26
25
|
import time
|
|
27
26
|
|
|
28
27
|
__all__ = [
|
|
@@ -64,10 +63,11 @@ def do_request(
|
|
|
64
63
|
payload: [dict, str] = None,
|
|
65
64
|
files: list = None,
|
|
66
65
|
method: str = "GET",
|
|
66
|
+
base_url: str = None,
|
|
67
67
|
) -> requests.request:
|
|
68
68
|
"""
|
|
69
69
|
do_requests is the shared function for making HTTP calls
|
|
70
|
-
|
|
70
|
+
:param base_url:
|
|
71
71
|
:param path: Required path for the request
|
|
72
72
|
:param headers: Optional dictionary of headers. If not set will use a default set
|
|
73
73
|
:param payload: Optional dictionary or string of the payload to pass
|
|
@@ -75,8 +75,13 @@ def do_request(
|
|
|
75
75
|
:param method: Optional method to use, defaults to GET
|
|
76
76
|
:return:
|
|
77
77
|
"""
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
|
|
79
|
+
if base_url is not None:
|
|
80
|
+
url = f"{base_url}/{path}"
|
|
81
|
+
else:
|
|
82
|
+
if encoded_key is None or encoded_key == "":
|
|
83
|
+
raise APIKeyMissing
|
|
84
|
+
url = f"{api_url}/{path}"
|
|
80
85
|
|
|
81
86
|
if headers is None:
|
|
82
87
|
headers = {
|
|
@@ -84,7 +89,6 @@ def do_request(
|
|
|
84
89
|
'User-Agent': f'SocketPythonCLI/{__version__}',
|
|
85
90
|
"accept": "application/json"
|
|
86
91
|
}
|
|
87
|
-
url = f"{api_url}/{path}"
|
|
88
92
|
response = requests.request(
|
|
89
93
|
method.upper(),
|
|
90
94
|
url,
|
|
@@ -93,8 +97,8 @@ def do_request(
|
|
|
93
97
|
files=files,
|
|
94
98
|
timeout=timeout
|
|
95
99
|
)
|
|
96
|
-
output_headers = headers
|
|
97
|
-
output_headers['Authorization'] = "
|
|
100
|
+
output_headers = headers.copy()
|
|
101
|
+
output_headers['Authorization'] = "API_KEY_REDACTED"
|
|
98
102
|
output = {
|
|
99
103
|
"url": url,
|
|
100
104
|
"headers": output_headers,
|
|
@@ -108,14 +112,7 @@ def do_request(
|
|
|
108
112
|
if response.status_code <= 399:
|
|
109
113
|
return response
|
|
110
114
|
elif response.status_code == 400:
|
|
111
|
-
|
|
112
|
-
print(f"payload={payload}")
|
|
113
|
-
print(f"files={files}")
|
|
114
|
-
error = {
|
|
115
|
-
"msg": "bad request",
|
|
116
|
-
"error": response.text
|
|
117
|
-
}
|
|
118
|
-
raise APIFailure(error)
|
|
115
|
+
raise APIFailure(output)
|
|
119
116
|
elif response.status_code == 401:
|
|
120
117
|
raise APIAccessDenied("Unauthorized")
|
|
121
118
|
elif response.status_code == 403:
|
|
@@ -158,6 +155,11 @@ class Core:
|
|
|
158
155
|
all_new_alerts = True
|
|
159
156
|
Core.set_org_vars()
|
|
160
157
|
|
|
158
|
+
@staticmethod
|
|
159
|
+
def enable_debug_log(level: int):
|
|
160
|
+
global log
|
|
161
|
+
log.setLevel(level)
|
|
162
|
+
|
|
161
163
|
@staticmethod
|
|
162
164
|
def set_org_vars() -> None:
|
|
163
165
|
"""
|
|
@@ -58,7 +58,6 @@ headers = {
|
|
|
58
58
|
'User-Agent': 'SocketPythonScript/0.0.1',
|
|
59
59
|
"accept": "application/json"
|
|
60
60
|
}
|
|
61
|
-
base_url = f"{github_api_url}/"
|
|
62
61
|
|
|
63
62
|
|
|
64
63
|
class Github:
|
|
@@ -149,22 +148,22 @@ class Github:
|
|
|
149
148
|
@staticmethod
|
|
150
149
|
def post_comment(body: str) -> None:
|
|
151
150
|
repo = github_repository.rsplit("/", 1)[1]
|
|
152
|
-
path = f"
|
|
151
|
+
path = f"repos/{github_repository_owner}/{repo}/issues/{pr_number}/comments"
|
|
153
152
|
payload = {
|
|
154
153
|
"body": body
|
|
155
154
|
}
|
|
156
155
|
payload = json.dumps(payload)
|
|
157
|
-
do_request(path, payload=payload, method="POST", headers=headers)
|
|
156
|
+
do_request(path, payload=payload, method="POST", headers=headers, base_url=github_api_url)
|
|
158
157
|
|
|
159
158
|
@staticmethod
|
|
160
159
|
def update_comment(body: str, comment_id: str) -> None:
|
|
161
160
|
repo = github_repository.rsplit("/", 1)[1]
|
|
162
|
-
path = f"
|
|
161
|
+
path = f"repos/{github_repository_owner}/{repo}/issues/comments/{comment_id}"
|
|
163
162
|
payload = {
|
|
164
163
|
"body": body
|
|
165
164
|
}
|
|
166
165
|
payload = json.dumps(payload)
|
|
167
|
-
do_request(path, payload=payload, method="PATCH", headers=headers)
|
|
166
|
+
do_request(path, payload=payload, method="PATCH", headers=headers, base_url=github_api_url)
|
|
168
167
|
|
|
169
168
|
@staticmethod
|
|
170
169
|
def write_new_env(name: str, content: str) -> None:
|
|
@@ -175,8 +174,8 @@ class Github:
|
|
|
175
174
|
|
|
176
175
|
@staticmethod
|
|
177
176
|
def get_comments_for_pr(repo: str, pr: str) -> dict:
|
|
178
|
-
path = f"
|
|
179
|
-
raw_comments = do_request(path, headers=headers)
|
|
177
|
+
path = f"repos/{github_repository_owner}/{repo}/issues/{pr}/comments"
|
|
178
|
+
raw_comments = Comments.process_response(do_request(path, headers=headers, base_url=github_api_url))
|
|
180
179
|
comments = {}
|
|
181
180
|
if "error" not in raw_comments:
|
|
182
181
|
for item in raw_comments:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import os
|
|
2
3
|
from socketsecurity.core import log, do_request
|
|
3
4
|
from socketsecurity.core.scm_comments import Comments
|
|
@@ -46,14 +47,12 @@ for env in gitlab_variables:
|
|
|
46
47
|
value = globals()[var_name]
|
|
47
48
|
log.debug(f"{env}={value}")
|
|
48
49
|
|
|
49
|
-
base_url = f"{ci_api_v4_url}/"
|
|
50
50
|
headers = {
|
|
51
51
|
'Authorization': f"Bearer {gitlab_token}",
|
|
52
52
|
'User-Agent': 'SocketPythonScript/0.0.1',
|
|
53
53
|
"accept": "application/json"
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
57
56
|
class Gitlab:
|
|
58
57
|
commit_sha: str
|
|
59
58
|
api_url: str
|
|
@@ -141,24 +140,24 @@ class Gitlab:
|
|
|
141
140
|
|
|
142
141
|
@staticmethod
|
|
143
142
|
def post_comment(body: str) -> None:
|
|
144
|
-
path = f"
|
|
143
|
+
path = f"projects/{ci_merge_request_project_id}/merge_requests/{ci_merge_request_iid}/notes"
|
|
145
144
|
payload = {
|
|
146
145
|
"body": body
|
|
147
146
|
}
|
|
148
|
-
do_request(path, payload=payload, method="POST", headers=headers)
|
|
147
|
+
do_request(path, payload=payload, method="POST", headers=headers, base_url=ci_api_v4_url)
|
|
149
148
|
|
|
150
149
|
@staticmethod
|
|
151
150
|
def update_comment(body: str, comment_id: str) -> None:
|
|
152
|
-
path = f"
|
|
151
|
+
path = f"projects/{ci_merge_request_project_id}/merge_requests/{ci_merge_request_iid}/notes/{comment_id}"
|
|
153
152
|
payload = {
|
|
154
153
|
"body": body
|
|
155
154
|
}
|
|
156
|
-
do_request(path, payload=payload, method="PUT", headers=headers)
|
|
155
|
+
do_request(path, payload=payload, method="PUT", headers=headers, base_url=ci_api_v4_url)
|
|
157
156
|
|
|
158
157
|
@staticmethod
|
|
159
158
|
def get_comments_for_pr(repo: str, pr: str) -> dict:
|
|
160
|
-
path = f"
|
|
161
|
-
raw_comments = do_request(path, headers=headers)
|
|
159
|
+
path = f"projects/{ci_merge_request_project_id}/merge_requests/{ci_merge_request_iid}/notes"
|
|
160
|
+
raw_comments = Comments.process_response(do_request(path, headers=headers, base_url=ci_api_v4_url))
|
|
162
161
|
comments = {}
|
|
163
162
|
if "message" not in raw_comments:
|
|
164
163
|
for item in raw_comments:
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
from socketsecurity.core.classes import Comment, Issue
|
|
2
|
+
from socketsecurity.core import log
|
|
3
|
+
from requests import Response
|
|
4
|
+
import json
|
|
2
5
|
|
|
3
6
|
|
|
4
7
|
class Comments:
|
|
8
|
+
@staticmethod
|
|
9
|
+
def process_response(response: Response) -> dict:
|
|
10
|
+
output = {}
|
|
11
|
+
try:
|
|
12
|
+
output = response.json()
|
|
13
|
+
except Exception as error:
|
|
14
|
+
log.debug("Unable to parse comment response json, trying as text")
|
|
15
|
+
log.debug(error)
|
|
16
|
+
try:
|
|
17
|
+
output = json.loads(response.text)
|
|
18
|
+
except Exception as error:
|
|
19
|
+
log.error("Unable to process comment data, unable to get previous comment data")
|
|
20
|
+
log.error(error)
|
|
21
|
+
return output
|
|
22
|
+
|
|
5
23
|
@staticmethod
|
|
6
24
|
def remove_alerts(comments: dict, new_alerts: list) -> list:
|
|
7
25
|
alerts = []
|
|
@@ -170,6 +170,9 @@ def main_code():
|
|
|
170
170
|
debug = arguments.enable_debug
|
|
171
171
|
if debug:
|
|
172
172
|
logging.basicConfig(level=logging.DEBUG)
|
|
173
|
+
log.setLevel(logging.DEBUG)
|
|
174
|
+
Core.enable_debug_log(logging.DEBUG)
|
|
175
|
+
log.debug("Debug logging enabled")
|
|
173
176
|
repo = arguments.repo
|
|
174
177
|
branch = arguments.branch
|
|
175
178
|
commit_message = arguments.commit_message
|
|
@@ -261,7 +264,6 @@ def main_code():
|
|
|
261
264
|
log.debug(f"Getting comments for Repo {scm.repository} for PR {scm.pr_number}")
|
|
262
265
|
comments = scm.get_comments_for_pr(repo, str(pr_number))
|
|
263
266
|
log.debug("Removing comment alerts")
|
|
264
|
-
log.debug("")
|
|
265
267
|
diff.new_alerts = Comments.remove_alerts(comments, diff.new_alerts)
|
|
266
268
|
log.debug("Creating Dependency Overview Comment")
|
|
267
269
|
overview_comment = Messages.dependency_overview_template(diff)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
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.92 → socketsecurity-0.0.94}/socketsecurity.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|