Skip to content

Commit 3e56be0

Browse files
committed
Threat-feed; use new api endpoint, add search flags
1 parent 6f3530d commit 3e56be0

File tree

4 files changed

+71
-23
lines changed

4 files changed

+71
-23
lines changed

src/commands/threat-feed/cmd-threat-feed.mts

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ const config: CliCommandConfig = {
2222
flags: {
2323
...commonFlags,
2424
...outputFlags,
25+
direction: {
26+
type: 'string',
27+
shortFlag: 'd',
28+
default: 'desc',
29+
description: 'Order asc or desc by the createdAt attribute',
30+
},
31+
eco: {
32+
type: 'string',
33+
shortFlag: 'e',
34+
default: '',
35+
description: 'Only show threats for a particular ecosystem',
36+
},
37+
filter: {
38+
type: 'string',
39+
shortFlag: 'f',
40+
default: 'mal',
41+
description: 'Filter what type of threats to return',
42+
},
2543
interactive: {
2644
type: 'boolean',
2745
default: true,
@@ -33,35 +51,25 @@ const config: CliCommandConfig = {
3351
description:
3452
'Force override the organization slug, overrides the default org from config',
3553
},
36-
perPage: {
37-
type: 'number',
38-
shortFlag: 'pp',
39-
default: 30,
40-
description: 'Number of items per page',
41-
},
4254
page: {
4355
type: 'string',
4456
shortFlag: 'p',
4557
default: '1',
4658
description: 'Page token',
4759
},
48-
direction: {
49-
type: 'string',
50-
shortFlag: 'd',
51-
default: 'desc',
52-
description: 'Order asc or desc by the createdAt attribute',
60+
perPage: {
61+
type: 'number',
62+
shortFlag: 'pp',
63+
default: 30,
64+
description: 'Number of items per page',
5365
},
54-
eco: {
66+
pkg: {
5567
type: 'string',
56-
shortFlag: 'e',
57-
default: '',
58-
description: 'Only show threats for a particular ecosystem',
68+
description: 'Filter by this package name',
5969
},
60-
filter: {
70+
version: {
6171
type: 'string',
62-
shortFlag: 'f',
63-
default: 'mal',
64-
description: 'Filter what type of threats to return',
72+
description: 'Filter by this package version',
6573
},
6674
},
6775
help: (command, config) => `
@@ -102,6 +110,11 @@ const config: CliCommandConfig = {
102110
- nuget
103111
- pypi
104112
113+
Note: if you filter by package name or version, it will do so for anything
114+
unless you also filter by that ecosystem and/or package name. When in
115+
doubt, look at the threat-feed and see the names in the name/version
116+
column. That's what you want to search for.
117+
105118
Examples
106119
$ ${command}${isTestingV1() ? '' : ' FakeOrg'}
107120
$ ${command}${isTestingV1() ? '' : ' FakeOrg'} --perPage=5 --page=2 --direction=asc --filter=joke
@@ -126,7 +139,15 @@ async function run(
126139
parentName,
127140
})
128141

129-
const { dryRun, interactive, json, markdown, org: orgFlag } = cli.flags
142+
const {
143+
dryRun,
144+
interactive,
145+
json,
146+
markdown,
147+
org: orgFlag,
148+
pkg,
149+
version,
150+
} = cli.flags
130151
const outputKind = getOutputKind(json, markdown)
131152

132153
const [orgSlug] = await determineOrgSlug(
@@ -177,7 +198,10 @@ async function run(
177198
ecosystem: String(cli.flags['eco'] || ''),
178199
filter: String(cli.flags['filter'] || 'mal'),
179200
outputKind,
201+
orgSlug,
180202
page: String(cli.flags['page'] || '1'),
181203
perPage: Number(cli.flags['perPage']) || 30,
204+
pkg: String(pkg || ''),
205+
version: String(version || ''),
182206
})
183207
}

src/commands/threat-feed/cmd-threat-feed.test.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ describe('socket threat-feed', async () => {
3939
--org Force override the organization slug, overrides the default org from config
4040
--page Page token
4141
--perPage Number of items per page
42+
--pkg Filter by this package name
43+
--version Filter by this package version
4244
4345
Valid filters:
4446
@@ -63,6 +65,11 @@ describe('socket threat-feed', async () => {
6365
- nuget
6466
- pypi
6567
68+
Note: if you filter by package name or version, it will do so for anything
69+
unless you also filter by that ecosystem and/or package name. When in
70+
doubt, look at the threat-feed and see the names in the name/version
71+
column. That's what you want to search for.
72+
6673
Examples
6774
$ socket threat-feed FakeOrg
6875
$ socket threat-feed FakeOrg --perPage=5 --page=2 --direction=asc --filter=joke"

src/commands/threat-feed/fetch-threat-feed.mts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,33 @@ export async function fetchThreatFeed({
77
direction,
88
ecosystem,
99
filter,
10+
orgSlug,
1011
page,
1112
perPage,
13+
pkg,
14+
version,
1215
}: {
1316
direction: string
1417
ecosystem: string
1518
filter: string
19+
orgSlug: string
1620
page: string
1721
perPage: number
22+
pkg: string
23+
version: string
1824
}): Promise<CResult<ThreadFeedResponse>> {
1925
const queryParams = new URLSearchParams([
2026
['direction', direction],
2127
['ecosystem', ecosystem],
22-
['filter', filter],
23-
['page', page],
28+
filter ? ['filter', filter] : ['', ''],
29+
['page_cursor', page],
2430
['per_page', String(perPage)],
31+
pkg ? ['name', pkg] : ['', ''],
32+
version ? ['version', version] : ['', ''],
2533
])
2634

2735
return await queryApiSafeJson(
28-
`threat-feed?${queryParams}`,
36+
`orgs/${orgSlug}/threat-feed?${queryParams}`,
2937
'the Threat Feed data',
3038
)
3139
}

src/commands/threat-feed/handle-threat-feed.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,32 @@ export async function handleThreatFeed({
77
direction,
88
ecosystem,
99
filter,
10+
orgSlug,
1011
outputKind,
1112
page,
1213
perPage,
14+
pkg,
15+
version,
1316
}: {
1417
direction: string
1518
ecosystem: string
1619
filter: string
1720
outputKind: OutputKind
21+
orgSlug: string
1822
page: string
1923
perPage: number
24+
pkg: string
25+
version: string
2026
}): Promise<void> {
2127
const data = await fetchThreatFeed({
2228
direction,
2329
ecosystem,
2430
filter,
31+
orgSlug,
2532
page,
2633
perPage,
34+
pkg,
35+
version,
2736
})
2837

2938
await outputThreatFeed(data, outputKind)

0 commit comments

Comments
 (0)