Skip to content

Commit bd28b33

Browse files
committed
Add --analysis-type flag to app process
1 parent 5beabf3 commit bd28b33

5 files changed

Lines changed: 70 additions & 20 deletions

File tree

cli/README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $ npm install -g @nowsecure/platform-cli
2222
$ ns-cli COMMAND
2323
running command...
2424
$ ns-cli (--version)
25-
@nowsecure/platform-cli/1.0.0-beta.3 darwin-x64 node-v16.19.1
25+
@nowsecure/platform-cli/1.0.0 darwin-x64 node-v16.19.1
2626
$ ns-cli --help [COMMAND]
2727
USAGE
2828
$ ns-cli COMMAND
@@ -86,7 +86,7 @@ DESCRIPTION
8686
Commands to manipulate applications for analysis
8787
```
8888

89-
_See code: [dist/commands/app/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0-beta.3/dist/commands/app/index.ts)_
89+
_See code: [dist/commands/app/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0/dist/commands/app/index.ts)_
9090

9191
## `ns-cli app archive [PLATFORM] [PACKAGENAME]`
9292

@@ -332,15 +332,18 @@ Upload and analyze an application binary
332332
```
333333
USAGE
334334
$ ns-cli app process BINARY [--token <value>] [--graphql <value>] [--rest <value>] [--ui <value>] [--profile
335-
<value>] [--config-file <value>] [--json] [-g <value>] [--group-ref <value>] [-v <value>]
335+
<value>] [--config-file <value>] [--json] [-g <value>] [--group-ref <value>] [-v <value>] [-t
336+
full|static|dependencies]
336337
337338
ARGUMENTS
338339
BINARY file to send to Platform
339340
340341
FLAGS
341-
-g, --group=<value> Group name
342-
-v, --set-version=<value> Set the version of the uploaded binary
343-
--group-ref=<value> Group reference
342+
-g, --group=<value> Group name
343+
-t, --analysis-type=<option> The type of analysis to perform
344+
<options: full|static|dependencies>
345+
-v, --set-version=<value> Set the version of the uploaded binary
346+
--group-ref=<value> Group reference
344347
345348
GLOBAL FLAGS
346349
--config-file=<value> Path to the config file
@@ -480,7 +483,7 @@ DESCRIPTION
480483
Commands to retrieve assessment data
481484
```
482485

483-
_See code: [dist/commands/assessment/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0-beta.3/dist/commands/assessment/index.ts)_
486+
_See code: [dist/commands/assessment/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0/dist/commands/assessment/index.ts)_
484487

485488
## `ns-cli assessment cancel ASSESSMENT`
486489

@@ -810,7 +813,7 @@ FLAGS
810813
--ui=<value> URL of the UI server
811814
```
812815

813-
_See code: [dist/commands/configure/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0-beta.3/dist/commands/configure/index.ts)_
816+
_See code: [dist/commands/configure/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0/dist/commands/configure/index.ts)_
814817

815818
## `ns-cli help [COMMANDS]`
816819

@@ -844,7 +847,7 @@ DESCRIPTION
844847
Commands for the user's organization
845848
```
846849

847-
_See code: [dist/commands/organization/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0-beta.3/dist/commands/organization/index.ts)_
850+
_See code: [dist/commands/organization/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0/dist/commands/organization/index.ts)_
848851

849852
## `ns-cli organization groups`
850853

@@ -1241,7 +1244,7 @@ DESCRIPTION
12411244
Commands for users & accounts
12421245
```
12431246

1244-
_See code: [dist/commands/user/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0-beta.3/dist/commands/user/index.ts)_
1247+
_See code: [dist/commands/user/index.ts](https://github.com/cosdon/nowsecure-cli/blob/v1.0.0/dist/commands/user/index.ts)_
12451248

12461249
## `ns-cli user account`
12471250

cli/src/commands/app/process.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Args, Flags } from "@oclif/core";
99
import { ProcessApplicationResponse } from "@nowsecure/platform-lib/lib/types";
1010
import { getGroupRef, BaseCommand, groupFlags } from "../../utils";
1111
import ProgressBar from "progress";
12-
import { RequestConfig } from "@nowsecure/platform-lib";
12+
import { AnalysisType, RequestConfig } from "@nowsecure/platform-lib";
1313

1414
export default class ProcessBinary extends BaseCommand {
1515
static description = "Upload and analyze an application binary";
@@ -22,6 +22,11 @@ export default class ProcessBinary extends BaseCommand {
2222
char: "v",
2323
summary: "Set the version of the uploaded binary",
2424
}),
25+
"analysis-type": Flags.string({
26+
char: "t",
27+
summary: "The type of analysis to perform",
28+
options: Object.values(AnalysisType),
29+
}),
2530
};
2631
static args = {
2732
binary: Args.string({
@@ -53,6 +58,7 @@ export default class ProcessBinary extends BaseCommand {
5358
stream,
5459
groupRef,
5560
flags["set-version"],
61+
flags["analysis-type"] as AnalysisType | undefined,
5662
config
5763
);
5864
this.log(

lib/docs/includes/_app_processBinary.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ interface PlatformAPI {
66
stream: NodeJS.ReadableStream,
77
groupId?: string,
88
version?: string,
9+
analysisType?: AnalysisType
910
config?: RequestConfig
1011
): Promise<ProcessApplicationResponse>;
1112
}
1213

14+
enum AnalysisType {
15+
FULL = "full",
16+
STATIC = "static",
17+
DEPENDENCIES = "dependencies",
18+
}
19+
1320
interface ProcessApplicationResponse {
1421
ref: string;
1522
application: string;
@@ -38,12 +45,13 @@ interface ProcessApplicationResponse {
3845

3946
Upload an ipa or apk file to Platform and begin an assessment.
4047

41-
| Parameter | Description |
42-
| --------- | --------------------------------------------------------------------------------------------------------------------------- |
43-
| stream | The application data to send to Platform |
44-
| groupId | The application group to use for the assessment. Required if the user is a member of more than one group |
45-
| version | Optional version string for the build. If this field is not specified the version from the application package will be used |
46-
| config | [`RequestConfig`](#requestconfig). Upload progress can be monitored via the `onUploadProgress` callback. |
48+
| Parameter | Description |
49+
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
50+
| stream | The application data to send to Platform |
51+
| groupId | The application group to use for the assessment. Required if the user is a member of more than one group |
52+
| version | Optional version string for the build. If this field is not specified the version from the application package will be used |
53+
| analysisType | If specified, the type of analysis to run. "static" runs a static-only analysis, "dependencies" returns the SBOM dependency graph. |
54+
| config | [`RequestConfig`](#requestconfig). Upload progress can be monitored via the `onUploadProgress` callback. |
4755

4856
`ProcessApplicationResponse`
4957

lib/src/api/app/upload-binary.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,36 @@ import {
1010
UploadApplicationResponse,
1111
} from "../../types/platform";
1212

13-
function queryParams(groupId?: string, version?: string) {
13+
export enum AnalysisType {
14+
FULL = "full",
15+
STATIC = "static",
16+
DEPENDENCIES = "dependencies",
17+
}
18+
19+
function queryParams(
20+
groupId?: string,
21+
version?: string,
22+
analysisType?: AnalysisType
23+
) {
1424
const args: string[] = [];
1525
if (groupId) {
1626
args.push("group=" + encodeURIComponent(groupId));
1727
}
1828
if (version) {
1929
args.push("version=" + encodeURIComponent(version));
2030
}
31+
if (analysisType) {
32+
switch (analysisType) {
33+
case AnalysisType.FULL:
34+
break;
35+
case AnalysisType.DEPENDENCIES:
36+
args.push("analysisType=sbom");
37+
break;
38+
case AnalysisType.STATIC:
39+
args.push("analysisType=static");
40+
break;
41+
}
42+
}
2143

2244
return args.length > 0 ? "?" + args.join("&") : "";
2345
}
@@ -31,9 +53,10 @@ export /*async*/ function processBinary(
3153
stream: NodeJS.ReadableStream,
3254
groupId?: string,
3355
version?: string,
56+
analysisType?: AnalysisType,
3457
config?: RequestConfig
3558
): Promise<ProcessApplicationResponse> {
36-
const paramStr = queryParams(groupId, version);
59+
const paramStr = queryParams(groupId, version, analysisType);
3760
return client.postStream<ProcessApplicationResponse>(
3861
`/build/${paramStr}`,
3962
stream,

lib/src/platform.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
updateAnalysisConfig,
5858
resetAnalysisConfig,
5959
UpdateConfigOptions,
60+
AnalysisType,
6061
} from "./api";
6162

6263
export interface PlatformAPI {
@@ -90,6 +91,7 @@ export interface PlatformAPI {
9091
stream: NodeJS.ReadableStream,
9192
groupId?: string,
9293
version?: string,
94+
analysisType?: AnalysisType,
9395
config?: RequestConfig
9496
): Promise<ProcessApplicationResponse>;
9597

@@ -207,9 +209,17 @@ export class Platform implements PlatformAPI {
207209
stream: NodeJS.ReadableStream,
208210
groupId?: string,
209211
version?: string,
212+
analysisType?: AnalysisType,
210213
config?: RequestConfig
211214
): Promise<ProcessApplicationResponse> {
212-
return processBinary(this._client, stream, groupId, version, config);
215+
return processBinary(
216+
this._client,
217+
stream,
218+
groupId,
219+
version,
220+
analysisType,
221+
config
222+
);
213223
}
214224

215225
uploadBinary(

0 commit comments

Comments
 (0)