socketdev 3.5.0__py3-none-any.whl → 3.6.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/__init__.py +115 -115
- socketdev/core/classes.py +148 -148
- socketdev/core/enums.py +35 -0
- socketdev/dependencies/__init__.py +53 -53
- socketdev/fullscans/__init__.py +40 -19
- socketdev/npm/__init__.py +28 -28
- socketdev/openapi/__init__.py +19 -19
- socketdev/org/__init__.py +34 -34
- socketdev/quota/__init__.py +19 -19
- socketdev/report/__init__.py +87 -87
- socketdev/repositories/__init__.py +31 -31
- socketdev/settings/__init__.py +182 -172
- socketdev/tools/__init__.py +65 -65
- socketdev/version.py +1 -1
- {socketdev-3.5.0.dist-info → socketdev-3.6.0.dist-info}/METADATA +2 -2
- {socketdev-3.5.0.dist-info → socketdev-3.6.0.dist-info}/RECORD +18 -17
- {socketdev-3.5.0.dist-info → socketdev-3.6.0.dist-info}/WHEEL +1 -1
- {socketdev-3.5.0.dist-info → socketdev-3.6.0.dist-info}/licenses/LICENSE +0 -0
socketdev/__init__.py
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from socketdev.core.api import API
|
|
3
|
-
from socketdev.dependencies import Dependencies
|
|
4
|
-
from socketdev.diffscans import DiffScans
|
|
5
|
-
from socketdev.export import Export
|
|
6
|
-
from socketdev.fullscans import FullScans
|
|
7
|
-
from socketdev.historical import Historical
|
|
8
|
-
from socketdev.npm import NPM
|
|
9
|
-
from socketdev.openapi import OpenAPI
|
|
10
|
-
from socketdev.org import Orgs
|
|
11
|
-
from socketdev.purl import Purl
|
|
12
|
-
from socketdev.quota import Quota
|
|
13
|
-
from socketdev.report import Report
|
|
14
|
-
from socketdev.repos import Repos
|
|
15
|
-
from socketdev.repositories import Repositories
|
|
16
|
-
from socketdev.sbom import Sbom
|
|
17
|
-
from socketdev.settings import Settings
|
|
18
|
-
from socketdev.triage import Triage
|
|
19
|
-
from socketdev.utils import Utils, IntegrationType, INTEGRATION_TYPES
|
|
20
|
-
from socketdev.version import __version__
|
|
21
|
-
from socketdev.labels import Labels
|
|
22
|
-
from socketdev.licensemetadata import LicenseMetadata
|
|
23
|
-
from socketdev.threatfeed import ThreatFeed
|
|
24
|
-
from socketdev.apitokens import ApiTokens
|
|
25
|
-
from socketdev.auditlog import AuditLog
|
|
26
|
-
from socketdev.analytics import Analytics
|
|
27
|
-
from socketdev.alerttypes import AlertTypes
|
|
28
|
-
from socketdev.basics import Basics
|
|
29
|
-
from socketdev.uploadmanifests import UploadManifests
|
|
30
|
-
from socketdev.alertfullscansearch import AlertFullScanSearch
|
|
31
|
-
from socketdev.alerts import Alerts
|
|
32
|
-
from socketdev.fixes import Fixes
|
|
33
|
-
from socketdev.supportedfiles import SupportedFiles
|
|
34
|
-
from socketdev.webhooks import Webhooks
|
|
35
|
-
from socketdev.telemetry import Telemetry
|
|
36
|
-
from socketdev.log import log
|
|
37
|
-
from typing import Optional
|
|
38
|
-
|
|
39
|
-
__author__ = "socket.dev"
|
|
40
|
-
__version__ = __version__
|
|
41
|
-
__all__ = ["socketdev", "Utils", "IntegrationType", "INTEGRATION_TYPES"]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
global encoded_key
|
|
45
|
-
encoded_key: str
|
|
46
|
-
|
|
47
|
-
api_url = "https://api.socket.dev/v0"
|
|
48
|
-
request_timeout = 1200
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# TODO: Add debug flag to constructor to enable verbose error logging for API response parsing.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
class socketdev:
|
|
55
|
-
def __init__(self, token: Optional[str] = None, timeout: int = 1200, allow_unverified: bool = False, user_agent: Optional[str] = None):
|
|
56
|
-
# Try to get token from environment variables if not provided
|
|
57
|
-
if token is None:
|
|
58
|
-
token = (
|
|
59
|
-
os.getenv("SOCKET_SECURITY_API_TOKEN") or
|
|
60
|
-
os.getenv("SOCKET_SECURITY_API_KEY") or
|
|
61
|
-
os.getenv("SOCKET_API_KEY") or
|
|
62
|
-
os.getenv("SOCKET_API_TOKEN")
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
if token is None:
|
|
66
|
-
raise ValueError(
|
|
67
|
-
"API token is required. Provide it as a parameter or set one of these environment variables: "
|
|
68
|
-
"SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY, SOCKET_API_KEY, SOCKET_API_TOKEN"
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
self.api = API()
|
|
72
|
-
self.token = token + ":"
|
|
73
|
-
self.api.encode_key(self.token)
|
|
74
|
-
self.api.set_timeout(timeout)
|
|
75
|
-
self.api.set_allow_unverified(allow_unverified)
|
|
76
|
-
if user_agent is not None:
|
|
77
|
-
self.api.set_user_agent(user_agent)
|
|
78
|
-
|
|
79
|
-
self.dependencies = Dependencies(self.api)
|
|
80
|
-
self.export = Export(self.api)
|
|
81
|
-
self.fullscans = FullScans(self.api)
|
|
82
|
-
self.historical = Historical(self.api)
|
|
83
|
-
self.npm = NPM(self.api)
|
|
84
|
-
self.openapi = OpenAPI(self.api)
|
|
85
|
-
self.org = Orgs(self.api)
|
|
86
|
-
self.purl = Purl(self.api)
|
|
87
|
-
self.quota = Quota(self.api)
|
|
88
|
-
self.report = Report(self.api)
|
|
89
|
-
self.repos = Repos(self.api)
|
|
90
|
-
self.repositories = Repositories(self.api)
|
|
91
|
-
self.sbom = Sbom(self.api)
|
|
92
|
-
self.settings = Settings(self.api)
|
|
93
|
-
self.triage = Triage(self.api)
|
|
94
|
-
self.utils = Utils()
|
|
95
|
-
self.labels = Labels(self.api)
|
|
96
|
-
self.licensemetadata = LicenseMetadata(self.api)
|
|
97
|
-
self.diffscans = DiffScans(self.api)
|
|
98
|
-
self.threatfeed = ThreatFeed(self.api)
|
|
99
|
-
self.apitokens = ApiTokens(self.api)
|
|
100
|
-
self.auditlog = AuditLog(self.api)
|
|
101
|
-
self.analytics = Analytics(self.api)
|
|
102
|
-
self.alerttypes = AlertTypes(self.api)
|
|
103
|
-
self.basics = Basics(self.api)
|
|
104
|
-
self.uploadmanifests = UploadManifests(self.api)
|
|
105
|
-
self.alertfullscansearch = AlertFullScanSearch(self.api)
|
|
106
|
-
self.alerts = Alerts(self.api)
|
|
107
|
-
self.fixes = Fixes(self.api)
|
|
108
|
-
self.supportedfiles = SupportedFiles(self.api)
|
|
109
|
-
self.webhooks = Webhooks(self.api)
|
|
110
|
-
self.telemetry = Telemetry(self.api)
|
|
111
|
-
|
|
112
|
-
@staticmethod
|
|
113
|
-
def set_timeout(timeout: int):
|
|
114
|
-
# Kept for backwards compatibility
|
|
115
|
-
pass
|
|
1
|
+
import os
|
|
2
|
+
from socketdev.core.api import API
|
|
3
|
+
from socketdev.dependencies import Dependencies
|
|
4
|
+
from socketdev.diffscans import DiffScans
|
|
5
|
+
from socketdev.export import Export
|
|
6
|
+
from socketdev.fullscans import FullScans
|
|
7
|
+
from socketdev.historical import Historical
|
|
8
|
+
from socketdev.npm import NPM
|
|
9
|
+
from socketdev.openapi import OpenAPI
|
|
10
|
+
from socketdev.org import Orgs
|
|
11
|
+
from socketdev.purl import Purl
|
|
12
|
+
from socketdev.quota import Quota
|
|
13
|
+
from socketdev.report import Report
|
|
14
|
+
from socketdev.repos import Repos
|
|
15
|
+
from socketdev.repositories import Repositories
|
|
16
|
+
from socketdev.sbom import Sbom
|
|
17
|
+
from socketdev.settings import Settings
|
|
18
|
+
from socketdev.triage import Triage
|
|
19
|
+
from socketdev.utils import Utils, IntegrationType, INTEGRATION_TYPES
|
|
20
|
+
from socketdev.version import __version__
|
|
21
|
+
from socketdev.labels import Labels
|
|
22
|
+
from socketdev.licensemetadata import LicenseMetadata
|
|
23
|
+
from socketdev.threatfeed import ThreatFeed
|
|
24
|
+
from socketdev.apitokens import ApiTokens
|
|
25
|
+
from socketdev.auditlog import AuditLog
|
|
26
|
+
from socketdev.analytics import Analytics
|
|
27
|
+
from socketdev.alerttypes import AlertTypes
|
|
28
|
+
from socketdev.basics import Basics
|
|
29
|
+
from socketdev.uploadmanifests import UploadManifests
|
|
30
|
+
from socketdev.alertfullscansearch import AlertFullScanSearch
|
|
31
|
+
from socketdev.alerts import Alerts
|
|
32
|
+
from socketdev.fixes import Fixes
|
|
33
|
+
from socketdev.supportedfiles import SupportedFiles
|
|
34
|
+
from socketdev.webhooks import Webhooks
|
|
35
|
+
from socketdev.telemetry import Telemetry
|
|
36
|
+
from socketdev.log import log
|
|
37
|
+
from typing import Optional
|
|
38
|
+
|
|
39
|
+
__author__ = "socket.dev"
|
|
40
|
+
__version__ = __version__
|
|
41
|
+
__all__ = ["socketdev", "Utils", "IntegrationType", "INTEGRATION_TYPES"]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
global encoded_key
|
|
45
|
+
encoded_key: str
|
|
46
|
+
|
|
47
|
+
api_url = "https://api.socket.dev/v0"
|
|
48
|
+
request_timeout = 1200
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# TODO: Add debug flag to constructor to enable verbose error logging for API response parsing.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class socketdev:
|
|
55
|
+
def __init__(self, token: Optional[str] = None, timeout: int = 1200, allow_unverified: bool = False, user_agent: Optional[str] = None):
|
|
56
|
+
# Try to get token from environment variables if not provided
|
|
57
|
+
if token is None:
|
|
58
|
+
token = (
|
|
59
|
+
os.getenv("SOCKET_SECURITY_API_TOKEN") or
|
|
60
|
+
os.getenv("SOCKET_SECURITY_API_KEY") or
|
|
61
|
+
os.getenv("SOCKET_API_KEY") or
|
|
62
|
+
os.getenv("SOCKET_API_TOKEN")
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if token is None:
|
|
66
|
+
raise ValueError(
|
|
67
|
+
"API token is required. Provide it as a parameter or set one of these environment variables: "
|
|
68
|
+
"SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY, SOCKET_API_KEY, SOCKET_API_TOKEN"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
self.api = API()
|
|
72
|
+
self.token = token + ":"
|
|
73
|
+
self.api.encode_key(self.token)
|
|
74
|
+
self.api.set_timeout(timeout)
|
|
75
|
+
self.api.set_allow_unverified(allow_unverified)
|
|
76
|
+
if user_agent is not None:
|
|
77
|
+
self.api.set_user_agent(user_agent)
|
|
78
|
+
|
|
79
|
+
self.dependencies = Dependencies(self.api)
|
|
80
|
+
self.export = Export(self.api)
|
|
81
|
+
self.fullscans = FullScans(self.api)
|
|
82
|
+
self.historical = Historical(self.api)
|
|
83
|
+
self.npm = NPM(self.api)
|
|
84
|
+
self.openapi = OpenAPI(self.api)
|
|
85
|
+
self.org = Orgs(self.api)
|
|
86
|
+
self.purl = Purl(self.api)
|
|
87
|
+
self.quota = Quota(self.api)
|
|
88
|
+
self.report = Report(self.api)
|
|
89
|
+
self.repos = Repos(self.api)
|
|
90
|
+
self.repositories = Repositories(self.api)
|
|
91
|
+
self.sbom = Sbom(self.api)
|
|
92
|
+
self.settings = Settings(self.api)
|
|
93
|
+
self.triage = Triage(self.api)
|
|
94
|
+
self.utils = Utils()
|
|
95
|
+
self.labels = Labels(self.api)
|
|
96
|
+
self.licensemetadata = LicenseMetadata(self.api)
|
|
97
|
+
self.diffscans = DiffScans(self.api)
|
|
98
|
+
self.threatfeed = ThreatFeed(self.api)
|
|
99
|
+
self.apitokens = ApiTokens(self.api)
|
|
100
|
+
self.auditlog = AuditLog(self.api)
|
|
101
|
+
self.analytics = Analytics(self.api)
|
|
102
|
+
self.alerttypes = AlertTypes(self.api)
|
|
103
|
+
self.basics = Basics(self.api)
|
|
104
|
+
self.uploadmanifests = UploadManifests(self.api)
|
|
105
|
+
self.alertfullscansearch = AlertFullScanSearch(self.api)
|
|
106
|
+
self.alerts = Alerts(self.api)
|
|
107
|
+
self.fixes = Fixes(self.api)
|
|
108
|
+
self.supportedfiles = SupportedFiles(self.api)
|
|
109
|
+
self.webhooks = Webhooks(self.api)
|
|
110
|
+
self.telemetry = Telemetry(self.api)
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def set_timeout(timeout: int):
|
|
114
|
+
# Kept for backwards compatibility
|
|
115
|
+
pass
|
socketdev/core/classes.py
CHANGED
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
import json
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Score:
|
|
5
|
-
supplyChain: float
|
|
6
|
-
quality: float
|
|
7
|
-
maintenance: float
|
|
8
|
-
license: float
|
|
9
|
-
overall: float
|
|
10
|
-
vulnerability: float
|
|
11
|
-
|
|
12
|
-
def __init__(self, **kwargs):
|
|
13
|
-
if kwargs:
|
|
14
|
-
for key, value in kwargs.items():
|
|
15
|
-
setattr(self, key, value)
|
|
16
|
-
for score_name in self.__dict__:
|
|
17
|
-
score = getattr(self, score_name)
|
|
18
|
-
if score <= 1:
|
|
19
|
-
score = score * 100
|
|
20
|
-
setattr(self, score_name, score)
|
|
21
|
-
|
|
22
|
-
def __str__(self):
|
|
23
|
-
return json.dumps(self.__dict__)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class Package:
|
|
27
|
-
type: str
|
|
28
|
-
name: str
|
|
29
|
-
version: str
|
|
30
|
-
release: str
|
|
31
|
-
id: str
|
|
32
|
-
direct: bool
|
|
33
|
-
manifestFiles: list
|
|
34
|
-
author: list
|
|
35
|
-
size: int
|
|
36
|
-
score: dict
|
|
37
|
-
scores: Score
|
|
38
|
-
alerts: list
|
|
39
|
-
error_alerts: list
|
|
40
|
-
alert_counts: dict
|
|
41
|
-
topLevelAncestors: list
|
|
42
|
-
url: str
|
|
43
|
-
transitives: int
|
|
44
|
-
license: str
|
|
45
|
-
license_text: str
|
|
46
|
-
purl: str
|
|
47
|
-
|
|
48
|
-
def __init__(self, **kwargs):
|
|
49
|
-
if kwargs:
|
|
50
|
-
for key, value in kwargs.items():
|
|
51
|
-
setattr(self, key, value)
|
|
52
|
-
if not hasattr(self, "direct"):
|
|
53
|
-
self.direct = False
|
|
54
|
-
else:
|
|
55
|
-
if str(self.direct).lower() == "true":
|
|
56
|
-
self.direct = True
|
|
57
|
-
self.url = f"https://socket.dev/{self.type}/package/{self.name}/overview/{self.version}"
|
|
58
|
-
if hasattr(self, 'score'):
|
|
59
|
-
self.scores = Score(**self.score)
|
|
60
|
-
if not hasattr(self, "alerts"):
|
|
61
|
-
self.alerts = []
|
|
62
|
-
if not hasattr(self, "topLevelAncestors"):
|
|
63
|
-
self.topLevelAncestors = []
|
|
64
|
-
if not hasattr(self, "manifestFiles"):
|
|
65
|
-
self.manifestFiles = []
|
|
66
|
-
if not hasattr(self, "transitives"):
|
|
67
|
-
self.transitives = 0
|
|
68
|
-
if not hasattr(self, "author"):
|
|
69
|
-
self.author = []
|
|
70
|
-
if not hasattr(self, "size"):
|
|
71
|
-
self.size = 0
|
|
72
|
-
self.alert_counts = {
|
|
73
|
-
"critical": 0,
|
|
74
|
-
"high": 0,
|
|
75
|
-
"middle": 0,
|
|
76
|
-
"low": 0
|
|
77
|
-
}
|
|
78
|
-
self.error_alerts = []
|
|
79
|
-
if not hasattr(self, "license"):
|
|
80
|
-
self.license = "NoLicenseFound"
|
|
81
|
-
if not hasattr(self, "license_text"):
|
|
82
|
-
self.license_text = ""
|
|
83
|
-
self.url = f"https://socket.dev/{self.type}/package/{self.name}/overview/{self.version}"
|
|
84
|
-
self.purl = f"{self.type}/{self.name}@{self.version}"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
class Dependency:
|
|
88
|
-
branch: str
|
|
89
|
-
id: int
|
|
90
|
-
name: str
|
|
91
|
-
type: str
|
|
92
|
-
version: str
|
|
93
|
-
namespace: str
|
|
94
|
-
repository: str
|
|
95
|
-
|
|
96
|
-
def __init__(self, **kwargs):
|
|
97
|
-
if kwargs:
|
|
98
|
-
for key, value in kwargs.items():
|
|
99
|
-
setattr(self, key, value)
|
|
100
|
-
|
|
101
|
-
def __str__(self):
|
|
102
|
-
return json.dumps(self.__dict__)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
class Org:
|
|
106
|
-
id: int
|
|
107
|
-
image: str
|
|
108
|
-
name: str
|
|
109
|
-
plan: str
|
|
110
|
-
|
|
111
|
-
def __init__(self, **kwargs):
|
|
112
|
-
if kwargs:
|
|
113
|
-
for key, value in kwargs.items():
|
|
114
|
-
setattr(self, key, value)
|
|
115
|
-
|
|
116
|
-
def __str__(self):
|
|
117
|
-
return json.dumps(self.__dict__)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
class Response:
|
|
121
|
-
text: str
|
|
122
|
-
error: bool
|
|
123
|
-
status_code: int
|
|
124
|
-
|
|
125
|
-
def __init__(self, text: str, error: bool, status_code: int):
|
|
126
|
-
self.text = text
|
|
127
|
-
self.error = error
|
|
128
|
-
self.status_code = status_code
|
|
129
|
-
|
|
130
|
-
def __str__(self):
|
|
131
|
-
return json.dumps(self.__dict__)
|
|
132
|
-
|
|
133
|
-
def json(self):
|
|
134
|
-
return self.__dict__
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
class DependGetData:
|
|
138
|
-
url: str
|
|
139
|
-
headers: dict
|
|
140
|
-
payload: str
|
|
141
|
-
|
|
142
|
-
def __init__(self, **kwargs):
|
|
143
|
-
if kwargs:
|
|
144
|
-
for key, value in kwargs.items():
|
|
145
|
-
setattr(self, key, value)
|
|
146
|
-
|
|
147
|
-
def __str__(self):
|
|
148
|
-
return json.dumps(self.__dict__)
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Score:
|
|
5
|
+
supplyChain: float
|
|
6
|
+
quality: float
|
|
7
|
+
maintenance: float
|
|
8
|
+
license: float
|
|
9
|
+
overall: float
|
|
10
|
+
vulnerability: float
|
|
11
|
+
|
|
12
|
+
def __init__(self, **kwargs):
|
|
13
|
+
if kwargs:
|
|
14
|
+
for key, value in kwargs.items():
|
|
15
|
+
setattr(self, key, value)
|
|
16
|
+
for score_name in self.__dict__:
|
|
17
|
+
score = getattr(self, score_name)
|
|
18
|
+
if score <= 1:
|
|
19
|
+
score = score * 100
|
|
20
|
+
setattr(self, score_name, score)
|
|
21
|
+
|
|
22
|
+
def __str__(self):
|
|
23
|
+
return json.dumps(self.__dict__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Package:
|
|
27
|
+
type: str
|
|
28
|
+
name: str
|
|
29
|
+
version: str
|
|
30
|
+
release: str
|
|
31
|
+
id: str
|
|
32
|
+
direct: bool
|
|
33
|
+
manifestFiles: list
|
|
34
|
+
author: list
|
|
35
|
+
size: int
|
|
36
|
+
score: dict
|
|
37
|
+
scores: Score
|
|
38
|
+
alerts: list
|
|
39
|
+
error_alerts: list
|
|
40
|
+
alert_counts: dict
|
|
41
|
+
topLevelAncestors: list
|
|
42
|
+
url: str
|
|
43
|
+
transitives: int
|
|
44
|
+
license: str
|
|
45
|
+
license_text: str
|
|
46
|
+
purl: str
|
|
47
|
+
|
|
48
|
+
def __init__(self, **kwargs):
|
|
49
|
+
if kwargs:
|
|
50
|
+
for key, value in kwargs.items():
|
|
51
|
+
setattr(self, key, value)
|
|
52
|
+
if not hasattr(self, "direct"):
|
|
53
|
+
self.direct = False
|
|
54
|
+
else:
|
|
55
|
+
if str(self.direct).lower() == "true":
|
|
56
|
+
self.direct = True
|
|
57
|
+
self.url = f"https://socket.dev/{self.type}/package/{self.name}/overview/{self.version}"
|
|
58
|
+
if hasattr(self, 'score'):
|
|
59
|
+
self.scores = Score(**self.score)
|
|
60
|
+
if not hasattr(self, "alerts"):
|
|
61
|
+
self.alerts = []
|
|
62
|
+
if not hasattr(self, "topLevelAncestors"):
|
|
63
|
+
self.topLevelAncestors = []
|
|
64
|
+
if not hasattr(self, "manifestFiles"):
|
|
65
|
+
self.manifestFiles = []
|
|
66
|
+
if not hasattr(self, "transitives"):
|
|
67
|
+
self.transitives = 0
|
|
68
|
+
if not hasattr(self, "author"):
|
|
69
|
+
self.author = []
|
|
70
|
+
if not hasattr(self, "size"):
|
|
71
|
+
self.size = 0
|
|
72
|
+
self.alert_counts = {
|
|
73
|
+
"critical": 0,
|
|
74
|
+
"high": 0,
|
|
75
|
+
"middle": 0,
|
|
76
|
+
"low": 0
|
|
77
|
+
}
|
|
78
|
+
self.error_alerts = []
|
|
79
|
+
if not hasattr(self, "license"):
|
|
80
|
+
self.license = "NoLicenseFound"
|
|
81
|
+
if not hasattr(self, "license_text"):
|
|
82
|
+
self.license_text = ""
|
|
83
|
+
self.url = f"https://socket.dev/{self.type}/package/{self.name}/overview/{self.version}"
|
|
84
|
+
self.purl = f"{self.type}/{self.name}@{self.version}"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class Dependency:
|
|
88
|
+
branch: str
|
|
89
|
+
id: int
|
|
90
|
+
name: str
|
|
91
|
+
type: str
|
|
92
|
+
version: str
|
|
93
|
+
namespace: str
|
|
94
|
+
repository: str
|
|
95
|
+
|
|
96
|
+
def __init__(self, **kwargs):
|
|
97
|
+
if kwargs:
|
|
98
|
+
for key, value in kwargs.items():
|
|
99
|
+
setattr(self, key, value)
|
|
100
|
+
|
|
101
|
+
def __str__(self):
|
|
102
|
+
return json.dumps(self.__dict__)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class Org:
|
|
106
|
+
id: int
|
|
107
|
+
image: str
|
|
108
|
+
name: str
|
|
109
|
+
plan: str
|
|
110
|
+
|
|
111
|
+
def __init__(self, **kwargs):
|
|
112
|
+
if kwargs:
|
|
113
|
+
for key, value in kwargs.items():
|
|
114
|
+
setattr(self, key, value)
|
|
115
|
+
|
|
116
|
+
def __str__(self):
|
|
117
|
+
return json.dumps(self.__dict__)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class Response:
|
|
121
|
+
text: str
|
|
122
|
+
error: bool
|
|
123
|
+
status_code: int
|
|
124
|
+
|
|
125
|
+
def __init__(self, text: str, error: bool, status_code: int):
|
|
126
|
+
self.text = text
|
|
127
|
+
self.error = error
|
|
128
|
+
self.status_code = status_code
|
|
129
|
+
|
|
130
|
+
def __str__(self):
|
|
131
|
+
return json.dumps(self.__dict__)
|
|
132
|
+
|
|
133
|
+
def json(self):
|
|
134
|
+
return self.__dict__
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class DependGetData:
|
|
138
|
+
url: str
|
|
139
|
+
headers: dict
|
|
140
|
+
payload: str
|
|
141
|
+
|
|
142
|
+
def __init__(self, **kwargs):
|
|
143
|
+
if kwargs:
|
|
144
|
+
for key, value in kwargs.items():
|
|
145
|
+
setattr(self, key, value)
|
|
146
|
+
|
|
147
|
+
def __str__(self):
|
|
148
|
+
return json.dumps(self.__dict__)
|
socketdev/core/enums.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Forward-compatibility helpers for enums sourced from the Socket API.
|
|
2
|
+
|
|
3
|
+
The Socket API adds values to its enums (purl types, alert categories, policy
|
|
4
|
+
actions) without a corresponding SDK release. When a strict ``Enum`` coercion
|
|
5
|
+
meets one of those values it raises ``ValueError``, and because coercion happens
|
|
6
|
+
inside ``from_dict`` that error takes down the whole response parse rather than
|
|
7
|
+
the single field it applies to. That is how issue #78 (an unknown
|
|
8
|
+
``SocketCategory``) and the unknown ``generic`` purl type each produced
|
|
9
|
+
empty reports from otherwise-successful scans.
|
|
10
|
+
|
|
11
|
+
Every enum in this package that is populated from an API response therefore
|
|
12
|
+
defines ``_missing_`` and falls back to a documented sentinel instead of
|
|
13
|
+
raising. ``tests/unit/test_enum_forward_compat.py`` enforces that as an
|
|
14
|
+
invariant across the package, including for enums added later.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
|
|
19
|
+
log = logging.getLogger("socketdev")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def unknown_enum_value(enum_name: str, value: object, fallback):
|
|
23
|
+
"""Log an unrecognized API enum value and return the enum's fallback member.
|
|
24
|
+
|
|
25
|
+
Callers are ``_missing_`` implementations, so returning ``fallback`` is what
|
|
26
|
+
turns the would-be ``ValueError`` into a usable member.
|
|
27
|
+
"""
|
|
28
|
+
log.warning(
|
|
29
|
+
"Unknown %s %r; falling back to %s. "
|
|
30
|
+
"Upgrade socketdev to pick up newer values.",
|
|
31
|
+
enum_name,
|
|
32
|
+
value,
|
|
33
|
+
fallback.name,
|
|
34
|
+
)
|
|
35
|
+
return fallback
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from urllib.parse import urlencode
|
|
3
|
-
import logging
|
|
4
|
-
from socketdev.tools import load_files
|
|
5
|
-
from ..utils import Utils
|
|
6
|
-
|
|
7
|
-
log = logging.getLogger("socketdev")
|
|
8
|
-
|
|
9
|
-
# TODO: Add types for responses. Not currently used in the CLI.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Dependencies:
|
|
13
|
-
def __init__(self, api):
|
|
14
|
-
self.api = api
|
|
15
|
-
|
|
16
|
-
def post(self, files: list, params: dict, use_lazy_loading: bool = True, workspace: str = None, base_path: str = None) -> dict:
|
|
17
|
-
if use_lazy_loading:
|
|
18
|
-
loaded_files = Utils.load_files_for_sending_lazy(files, workspace, base_path=base_path)
|
|
19
|
-
else:
|
|
20
|
-
loaded_files = []
|
|
21
|
-
loaded_files = load_files(files, loaded_files)
|
|
22
|
-
|
|
23
|
-
path = "dependencies/upload?" + urlencode(params)
|
|
24
|
-
response = self.api.do_request(path=path, files=loaded_files, method="POST")
|
|
25
|
-
if response.status_code == 200:
|
|
26
|
-
result = response.json()
|
|
27
|
-
else:
|
|
28
|
-
result = {}
|
|
29
|
-
log.error(f"Error posting {files} to the Dependency API")
|
|
30
|
-
log.error(response.text)
|
|
31
|
-
return result
|
|
32
|
-
|
|
33
|
-
def get(self, org_slug: str = None, ecosystem: str = None, package: str = None, version: str = None, **kwargs) -> dict:
|
|
34
|
-
# If all specific parameters are provided, use the specific dependency endpoint
|
|
35
|
-
if org_slug and ecosystem and package and version:
|
|
36
|
-
path = f"orgs/{org_slug}/dependencies/{ecosystem}/{package}/{version}"
|
|
37
|
-
response = self.api.do_request(path=path, method="GET")
|
|
38
|
-
else:
|
|
39
|
-
# Otherwise use the search endpoint
|
|
40
|
-
limit = kwargs.get('limit', 50)
|
|
41
|
-
offset = kwargs.get('offset', 0)
|
|
42
|
-
path = "dependencies/search"
|
|
43
|
-
payload = {"limit": limit, "offset": offset}
|
|
44
|
-
payload_str = json.dumps(payload)
|
|
45
|
-
response = self.api.do_request(path=path, method="POST", payload=payload_str)
|
|
46
|
-
|
|
47
|
-
if response.status_code == 200:
|
|
48
|
-
result = response.json()
|
|
49
|
-
else:
|
|
50
|
-
result = {}
|
|
51
|
-
log.error("Unable to retrieve Dependencies")
|
|
52
|
-
log.error(response.text)
|
|
53
|
-
return result
|
|
1
|
+
import json
|
|
2
|
+
from urllib.parse import urlencode
|
|
3
|
+
import logging
|
|
4
|
+
from socketdev.tools import load_files
|
|
5
|
+
from ..utils import Utils
|
|
6
|
+
|
|
7
|
+
log = logging.getLogger("socketdev")
|
|
8
|
+
|
|
9
|
+
# TODO: Add types for responses. Not currently used in the CLI.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Dependencies:
|
|
13
|
+
def __init__(self, api):
|
|
14
|
+
self.api = api
|
|
15
|
+
|
|
16
|
+
def post(self, files: list, params: dict, use_lazy_loading: bool = True, workspace: str = None, base_path: str = None) -> dict:
|
|
17
|
+
if use_lazy_loading:
|
|
18
|
+
loaded_files = Utils.load_files_for_sending_lazy(files, workspace, base_path=base_path)
|
|
19
|
+
else:
|
|
20
|
+
loaded_files = []
|
|
21
|
+
loaded_files = load_files(files, loaded_files)
|
|
22
|
+
|
|
23
|
+
path = "dependencies/upload?" + urlencode(params)
|
|
24
|
+
response = self.api.do_request(path=path, files=loaded_files, method="POST")
|
|
25
|
+
if response.status_code == 200:
|
|
26
|
+
result = response.json()
|
|
27
|
+
else:
|
|
28
|
+
result = {}
|
|
29
|
+
log.error(f"Error posting {files} to the Dependency API")
|
|
30
|
+
log.error(response.text)
|
|
31
|
+
return result
|
|
32
|
+
|
|
33
|
+
def get(self, org_slug: str = None, ecosystem: str = None, package: str = None, version: str = None, **kwargs) -> dict:
|
|
34
|
+
# If all specific parameters are provided, use the specific dependency endpoint
|
|
35
|
+
if org_slug and ecosystem and package and version:
|
|
36
|
+
path = f"orgs/{org_slug}/dependencies/{ecosystem}/{package}/{version}"
|
|
37
|
+
response = self.api.do_request(path=path, method="GET")
|
|
38
|
+
else:
|
|
39
|
+
# Otherwise use the search endpoint
|
|
40
|
+
limit = kwargs.get('limit', 50)
|
|
41
|
+
offset = kwargs.get('offset', 0)
|
|
42
|
+
path = "dependencies/search"
|
|
43
|
+
payload = {"limit": limit, "offset": offset}
|
|
44
|
+
payload_str = json.dumps(payload)
|
|
45
|
+
response = self.api.do_request(path=path, method="POST", payload=payload_str)
|
|
46
|
+
|
|
47
|
+
if response.status_code == 200:
|
|
48
|
+
result = response.json()
|
|
49
|
+
else:
|
|
50
|
+
result = {}
|
|
51
|
+
log.error("Unable to retrieve Dependencies")
|
|
52
|
+
log.error(response.text)
|
|
53
|
+
return result
|