socketsecurity 0.0.92__tar.gz → 0.0.93__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.93}/PKG-INFO +1 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/__init__.py +1 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/__init__.py +12 -14
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/github.py +6 -7
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/gitlab.py +7 -8
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/scm_comments.py +18 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/socketcli.py +2 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.93/socketsecurity.egg-info}/PKG-INFO +1 -1
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/LICENSE +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/README.md +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/pyproject.toml +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/setup.cfg +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/classes.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/exceptions.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/git_interface.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/issues.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/licenses.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity/core/messages.py +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity.egg-info/SOURCES.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity.egg-info/dependency_links.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity.egg-info/entry_points.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/socketsecurity.egg-info/requires.txt +0 -0
- {socketsecurity-0.0.92 → socketsecurity-0.0.93}/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.93'
|
|
@@ -64,10 +64,11 @@ def do_request(
|
|
|
64
64
|
payload: [dict, str] = None,
|
|
65
65
|
files: list = None,
|
|
66
66
|
method: str = "GET",
|
|
67
|
+
base_url: str = None,
|
|
67
68
|
) -> requests.request:
|
|
68
69
|
"""
|
|
69
70
|
do_requests is the shared function for making HTTP calls
|
|
70
|
-
|
|
71
|
+
:param base_url:
|
|
71
72
|
:param path: Required path for the request
|
|
72
73
|
:param headers: Optional dictionary of headers. If not set will use a default set
|
|
73
74
|
:param payload: Optional dictionary or string of the payload to pass
|
|
@@ -75,8 +76,13 @@ def do_request(
|
|
|
75
76
|
:param method: Optional method to use, defaults to GET
|
|
76
77
|
:return:
|
|
77
78
|
"""
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
if base_url is not None:
|
|
81
|
+
url = f"{base_url}/{path}"
|
|
82
|
+
else:
|
|
83
|
+
if encoded_key is None or encoded_key == "":
|
|
84
|
+
raise APIKeyMissing
|
|
85
|
+
url = f"{api_url}/{path}"
|
|
80
86
|
|
|
81
87
|
if headers is None:
|
|
82
88
|
headers = {
|
|
@@ -84,7 +90,6 @@ def do_request(
|
|
|
84
90
|
'User-Agent': f'SocketPythonCLI/{__version__}',
|
|
85
91
|
"accept": "application/json"
|
|
86
92
|
}
|
|
87
|
-
url = f"{api_url}/{path}"
|
|
88
93
|
response = requests.request(
|
|
89
94
|
method.upper(),
|
|
90
95
|
url,
|
|
@@ -93,8 +98,8 @@ def do_request(
|
|
|
93
98
|
files=files,
|
|
94
99
|
timeout=timeout
|
|
95
100
|
)
|
|
96
|
-
output_headers = headers
|
|
97
|
-
output_headers['Authorization'] = "
|
|
101
|
+
output_headers = headers.copy()
|
|
102
|
+
output_headers['Authorization'] = "API_KEY_REDACTED"
|
|
98
103
|
output = {
|
|
99
104
|
"url": url,
|
|
100
105
|
"headers": output_headers,
|
|
@@ -108,14 +113,7 @@ def do_request(
|
|
|
108
113
|
if response.status_code <= 399:
|
|
109
114
|
return response
|
|
110
115
|
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)
|
|
116
|
+
raise APIFailure(output)
|
|
119
117
|
elif response.status_code == 401:
|
|
120
118
|
raise APIAccessDenied("Unauthorized")
|
|
121
119
|
elif response.status_code == 403:
|
|
@@ -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 = []
|
|
@@ -169,7 +169,8 @@ def main_code():
|
|
|
169
169
|
arguments = parser.parse_args()
|
|
170
170
|
debug = arguments.enable_debug
|
|
171
171
|
if debug:
|
|
172
|
-
|
|
172
|
+
log.setLevel(logging.DEBUG)
|
|
173
|
+
log.debug("Debug logging enabled")
|
|
173
174
|
repo = arguments.repo
|
|
174
175
|
branch = arguments.branch
|
|
175
176
|
commit_message = arguments.commit_message
|
|
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.93}/socketsecurity.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|