Skip to content

Commit bb7b16f

Browse files
typicodejdalton
andauthored
Port socket-python-cli (#268)
* wip * wip * wip * refactor, use octokit, parseArgs, move shell logic to JS * wip * wip * wip * wip * wip * WIP * wip * fix-deps * update * fix-deps * cleanup * lint fix scm_comments * lint fix messages * fix last lint issues * fix check:lint errors --------- Signed-off-by: typicode <[email protected]> Signed-off-by: John-David Dalton <[email protected]> Co-authored-by: John-David Dalton <[email protected]>
1 parent c9c1a20 commit bb7b16f

File tree

11 files changed

+3632
-1
lines changed

11 files changed

+3632
-1
lines changed

package-lock.json

Lines changed: 344 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@
6363
"@apideck/better-ajv-errors": "^0.3.6",
6464
"@cyclonedx/cdxgen": "^11.1.7",
6565
"@npmcli/promise-spawn": "^8.0.2",
66+
"@octokit/rest": "^21.1.0",
6667
"@socketregistry/hyrious__bun.lockb": "^1.0.12",
6768
"@socketregistry/indent-string": "^1.0.9",
6869
"@socketregistry/is-interactive": "^1.0.1",
6970
"@socketregistry/is-unicode-supported": "^1.0.0",
71+
"@socketregistry/packageurl-js": "^1.0.2",
7072
"@socketsecurity/config": "^2.1.3",
7173
"@socketsecurity/registry": "^1.0.81",
7274
"@socketsecurity/sdk": "^1.4.5",
@@ -80,10 +82,12 @@
8082
"ignore": "^7.0.3",
8183
"meow": "^13.2.0",
8284
"micromatch": "^4.0.8",
85+
"ndjson": "^2.0.0",
8386
"npm-package-arg": "^12.0.1",
8487
"open": "^10.1.0",
8588
"pony-cause": "^2.1.11",
8689
"semver": "^7.7.0",
90+
"simple-git": "^3.27.0",
8791
"synp": "^1.9.14",
8892
"terminal-link": "2.1.1",
8993
"tiny-updater": "^3.5.3",
@@ -115,6 +119,7 @@
115119
"@types/micromatch": "^4.0.9",
116120
"@types/mocha": "^10.0.10",
117121
"@types/mock-fs": "^4.13.4",
122+
"@types/ndjson": "^2.0.4",
118123
"@types/node": "^22.13.0",
119124
"@types/npmcli__arborist": "^6.3.0",
120125
"@types/npmcli__promise-spawn": "^6.0.3",

src/commands/action/core/alerts.json

Lines changed: 1001 additions & 0 deletions
Large diffs are not rendered by default.

src/commands/action/core/classes.ts

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/classes.py
2+
import { components } from '@socketsecurity/sdk/types/api'
3+
4+
type IntroducedBy = [string, string][]
5+
6+
export class Alert {
7+
key = ''
8+
type = ''
9+
severity = ''
10+
category = ''
11+
props = {}
12+
13+
constructor(arg: Partial<Alert> = {}) {
14+
this.key = arg.key ?? this.key
15+
this.type = arg.type ?? this.type
16+
this.severity = arg.severity ?? this.severity
17+
this.category = arg.category ?? this.category
18+
this.props = arg.props ?? this.props
19+
}
20+
}
21+
22+
export class Comment {
23+
id = 0
24+
body = ''
25+
body_list: string[] = []
26+
27+
constructor(arg: Comment) {
28+
this.id = arg.id ?? this.id
29+
this.body = arg.body ?? this.body
30+
this.body_list = arg.body_list ?? this.body_list
31+
}
32+
}
33+
34+
export class Diff {
35+
newPackages: Purl[] = []
36+
newCapabilities: Record<string, any> = {}
37+
removedPackages: Purl[] = []
38+
newAlerts: Issue[] = []
39+
id = ''
40+
sbom = ''
41+
packages: Record<string, Package> = {}
42+
reportUrl = ''
43+
diffUrl = ''
44+
}
45+
46+
export class FullScan {
47+
id = ''
48+
created_at = ''
49+
updated_at = ''
50+
organizationId = ''
51+
repositoryId = ''
52+
branch = ''
53+
commit_message = ''
54+
commit_hash = ''
55+
pull_request = 0
56+
sbom_artifacts: components['schemas']['SocketArtifact'][] = []
57+
packages = {}
58+
59+
constructor(obj: Partial<FullScan> = {}) {
60+
this.id = obj.id ?? this.id
61+
this.created_at = obj.created_at ?? this.created_at
62+
this.updated_at = obj.updated_at ?? this.updated_at
63+
this.organizationId = obj.organizationId ?? this.organizationId
64+
this.repositoryId = obj.repositoryId ?? this.repositoryId
65+
this.branch = obj.branch ?? this.branch
66+
this.commit_message = obj.commit_message ?? this.commit_message
67+
this.commit_hash = obj.commit_hash ?? this.commit_hash
68+
this.pull_request = obj.pull_request ?? this.pull_request
69+
this.sbom_artifacts = obj.sbom_artifacts ?? this.sbom_artifacts
70+
this.packages = obj.packages ?? this.packages
71+
}
72+
}
73+
74+
export class Issue {
75+
pkg_type = ''
76+
pkg_name = ''
77+
pkg_version = ''
78+
category = ''
79+
type = ''
80+
severity = ''
81+
pkg_id = ''
82+
props = {}
83+
key = ''
84+
error = false
85+
warn = false
86+
ignore = false
87+
monitor = false
88+
description = ''
89+
title = ''
90+
emoji = ''
91+
next_step_title = ''
92+
suggestion = ''
93+
introduced_by: IntroducedBy = []
94+
manifests = ''
95+
url = ''
96+
purl = ''
97+
98+
constructor(arg: {
99+
pkg_type: string | undefined
100+
pkg_name: string | undefined
101+
pkg_version: string | undefined
102+
type: string | undefined
103+
severity: string | undefined
104+
pkg_id: string | undefined
105+
props: Record<string, any> | undefined
106+
key: string | undefined
107+
error: boolean | undefined
108+
warn: boolean | undefined
109+
ignore: boolean | undefined
110+
monitor: boolean | undefined
111+
description: string | undefined
112+
title: string | undefined
113+
next_step_title: string | undefined
114+
suggestion: string | undefined
115+
introduced_by: IntroducedBy | undefined
116+
url: string | undefined
117+
purl: string | undefined
118+
}) {
119+
this.pkg_type = arg.pkg_type ?? this.pkg_type
120+
this.pkg_name = arg.pkg_name ?? this.pkg_name
121+
this.pkg_version = arg.pkg_version ?? this.pkg_version
122+
this.type = arg.type ?? this.type
123+
this.severity = arg.severity ?? this.severity
124+
this.pkg_id = arg.pkg_id ?? this.pkg_id
125+
this.props = arg.props ?? this.props
126+
this.key = arg.key ?? this.key
127+
this.error = arg.error ?? this.error
128+
this.warn = arg.warn ?? this.warn
129+
this.ignore = arg.ignore ?? this.ignore
130+
this.monitor = arg.monitor ?? this.monitor
131+
this.description = arg.description ?? this.description
132+
this.title = arg.title ?? this.title
133+
this.next_step_title = arg.next_step_title ?? this.next_step_title
134+
this.suggestion = arg.suggestion ?? this.suggestion
135+
136+
if (arg.introduced_by) {
137+
const arr = []
138+
for (const item of arg.introduced_by) {
139+
const [, manifest] = item
140+
arr.push(manifest)
141+
}
142+
this.manifests = arr.join(';')
143+
}
144+
}
145+
}
146+
147+
export class Package {
148+
type = ''
149+
name = ''
150+
version = ''
151+
release = ''
152+
id = ''
153+
direct = false
154+
manifestFiles: { file: string }[] = []
155+
author: string[] = []
156+
size = 0
157+
score: Score
158+
scores = {}
159+
alerts: NonNullable<components['schemas']['SocketArtifact']['alerts']> = []
160+
alert_counts = {}
161+
topLevelAncestors: string[] = []
162+
url = ''
163+
transitives = 0
164+
license = 'NoLicenseFound'
165+
license_text = ''
166+
purl = ''
167+
168+
constructor(arg: {
169+
type: string | undefined
170+
name: string | undefined
171+
version: string | undefined
172+
release: string | undefined
173+
id: string | undefined
174+
direct: boolean | undefined
175+
manifestFiles: { file: string }[] | undefined
176+
author: string[] | undefined
177+
size: number | undefined
178+
score: Score | undefined
179+
alerts: components['schemas']['SocketArtifact']['alerts'] | undefined
180+
topLevelAncestors: string[] | undefined
181+
license: string | undefined
182+
}) {
183+
this.type = arg.type ?? this.type
184+
this.name = arg.name ?? this.name
185+
this.version = arg.version ?? this.version
186+
this.release = arg.release ?? this.release
187+
this.id = arg.id ?? this.id
188+
this.manifestFiles = arg.manifestFiles ?? this.manifestFiles
189+
this.author = arg.author ?? this.author
190+
this.size = arg.size ?? this.size
191+
this.alerts = arg.alerts ?? this.alerts
192+
this.topLevelAncestors = arg.topLevelAncestors ?? this.topLevelAncestors
193+
this.license = arg.license ?? this.license
194+
195+
this.url = `https://socket.dev/${this.type}/package/${this.name}/overview/${this.version}`
196+
this.score = new Score(
197+
arg.score ?? {
198+
supplyChain: 0,
199+
quality: 0,
200+
license: 0,
201+
overall: 0,
202+
vulnerability: 0
203+
}
204+
)
205+
this.alert_counts = {
206+
critical: 0,
207+
high: 0,
208+
middle: 0,
209+
low: 0
210+
}
211+
this.purl = `${this.type}/${this.name}@${this.version}`
212+
}
213+
}
214+
215+
export class Purl {
216+
id = ''
217+
name = ''
218+
version = ''
219+
ecosystem = ''
220+
direct = false
221+
author: string[] = []
222+
size = 0
223+
transitives = 0
224+
introduced_by: IntroducedBy = []
225+
capabilities: string[] = []
226+
// is_new = false
227+
author_url = ''
228+
url = ''
229+
purl = ''
230+
231+
constructor(arg: {
232+
id: string | undefined
233+
name: string | undefined
234+
version: string | undefined
235+
ecosystem: string | undefined
236+
direct: boolean | undefined
237+
introduced_by: IntroducedBy | undefined
238+
author: string[] | undefined
239+
size: number | undefined
240+
transitives: number | undefined
241+
url: string | undefined
242+
purl: string | undefined
243+
}) {
244+
this.id = arg.id ?? this.id
245+
this.name = arg.name ?? this.name
246+
this.version = arg.version ?? this.version
247+
this.ecosystem = arg.ecosystem ?? this.ecosystem
248+
this.direct = arg.direct ?? this.direct
249+
this.author = arg.author ?? this.author
250+
this.size = arg.size ?? this.size
251+
this.transitives = arg.transitives ?? this.transitives
252+
this.introduced_by = arg.introduced_by ?? this.introduced_by
253+
this.url = arg.url ?? this.url
254+
this.purl = arg.purl ?? this.purl
255+
256+
this.author_url = this.generateAuthorData(this.author, this.ecosystem)
257+
}
258+
259+
private generateAuthorData(authors: string[], ecosystem: string): string {
260+
const arr = []
261+
for (const author of authors) {
262+
const url = `https://socket.dev/${ecosystem}/user/${author}`
263+
arr.push(`[${author}](${url})`)
264+
}
265+
return arr.join(',')
266+
}
267+
}
268+
269+
export class Score {
270+
supplyChain = 0
271+
quality = 0
272+
license = 0
273+
overall = 0
274+
vulnerability = 0
275+
276+
constructor(arg: Score) {
277+
this.supplyChain = (arg.supplyChain ?? 0) * 100
278+
this.quality = (arg.quality ?? 0) * 100
279+
this.license = (arg.license ?? 0) * 100
280+
this.overall = (arg.overall ?? 0) * 100
281+
this.vulnerability = (arg.vulnerability ?? 0) * 100
282+
}
283+
}

0 commit comments

Comments
 (0)