Skip to content

Commit 7f2b960

Browse files
committed
Use requirements.json to add perms and quotas
1 parent d818b0e commit 7f2b960

33 files changed

Lines changed: 1087 additions & 759 deletions

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"./bin/npm-cli.js": "./dist/npm-cli.js",
2525
"./bin/npx-cli.js": "./dist/npx-cli.js",
2626
"./package.json": "./package.json",
27+
"./requirements.json": "./requirements.json",
2728
"./translations.json": "./translations.json"
2829
},
2930
"scripts": {
@@ -218,6 +219,7 @@
218219
"dist/**",
219220
"external/**",
220221
"shadow-bin/**",
222+
"requirements.json",
221223
"translations.json"
222224
],
223225
"lint-staged": {

requirements.json

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"api": {
3+
"analytics": {
4+
"quota": 1,
5+
"permissions": ["report:write"]
6+
},
7+
"audit-log": {
8+
"quota": 1,
9+
"permissions": ["audit-log:list"]
10+
},
11+
"fix": {
12+
"quota": 100,
13+
"permissions": ["packages:list"]
14+
},
15+
"login": {
16+
"quota": 1,
17+
"permissions": []
18+
},
19+
"npm": {
20+
"quota": 100,
21+
"permissions": ["packages:list"]
22+
},
23+
"npx": {
24+
"quota": 100,
25+
"permissions": ["packages:list"]
26+
},
27+
"organization:dependencies": {
28+
"quota": 1,
29+
"permissions": []
30+
},
31+
"organization:list": {
32+
"quota": 1,
33+
"permissions": []
34+
},
35+
"organization:policy:license": {
36+
"quota": 1,
37+
"permissions": ["license-policy:read"]
38+
},
39+
"organization:policy:security": {
40+
"quota": 1,
41+
"permissions": ["security-policy:read"]
42+
},
43+
"package:score": {
44+
"quota": 100,
45+
"permissions": ["packages:list"]
46+
},
47+
"package:shallow": {
48+
"quota": 100,
49+
"permissions": ["packages:list"]
50+
},
51+
"repository:create": {
52+
"quota": 1,
53+
"permissions": ["repo:create"]
54+
},
55+
"repository:del": {
56+
"quota": 1,
57+
"permissions": ["repo:delete"]
58+
},
59+
"repository:list": {
60+
"quota": 1,
61+
"permissions": ["repo:list"]
62+
},
63+
"repository:update": {
64+
"quota": 1,
65+
"permissions": ["repo:update"]
66+
},
67+
"repository:view": {
68+
"quota": 1,
69+
"permissions": ["repo:list"]
70+
},
71+
"scan:create": {
72+
"quota": 1,
73+
"permissions": ["full-scans:create"]
74+
},
75+
"scan:delete": {
76+
"quota": 1,
77+
"permissions": ["full-scans:delete"]
78+
},
79+
"scan:diff": {
80+
"quota": 1,
81+
"permissions": ["full-scans:list"]
82+
},
83+
"scan:list": {
84+
"quota": 1,
85+
"permissions": ["full-scans:list"]
86+
},
87+
"scan:github": {
88+
"quota": 1,
89+
"permissions": ["full-scans:create"]
90+
},
91+
"scan:metadata": {
92+
"quota": 1,
93+
"permissions": ["full-scans:list"]
94+
},
95+
"scan:reach": {
96+
"quota": 1,
97+
"permissions": ["full-scans:create"]
98+
},
99+
"scan:report": {
100+
"quota": 2,
101+
"permissions": ["full-scans:list", "security-policy:read"]
102+
},
103+
"scan:view": {
104+
"quota": 1,
105+
"permissions": ["full-scans:list"]
106+
},
107+
"shallow": {
108+
"quota": 100,
109+
"permissions": ["packages:list"]
110+
},
111+
"threat-feed": {
112+
"quota": 1,
113+
"permissions": ["threat-feed:list"]
114+
}
115+
}
116+
}

src/commands.mts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const rootCommands = {
3434
ci: cmdCI,
3535
cdxgen: cmdManifestCdxgen,
3636
config: cmdConfig,
37-
deps: cmdOrganizationDependencies,
37+
dependencies: cmdOrganizationDependencies,
3838
fix: cmdFix,
3939
install: cmdInstall,
4040
json: cmdJson,
@@ -79,6 +79,11 @@ export const rootAliases = {
7979
hidden: true,
8080
argv: ['audit-log'],
8181
},
82+
deps: {
83+
description: cmdOrganizationDependencies.description,
84+
hidden: true,
85+
argv: ['dependencies'],
86+
},
8287
feed: {
8388
description: cmdThreatFeed.description,
8489
hidden: true,

src/commands/analytics/cmd-analytics.mts

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,52 @@ import { commonFlags, outputFlags } from '../../flags.mts'
66
import { checkCommandInput } from '../../utils/check-input.mts'
77
import { getOutputKind } from '../../utils/get-output-kind.mts'
88
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
9-
import { getFlagListOutput } from '../../utils/output-formatting.mts'
9+
import {
10+
getFlagApiRequirementsOutput,
11+
getFlagListOutput,
12+
} from '../../utils/output-formatting.mts'
1013
import { hasDefaultToken } from '../../utils/sdk.mts'
1114

1215
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
1316

1417
const { DRY_RUN_BAILING_NOW } = constants
1518

16-
const config: CliCommandConfig = {
17-
commandName: 'analytics',
18-
description: 'Look up analytics data',
19-
hidden: false,
20-
flags: {
21-
...commonFlags,
22-
...outputFlags,
23-
file: {
24-
type: 'string',
25-
description: 'Path to store result, only valid with --json/--markdown',
19+
export const CMD_NAME = 'analytics'
20+
21+
const description = 'Look up analytics data'
22+
23+
const hidden = false
24+
25+
export const cmdAnalytics = {
26+
description,
27+
hidden,
28+
run: run,
29+
}
30+
31+
async function run(
32+
argv: string[] | readonly string[],
33+
importMeta: ImportMeta,
34+
{ parentName }: { parentName: string },
35+
): Promise<void> {
36+
const config: CliCommandConfig = {
37+
commandName: CMD_NAME,
38+
description,
39+
hidden,
40+
flags: {
41+
...commonFlags,
42+
...outputFlags,
43+
file: {
44+
type: 'string',
45+
description: 'Path to store result, only valid with --json/--markdown',
46+
},
2647
},
27-
},
28-
help: (command, { flags }) =>
29-
`
48+
help: (command, { flags }) =>
49+
`
3050
Usage
3151
$ ${command} [options] [ "org" | "repo" <reponame>] [TIME]
3252
3353
API Token Requirements
34-
- Quota: 1 unit
35-
- Permissions: report:write
54+
${getFlagApiRequirementsOutput(`${parentName}:${CMD_NAME}`)}
3655
3756
The scope is either org or repo level, defaults to org.
3857
@@ -48,19 +67,8 @@ const config: CliCommandConfig = {
4867
$ ${command} repo test-repo 30
4968
$ ${command} 90
5069
`,
51-
}
52-
53-
export const cmdAnalytics = {
54-
description: config.description,
55-
hidden: config.hidden,
56-
run: run,
57-
}
70+
}
5871

59-
async function run(
60-
argv: string[] | readonly string[],
61-
importMeta: ImportMeta,
62-
{ parentName }: { parentName: string },
63-
): Promise<void> {
6472
const cli = meowOrExit({
6573
argv,
6674
config,

src/commands/audit-log/cmd-audit-log.mts

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,67 @@ import { checkCommandInput } from '../../utils/check-input.mts'
77
import { determineOrgSlug } from '../../utils/determine-org-slug.mts'
88
import { getOutputKind } from '../../utils/get-output-kind.mts'
99
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
10-
import { getFlagListOutput } from '../../utils/output-formatting.mts'
10+
import {
11+
getFlagApiRequirementsOutput,
12+
getFlagListOutput,
13+
} from '../../utils/output-formatting.mts'
1114
import { hasDefaultToken } from '../../utils/sdk.mts'
1215

1316
import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
1417

1518
const { DRY_RUN_BAILING_NOW, SOCKET_WEBSITE_URL } = constants
1619

17-
const config: CliCommandConfig = {
18-
commandName: 'audit-log',
19-
description: 'Look up the audit log for an organization',
20-
hidden: false,
21-
flags: {
22-
...commonFlags,
23-
...outputFlags,
24-
interactive: {
25-
type: 'boolean',
26-
default: true,
27-
description:
28-
'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no.',
29-
},
30-
org: {
31-
type: 'string',
32-
description:
33-
'Force override the organization slug, overrides the default org from config',
34-
},
35-
page: {
36-
type: 'number',
37-
description: 'Result page to fetch',
38-
},
39-
perPage: {
40-
type: 'number',
41-
default: 30,
42-
description: 'Results per page - default is 30',
20+
const CMD_NAME = 'audit-log'
21+
22+
const description = 'Look up the audit log for an organization'
23+
24+
const hidden = false
25+
26+
export const cmdAuditLog = {
27+
description,
28+
hidden,
29+
run,
30+
}
31+
32+
async function run(
33+
argv: string[] | readonly string[],
34+
importMeta: ImportMeta,
35+
{ parentName }: { parentName: string },
36+
): Promise<void> {
37+
const config: CliCommandConfig = {
38+
commandName: CMD_NAME,
39+
description,
40+
hidden,
41+
flags: {
42+
...commonFlags,
43+
...outputFlags,
44+
interactive: {
45+
type: 'boolean',
46+
default: true,
47+
description:
48+
'Allow for interactive elements, asking for input.\nUse --no-interactive to prevent any input questions, defaulting them to cancel/no.',
49+
},
50+
org: {
51+
type: 'string',
52+
description:
53+
'Force override the organization slug, overrides the default org from config',
54+
},
55+
page: {
56+
type: 'number',
57+
description: 'Result page to fetch',
58+
},
59+
perPage: {
60+
type: 'number',
61+
default: 30,
62+
description: 'Results per page - default is 30',
63+
},
4364
},
44-
},
45-
help: (command, config) => `
65+
help: (command, config) => `
4666
Usage
4767
$ ${command} [options] [FILTER]
4868
4969
API Token Requirements
50-
- Quota: 1 unit
51-
- Permissions: audit-log:list
70+
${getFlagApiRequirementsOutput(`${parentName}:${CMD_NAME}`)}
5271
5372
This feature requires an Enterprise Plan. To learn more about getting access
5473
to this feature and many more, please visit ${SOCKET_WEBSITE_URL}/pricing
@@ -72,19 +91,8 @@ const config: CliCommandConfig = {
7291
$ ${command}
7392
$ ${command} deleteReport --page 2 --perPage 10
7493
`,
75-
}
76-
77-
export const cmdAuditLog = {
78-
description: config.description,
79-
hidden: config.hidden,
80-
run,
81-
}
94+
}
8295

83-
async function run(
84-
argv: string[] | readonly string[],
85-
importMeta: ImportMeta,
86-
{ parentName }: { parentName: string },
87-
): Promise<void> {
8896
const cli = meowOrExit({
8997
argv,
9098
config,

src/commands/audit-log/cmd-audit-log.test.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ describe('socket audit-log', async () => {
3939
The page arg should be a positive integer, offset 1. Defaults to 1.
4040
4141
Options
42-
--interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no.
42+
--interactive Allow for interactive elements, asking for input.
43+
Use --no-interactive to prevent any input questions, defaulting them to cancel/no.
4344
--json Output result as json
4445
--markdown Output result as markdown
4546
--org Force override the organization slug, overrides the default org from config

src/commands/cli.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('socket root command', async () => {
3232
package Look up published package details
3333
repository Manage registered repositories
3434
scan Manage Socket scans
35-
threat-feed [Beta] View the threat feed
35+
threat-feed [Beta] View the threat-feed
3636
3737
Local tools
3838
fix Update dependencies with "fixable" Socket alerts

src/commands/config/cmd-config-auto.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { DRY_RUN_BAILING_NOW } = constants
1919

2020
const description =
2121
'Automatically discover and set the correct value config item'
22+
2223
const hidden = false
2324

2425
export const cmdConfigAuto = {

src/commands/config/cmd-config-set.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
1818
const { DRY_RUN_BAILING_NOW } = constants
1919

2020
const description = 'Update the value of a local CLI config item'
21+
2122
const hidden = false
2223

2324
export const cmdConfigSet = {

0 commit comments

Comments
 (0)