socketdev 3.2.0__py3-none-any.whl → 3.3.0__py3-none-any.whl
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.
- socketdev/core/api.py +9 -9
- socketdev/exceptions.py +80 -47
- socketdev/version.py +1 -1
- {socketdev-3.2.0.dist-info → socketdev-3.3.0.dist-info}/METADATA +1 -1
- {socketdev-3.2.0.dist-info → socketdev-3.3.0.dist-info}/RECORD +7 -7
- {socketdev-3.2.0.dist-info → socketdev-3.3.0.dist-info}/WHEEL +0 -0
- {socketdev-3.2.0.dist-info → socketdev-3.3.0.dist-info}/licenses/LICENSE +0 -0
socketdev/core/api.py
CHANGED
|
@@ -76,26 +76,26 @@ class API:
|
|
|
76
76
|
path_str = f"\nPath: {url}"
|
|
77
77
|
|
|
78
78
|
if response.status_code == 401:
|
|
79
|
-
raise APIAccessDenied(f"Unauthorized{path_str}{headers_str}")
|
|
79
|
+
raise APIAccessDenied(f"Unauthorized{path_str}{headers_str}", status_code=401)
|
|
80
80
|
if response.status_code == 403:
|
|
81
81
|
try:
|
|
82
82
|
error_message = response.json().get("error", {}).get("message", "")
|
|
83
83
|
if "Insufficient permissions for API method" in error_message:
|
|
84
84
|
log.error(f"{error_message}{path_str}{headers_str}")
|
|
85
|
-
raise APIInsufficientPermissions()
|
|
85
|
+
raise APIInsufficientPermissions(status_code=403)
|
|
86
86
|
elif "Organization not allowed" in error_message:
|
|
87
87
|
log.error(f"{error_message}{path_str}{headers_str}")
|
|
88
|
-
raise APIOrganizationNotAllowed()
|
|
88
|
+
raise APIOrganizationNotAllowed(status_code=403)
|
|
89
89
|
elif "Insufficient max quota" in error_message:
|
|
90
90
|
log.error(f"{error_message}{path_str}{headers_str}")
|
|
91
|
-
raise APIInsufficientQuota()
|
|
91
|
+
raise APIInsufficientQuota(status_code=403)
|
|
92
92
|
else:
|
|
93
|
-
raise APIAccessDenied(f"{error_message or 'Access denied'}{path_str}{headers_str}")
|
|
93
|
+
raise APIAccessDenied(f"{error_message or 'Access denied'}{path_str}{headers_str}", status_code=403)
|
|
94
94
|
except ValueError:
|
|
95
|
-
raise APIAccessDenied(f"Access denied{path_str}{headers_str}")
|
|
95
|
+
raise APIAccessDenied(f"Access denied{path_str}{headers_str}", status_code=403)
|
|
96
96
|
if response.status_code == 404:
|
|
97
97
|
log.error(f"Path not found {path}{path_str}{headers_str}")
|
|
98
|
-
raise APIResourceNotFound()
|
|
98
|
+
raise APIResourceNotFound(status_code=404)
|
|
99
99
|
if response.status_code == 429:
|
|
100
100
|
retry_after = response.headers.get("retry-after")
|
|
101
101
|
if retry_after:
|
|
@@ -109,7 +109,7 @@ class API:
|
|
|
109
109
|
else:
|
|
110
110
|
time_msg = ""
|
|
111
111
|
log.error(f"Insufficient quota for API route.{time_msg}{path_str}{headers_str}")
|
|
112
|
-
raise APIInsufficientQuota()
|
|
112
|
+
raise APIInsufficientQuota(status_code=429)
|
|
113
113
|
if response.status_code == 502:
|
|
114
114
|
log.error(f"Upstream server error{path_str}{headers_str}")
|
|
115
115
|
raise APIBadGateway()
|
|
@@ -124,7 +124,7 @@ class API:
|
|
|
124
124
|
f"Error message: {error_message}"
|
|
125
125
|
)
|
|
126
126
|
log.error(error)
|
|
127
|
-
raise APIFailure(error)
|
|
127
|
+
raise APIFailure(error, status_code=response.status_code)
|
|
128
128
|
|
|
129
129
|
return response
|
|
130
130
|
except Timeout:
|
socketdev/exceptions.py
CHANGED
|
@@ -1,47 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class
|
|
36
|
-
"""Raised when
|
|
37
|
-
pass
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class
|
|
41
|
-
"""Raised when
|
|
42
|
-
pass
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class
|
|
46
|
-
"""Raised when
|
|
47
|
-
pass
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
# HTTP statuses classified as transient by APIFailure.is_transient_error(): gateway /
|
|
4
|
+
# availability failures where the request was dropped before the application produced a
|
|
5
|
+
# definitive response, so retrying the same request may succeed (408 Request Timeout,
|
|
6
|
+
# 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout).
|
|
7
|
+
TRANSIENT_HTTP_STATUS_CODES = frozenset({408, 502, 503, 504})
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class APIFailure(Exception):
|
|
11
|
+
"""Base exception for all Socket API errors"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, *args, status_code: Optional[int] = None):
|
|
14
|
+
super().__init__(*args)
|
|
15
|
+
self.status_code = status_code
|
|
16
|
+
|
|
17
|
+
def is_transient_error(self) -> bool:
|
|
18
|
+
"""Whether this failure is transient, i.e. retrying the same request may succeed.
|
|
19
|
+
|
|
20
|
+
Transient failures happen at the gateway/connection level - HTTP 408/502/503/504,
|
|
21
|
+
dropped or reset connections, and client-side timeouts - before the server produced
|
|
22
|
+
a definitive response. Deterministic errors (e.g. 400/401/403/404/429) are not
|
|
23
|
+
transient: retrying the same request fails the same way. Classification is based on
|
|
24
|
+
the HTTP status code recorded when the exception was raised (or overridden by
|
|
25
|
+
subclasses without an HTTP status, like timeouts), so it stays correct even if a
|
|
26
|
+
status code gains a dedicated exception subclass later.
|
|
27
|
+
"""
|
|
28
|
+
return self.status_code in TRANSIENT_HTTP_STATUS_CODES
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class APIKeyMissing(APIFailure):
|
|
32
|
+
"""Raised when the api key is not passed and the headers are empty"""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class APIAccessDenied(APIFailure):
|
|
36
|
+
"""Raised when access is denied to the API"""
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class APIInsufficientPermissions(APIFailure):
|
|
41
|
+
"""Raised when the API token doesn't have required permissions"""
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class APIOrganizationNotAllowed(APIFailure):
|
|
46
|
+
"""Raised when organization doesn't have access to the feature"""
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class APIInsufficientQuota(APIFailure):
|
|
51
|
+
"""Raised when access is denied to the API due to quota limits"""
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class APIResourceNotFound(APIFailure):
|
|
56
|
+
"""Raised when the requested resource is not found"""
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class APITimeout(APIFailure):
|
|
61
|
+
"""Raised when a request times out"""
|
|
62
|
+
|
|
63
|
+
def is_transient_error(self) -> bool:
|
|
64
|
+
# No HTTP status: the request timed out client-side, so a retry may succeed.
|
|
65
|
+
return True
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class APIConnectionError(APIFailure):
|
|
69
|
+
"""Raised when there's a connection error"""
|
|
70
|
+
|
|
71
|
+
def is_transient_error(self) -> bool:
|
|
72
|
+
# No HTTP status: the connection was dropped/reset mid-request, so a retry may succeed.
|
|
73
|
+
return True
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class APIBadGateway(APIFailure):
|
|
77
|
+
"""Raised when the upstream server returns a 502 Bad Gateway error"""
|
|
78
|
+
|
|
79
|
+
def __init__(self, *args):
|
|
80
|
+
super().__init__(*args, status_code=502)
|
socketdev/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "3.
|
|
1
|
+
__version__ = "3.3.0"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
socketdev/__init__.py,sha256=mYuLIlXdU0uec1418LIw_oILBRh5DyWQDpWafaMa_AU,4484
|
|
2
|
-
socketdev/exceptions.py,sha256=
|
|
2
|
+
socketdev/exceptions.py,sha256=Z7OPZi7k8rRkKWrn9ck-wtAqP-NrXmVp9IqPuIsnziw,2793
|
|
3
3
|
socketdev/log.py,sha256=AgEcsPN3y9U-fze8pTFvLigVvNob2vmNC-TkOOQkkeQ,90
|
|
4
|
-
socketdev/version.py,sha256=
|
|
4
|
+
socketdev/version.py,sha256=MPSbkJS_-QSkLK7sMlFXFf5iWlbcSL18Dj2ZiMCtS9c,22
|
|
5
5
|
socketdev/alertfullscansearch/__init__.py,sha256=YwXrgnrI9z9rAexXFFmoXQcaQdGW47HRhQ58CQBCG3U,884
|
|
6
6
|
socketdev/alerts/__init__.py,sha256=kGLCNXtXTRz3vl2s_bPQ7xuds_QGwNQnah1TfHzp2MU,846
|
|
7
7
|
socketdev/alerttypes/__init__.py,sha256=W-m2D9VxbepSAUELJPmWmX40zksGZbQcSzwQ1kjlB1k,1169
|
|
@@ -9,7 +9,7 @@ socketdev/analytics/__init__.py,sha256=kQGeO67TraqvfmYjfpYCvcNRtxW2a6x5EefEl6Jnc
|
|
|
9
9
|
socketdev/apitokens/__init__.py,sha256=Z6W9Jkh4gdDeJBivfcONZuz7jRKZtxWLTi1n9gkbYVE,4222
|
|
10
10
|
socketdev/auditlog/__init__.py,sha256=vjcVtOK6oujqC6-RW5Hrvmth5BqFkLdinbeyqtycOpA,881
|
|
11
11
|
socketdev/basics/__init__.py,sha256=9jTEwC4dMUV-9pKpU4twK-hM1cY0xeXAxjDrb37sxoQ,4067
|
|
12
|
-
socketdev/core/api.py,sha256=
|
|
12
|
+
socketdev/core/api.py,sha256=cpHgS6d7rKfUSccoXsr_uKkbB60uSiPLs2pMYDN-9FU,6350
|
|
13
13
|
socketdev/core/classes.py,sha256=fyDlolgnkpHFb1dMHa2SA0czCS1I6Tr3SuYb1a67-dY,3756
|
|
14
14
|
socketdev/core/dedupe.py,sha256=bvX92ia4anVQtEv18LaLupisuHg68eNPuLZjmLhhAGE,5493
|
|
15
15
|
socketdev/core/issues.py,sha256=SKhJz7SrglozeuEk72CbbuCM7X0hgzNMk55uM4wX-TI,68081
|
|
@@ -39,7 +39,7 @@ socketdev/triage/__init__.py,sha256=-h599vThVetfRSOAs1e4IUoMjcXS8xOsUfub41XPiX4,
|
|
|
39
39
|
socketdev/uploadmanifests/__init__.py,sha256=-sFHbOW-aw7U0wRfEJT_Edrzx8aCbzD9cTGmVTNJKpw,6043
|
|
40
40
|
socketdev/utils/__init__.py,sha256=E11UJTsWsN-ZurOwtKvPGOTc9UMP3ND79nPbmNRRQ6E,17666
|
|
41
41
|
socketdev/webhooks/__init__.py,sha256=fme6K7ma_Gvk_TFOLz9jVcR5QJbDpMHXqRaU3x_RShY,3507
|
|
42
|
-
socketdev-3.
|
|
43
|
-
socketdev-3.
|
|
44
|
-
socketdev-3.
|
|
45
|
-
socketdev-3.
|
|
42
|
+
socketdev-3.3.0.dist-info/METADATA,sha256=2v-4ahE7hsJUpN91hbBU-iTPO_31lJZPgBd6ombW5yY,45557
|
|
43
|
+
socketdev-3.3.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
44
|
+
socketdev-3.3.0.dist-info/licenses/LICENSE,sha256=mC0II_UuE-_gCG9XqOLNyrV3crnROzMpdAetGnMrhpw,1068
|
|
45
|
+
socketdev-3.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|