@aikidosec/ci-api-client 1.0.0

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.
package/.editorconfig ADDED
@@ -0,0 +1,18 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.{json,iml}]
12
+ indent_style = space
13
+ indent_size = 2
14
+ insert_final_newline = false
15
+
16
+ [*.{diff,md,markdown}]
17
+ trim_trailing_whitespace = false
18
+
package/.env ADDED
@@ -0,0 +1 @@
1
+ AIKIDO_API=https://app.aikido.dev
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "printWidth": 80,
4
+ "tabWidth": 2,
5
+ "semi": true,
6
+ "singleQuote": true,
7
+ "arrowParens": "avoid",
8
+ "bracketSameLine": false,
9
+ "bracketSpacing": true
10
+ }
@@ -0,0 +1,30 @@
1
+ # Contributing to aikido-api-client
2
+
3
+ Are you missing functionality or have you found a bug? Please feel free to add an issue or submit a PR. We try to be responsive and release updates and fixes as fast as possible.
4
+
5
+ ## Reporting issues
6
+
7
+ This package uses the [GitHub Issue Tracker](https://github.com/AikidoSec/aikido-api-client/issues) to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted.
8
+
9
+ ## Contributing code
10
+
11
+ If you want to add additional tags, attributes or functionality to the library, please feel free to create a [pull request](https://github.com/AikidoSec/aikido-api-client/pulls) with your changes.
12
+
13
+ Please try to follow this workflow:
14
+
15
+ - Fork the project
16
+ - Create a new branch forked from the main branch with a title for your feature (e.g. feature-that-i-want)
17
+ - Commit all your code into this branch until you are happy with your contribution
18
+ - Create a pull request with your commits
19
+
20
+ ## Formatting ⚠️
21
+
22
+ Please try to follow editor settings provided in `.editorconfig` and `.prettierrc`. If you are using an editor like VS Code your editor should automatically parse these files and auto-format your files on save. If not, you can re-format all source files with the following command:
23
+
24
+ ```sh
25
+ $ yarn format
26
+ ```
27
+
28
+ ## Unit testing ⚠️
29
+
30
+ No unit tests are currently available for the cli tool.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Aikido Security BV and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Aikido Security CI API client
2
+
3
+ <!-- [![NPM Version](http://img.shields.io/npm/v/aikido-api-client.svg?style=flat)](https://www.npmjs.org/package/aikido-api-client)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/aikido-api-client.svg?style=flat)](https://npmcharts.com/compare/aikido-api-client?minimal=true)
5
+ [![Install Size](https://packagephobia.now.sh/badge?p=aikido-api-client)](https://packagephobia.now.sh/result?p=aikido-api-client) -->
6
+
7
+ CLI helper for the public [Aikido CI API](https://aikido-dev.notion.site/aikido-dev/Aikido-CI-API-78d318b5f5f7477ab072e12f94b21374). This cli tool can help integrate Aikido into a custom CI pipeline without having to implement the Aikido CI API yourself.
8
+
9
+ ## Installation and setup
10
+
11
+ The quickest way to get started is to install the cli tool as a global package.
12
+
13
+ ```sh
14
+ # npm users
15
+ $ npm install -g @aikidosec/ci-api-client
16
+
17
+ # yarn users
18
+ $ yarn global add @aikidosec/ci-api-client
19
+ ```
20
+
21
+ After installation, you'll need to setup your Aikido API key. You can add your key by requesting a token on the [Continuous Integrations page](https://app.aikido.dev/settings/integrations/continuous-integration) in the [Integrations](https://app.aikido.dev/settings/integrations) section of the Aikido web platform. Click the "Start integrating" link and setup your key globally by executing
22
+
23
+ ```sh
24
+ $ aikido-api-client apikey <your-api-key-here>
25
+ ```
26
+
27
+ ⚠️ Your Aikido API key is stored in `~/.config/configstore/aikido-api-client.json`. If you don't want this behaviour (e.g. for security related issues), you can also provide your API key to `aikido-api-client` by adding `--apikey <your-api-key-here>` to every command. However, for the examples below, we'll assume you've used `aikido-api-client apikey <your-api-key-here>` to save your API key. If `--apikey` is provided while a key is set in the configuration file on disk, the key that was provided with `--apikey` will be used.
28
+
29
+ ## Usage
30
+
31
+ Using the `aikido-api-client` to start new scans is very straightforward.
32
+
33
+ ```sh
34
+ $ aikido-api-client scan <repository_id> <base_commit_id> <head_commit_id>
35
+ ```
36
+
37
+ The process will report scan progress and will exit with exitCode `0` if the scan was successfull (`gate_passed: true`). The process will exit with exitCode `10` if the scan was unsuccesfull (`gate_passed: false`). If anything else goes wrong (e.g. API unavailable, scanning unavailable, other unexpected issue) the process will exit with exitCode `1`.
38
+
39
+ If you want the scan to run quietly (without output), you can add the `--quiet` option to the command.
40
+
41
+ ```sh
42
+ # For more options and combinations, check the help output
43
+ $ aikido-api-client help scan
44
+ ```
45
+
46
+ Uploading custom test results:
47
+
48
+ ```sh
49
+ $ aikido-api-client upload --repository-id <repository_id> --type checkov --file <path_to_payload_file>
50
+
51
+ # For more options and combinations, check the help output
52
+ $ aikido-api-client help upload
53
+ ```
54
+
55
+ For more information about these parameters, please refer to `aikido-api-client help`, `aikido-api-client help scan` or `aikido-api-client help upload`, or [the public ci api page](https://aikido-dev.notion.site/aikido-dev/Aikido-CI-API-78d318b5f5f7477ab072e12f94b21374).
56
+
57
+ ## Help & contributing
58
+
59
+ For more information about all available commands and options, execute:
60
+
61
+ ```sh
62
+ $ aikido-api-client help
63
+ ```
64
+
65
+ ```sh
66
+ $ aikido-api-client help <command>
67
+ ```
68
+
69
+ If you are missing functionality in this cli tool, please feel free to add it. If you've detected a bug, please submit a PR. Check out [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
70
+
71
+
72
+ # Other resources
73
+
74
+ - [Aikido Official Website](https://aikido.dev)
75
+ - [Aikido Github Actions Workflow](https://github.com/AikidoSec/github-actions-workflow)
76
+ - [Aikido on Twitter](https://twitter.com/AikidoSecurity)
77
+
78
+
package/RELEASING.md ADDED
@@ -0,0 +1,26 @@
1
+ # Releasing
2
+
3
+ ## Creating a new version
4
+
5
+ Increment the version of the package by updating the version in `package.json`
6
+ or by updating the package using `npm version`.
7
+
8
+ ```sh
9
+ $ cd aikido-api-client
10
+ $ npm version
11
+ ```
12
+
13
+ ## Releasing a new version
14
+
15
+ Make sure to re-buidl all Typescript files using `yarn build`. Release a new version by publishing the package to npm using `npm publish`.
16
+
17
+ ```sh
18
+ $ cd aikido-api-client
19
+ $ yarn build
20
+ $ npm publish
21
+ ```
22
+
23
+ *or*
24
+
25
+ Setup the "Publish Node.js Package" action in the aikido-api-client Github.com repo.
26
+ See also: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
@@ -0,0 +1,60 @@
1
+ export type TScanApiOptions = {
2
+ repository_id?: string | number;
3
+ base_commit_id?: string;
4
+ head_commit_id?: string;
5
+ branch_name?: string;
6
+ pull_request_metadata?: {
7
+ title?: string;
8
+ url?: string;
9
+ };
10
+ self_managed_scanners?: string[];
11
+ fail_on_dependency_scan?: boolean;
12
+ fail_on_sast_scan?: boolean;
13
+ fail_on_iac_scan?: boolean;
14
+ minimum_severity?: string;
15
+ version: string;
16
+ };
17
+ export type TStartScanResult = {
18
+ scan_id: number;
19
+ };
20
+ export declare function startScan(data: TScanApiOptions): Promise<TStartScanResult>;
21
+ export type TPollIsScanningResult = {
22
+ all_scans_completed: boolean;
23
+ dependency_scan_completed: boolean;
24
+ sast_scan_completed: boolean;
25
+ iac_scan_completed: boolean;
26
+ sbom_scan_completed?: boolean;
27
+ };
28
+ type TPollScanCompletedOptions = {
29
+ gate_passed: boolean;
30
+ };
31
+ type TPollScanFeatureBranchCompletedOptions = {
32
+ new_issues_found: number;
33
+ new_dependency_issues_found: number;
34
+ new_sast_issues_found: number;
35
+ new_iac_issues_found: number;
36
+ diff_url: string;
37
+ };
38
+ type TPollScanDefaultBranchCompletedOptions = {
39
+ open_issues_found: number;
40
+ issue_links: string[];
41
+ };
42
+ export type TPollScanFeatureBranchCompletedResult = TPollIsScanningResult & TPollScanCompletedOptions & TPollScanFeatureBranchCompletedOptions;
43
+ export type TPollScanCompletedDefaultBranchResult = TPollIsScanningResult & TPollScanCompletedOptions & TPollScanDefaultBranchCompletedOptions;
44
+ export declare function pollScanStatus(scanId: number): Promise<TPollIsScanningResult | TPollScanFeatureBranchCompletedResult | TPollScanCompletedDefaultBranchResult>;
45
+ export declare enum TUploadPayloadType {
46
+ Checkov = "checkov",
47
+ JsonSbom = "json-sbom"
48
+ }
49
+ export type TUploadApiOptions = {
50
+ scan_id?: number;
51
+ repository_id: string | number;
52
+ container_image_name?: string;
53
+ payload_type: TUploadPayloadType;
54
+ payload: string;
55
+ };
56
+ export type TUploadResult = {
57
+ success: number;
58
+ };
59
+ export declare function uploadCustomScanResult(data: TUploadApiOptions): Promise<TUploadResult>;
60
+ export {};
@@ -0,0 +1,52 @@
1
+ import axios from 'axios';
2
+ import { getApiKey } from './configuration.js';
3
+ import { outputDebug } from './output.js';
4
+ const getApiUrl = () => process.env.AIKIDO_API || 'https://app.aikido.dev';
5
+ const getApiHeaders = () => ({
6
+ 'Content-Type': 'application/json',
7
+ 'X-AIK-API-SECRET': getApiKey(),
8
+ });
9
+ export async function startScan(data) {
10
+ const requestUrl = `${getApiUrl()}/api/integrations/continuous_integration/scan/repository`;
11
+ const requestConfig = {
12
+ method: 'POST',
13
+ data,
14
+ headers: getApiHeaders(),
15
+ };
16
+ outputDebug(`API request: ${requestUrl}`);
17
+ outputDebug(requestConfig);
18
+ const resultData = (await axios(requestUrl, requestConfig)).data;
19
+ outputDebug(resultData);
20
+ return resultData;
21
+ }
22
+ export async function pollScanStatus(scanId) {
23
+ const requestUrl = `${getApiUrl()}/api/integrations/continuous_integration/scan/repository`;
24
+ const requestConfig = {
25
+ method: 'GET',
26
+ params: { scan_id: scanId },
27
+ headers: getApiHeaders(),
28
+ };
29
+ outputDebug(`API request: ${requestUrl}`);
30
+ outputDebug(requestConfig);
31
+ const resultData = (await axios(requestUrl, requestConfig)).data;
32
+ outputDebug(resultData);
33
+ return resultData;
34
+ }
35
+ export var TUploadPayloadType;
36
+ (function (TUploadPayloadType) {
37
+ TUploadPayloadType["Checkov"] = "checkov";
38
+ TUploadPayloadType["JsonSbom"] = "json-sbom";
39
+ })(TUploadPayloadType || (TUploadPayloadType = {}));
40
+ export async function uploadCustomScanResult(data) {
41
+ const requestUrl = `${getApiUrl()}/api/integrations/continuous_integration/scan/custom`;
42
+ const requestConfig = {
43
+ method: 'POST',
44
+ data,
45
+ headers: getApiHeaders(),
46
+ };
47
+ outputDebug(`API request: ${requestUrl}`);
48
+ outputDebug(requestConfig);
49
+ const resultData = (await axios(requestUrl, requestConfig)).data;
50
+ outputDebug(resultData);
51
+ return resultData;
52
+ }
@@ -0,0 +1,8 @@
1
+ import { Command } from 'commander';
2
+ declare function cli(apiKey: string): void;
3
+ export declare const cliSetup: (program: Command) => Command;
4
+ declare const _default: {
5
+ cli: typeof cli;
6
+ cliSetup: (program: Command) => Command;
7
+ };
8
+ export default _default;
@@ -0,0 +1,18 @@
1
+ import { Argument } from 'commander';
2
+ import { setApiKey } from '../configuration.js';
3
+ import { outputError, outputLog } from '../output.js';
4
+ function cli(apiKey) {
5
+ if (apiKey && apiKey.trim().length != 128) {
6
+ outputError('That does not seem right, please verify your api key');
7
+ }
8
+ setApiKey(apiKey);
9
+ outputLog(apiKey
10
+ ? 'Your new Aikido API key has been set'
11
+ : 'Your Aikido API key has been removed');
12
+ }
13
+ export const cliSetup = (program) => program
14
+ .command('apikey')
15
+ .addArgument(new Argument('<key>', 'Your Aikido public CI API key. See also: https://app.aikido.dev/settings/integrations/continuous-integration. To remove your apikey, leave the <key> argument value empty.').argOptional())
16
+ .description('Set (or remove) your Aikido public CI API key.')
17
+ .action(cli);
18
+ export default { cli, cliSetup };
@@ -0,0 +1,36 @@
1
+ import { Command } from 'commander';
2
+ import { TPollIsScanningResult, TPollScanCompletedDefaultBranchResult, TPollScanFeatureBranchCompletedResult, TScanApiOptions } from '../aikidoApi.js';
3
+ type TScanArguments = {
4
+ repoId: string | number;
5
+ baseCommitId: string;
6
+ headCommitId: string;
7
+ branchName: string;
8
+ options: TScanApiOptions;
9
+ pollInterval: number;
10
+ onStart?: () => void | null;
11
+ onStartComplete?: (startResult: any) => void | null;
12
+ onStartFail?: (error: any) => void | null;
13
+ onScanStart?: (startResult: TPollIsScanningResult | TPollScanFeatureBranchCompletedResult | TPollScanCompletedDefaultBranchResult) => void | null;
14
+ onNextPoll?: (pollResult: TPollIsScanningResult | TPollScanFeatureBranchCompletedResult | TPollScanCompletedDefaultBranchResult) => void | null;
15
+ onScanComplete?: (pollResult: TPollIsScanningResult | TPollScanFeatureBranchCompletedResult | TPollScanCompletedDefaultBranchResult) => void | null;
16
+ onScanFail?: (error: any) => void | null;
17
+ };
18
+ type TScanUserCliOptions = {
19
+ pullRequestTitle?: string;
20
+ pullRequestUrl?: string;
21
+ selfManagedScanners?: string[];
22
+ failOnDependencyScan?: boolean;
23
+ failOnSastScan?: boolean;
24
+ failOnIacScan?: boolean;
25
+ minimumSeverityLevel?: string;
26
+ pollInterval?: number;
27
+ };
28
+ declare function cli(repoId: string, baseCommitId: string, headCommitId: string, branchName: string, options: TScanUserCliOptions, command: string): Promise<void>;
29
+ export declare const scan: ({ repoId, baseCommitId, headCommitId, branchName, options, pollInterval, onStart, onStartComplete, onStartFail, onScanStart, onNextPoll, onScanComplete, onScanFail, }: TScanArguments) => Promise<void>;
30
+ export declare const cliSetup: (program: Command) => Command;
31
+ declare const _default: {
32
+ cli: typeof cli;
33
+ cliSetup: (program: Command) => Command;
34
+ scan: ({ repoId, baseCommitId, headCommitId, branchName, options, pollInterval, onStart, onStartComplete, onStartFail, onScanStart, onNextPoll, onScanComplete, onScanFail, }: TScanArguments) => Promise<void>;
35
+ };
36
+ export default _default;
@@ -0,0 +1,188 @@
1
+ import { Argument, InvalidArgumentError, Option } from 'commander';
2
+ import { pollScanStatus, startScan, } from '../aikidoApi.js';
3
+ import { getApiKey } from '../configuration.js';
4
+ import { outputError, outputHttpError, outputLog, startSpinner, } from '../output.js';
5
+ import chalk from 'chalk';
6
+ async function cli(repoId, baseCommitId, headCommitId, branchName, options, command) {
7
+ const apiKey = getApiKey();
8
+ if (!apiKey) {
9
+ outputError('Please set an api key using: aikido-cli apikey <key>');
10
+ }
11
+ const { apiOptions, cliOptions } = parseCliOptions(options);
12
+ let loader;
13
+ let pollCount = 1;
14
+ const onStart = () => {
15
+ loader = startSpinner('Starting Aikido Security scan');
16
+ };
17
+ const onStartComplete = (startResult) => {
18
+ loader?.succeed(`Aikido Security scan started (id: ${startResult.scan_id})`);
19
+ };
20
+ const onNextPoll = () => {
21
+ if (loader) {
22
+ loader.text = `Polling for Aikido Security scan to complete (${pollCount})`;
23
+ }
24
+ pollCount += 1;
25
+ };
26
+ const onScanStart = () => {
27
+ loader = startSpinner('Waiting for scan to complete');
28
+ };
29
+ const onScanComplete = (pollResult) => {
30
+ if (pollResult.gate_passed === true) {
31
+ loader?.succeed('Scan completed, no new issues found');
32
+ }
33
+ else {
34
+ loader?.fail('Scan completed with issues');
35
+ if (pollResult.open_issues_found) {
36
+ outputLog(chalk.gray(chalk.bold('Open issues found: ') + pollResult.open_issues_found));
37
+ }
38
+ if (pollResult.issue_links) {
39
+ outputLog(chalk.gray(pollResult.issue_links
40
+ .map((issueLink) => '- ' + issueLink)
41
+ .join('\n')));
42
+ }
43
+ if (pollResult.diff_url) {
44
+ outputLog(chalk.gray(`* Diff url: ${pollResult.diff_url}`));
45
+ }
46
+ process.exit(10);
47
+ }
48
+ };
49
+ const onFail = (error) => {
50
+ loader?.fail();
51
+ if (error.response?.status && error.response?.status === 404) {
52
+ outputError('Please verify your repoId, baseCommitId, headCommitId and branchName');
53
+ }
54
+ else {
55
+ outputHttpError(error);
56
+ }
57
+ process.exit(1);
58
+ };
59
+ await scan({
60
+ repoId,
61
+ baseCommitId,
62
+ headCommitId,
63
+ branchName,
64
+ options: apiOptions,
65
+ pollInterval: cliOptions.pollInterval,
66
+ onStart,
67
+ onStartComplete,
68
+ onStartFail: onFail,
69
+ onNextPoll,
70
+ onScanStart,
71
+ onScanComplete,
72
+ onScanFail: onFail,
73
+ });
74
+ }
75
+ export const scan = async ({ repoId, baseCommitId, headCommitId, branchName, options, pollInterval = 5, onStart, onStartComplete, onStartFail, onScanStart, onNextPoll, onScanComplete, onScanFail, }) => {
76
+ onStart?.();
77
+ let result = null;
78
+ try {
79
+ result = await startScan({
80
+ repository_id: repoId,
81
+ base_commit_id: baseCommitId,
82
+ head_commit_id: headCommitId,
83
+ branch_name: branchName,
84
+ ...options,
85
+ });
86
+ if (result.scan_id) {
87
+ onStartComplete?.(result);
88
+ }
89
+ else {
90
+ onStartFail?.(result);
91
+ return;
92
+ }
93
+ }
94
+ catch (error) {
95
+ onStartFail?.(error);
96
+ return;
97
+ }
98
+ onScanStart?.(result);
99
+ let pollResult;
100
+ const pollStatus = async () => {
101
+ try {
102
+ pollResult = await pollScanStatus(result.scan_id);
103
+ if (pollResult.all_scans_completed === false) {
104
+ onNextPoll?.(pollResult);
105
+ setTimeout(pollStatus, pollInterval * 1000);
106
+ }
107
+ else {
108
+ onScanComplete?.(pollResult);
109
+ }
110
+ }
111
+ catch (error) {
112
+ onScanFail?.(error);
113
+ }
114
+ };
115
+ pollStatus();
116
+ };
117
+ const parseCliOptions = (userCliOptions) => {
118
+ const apiOptions = { version: '1.0.5' };
119
+ const cliOptions = { pollInterval: 5 };
120
+ if (userCliOptions.pullRequestTitle) {
121
+ apiOptions.pull_request_metadata = {
122
+ ...(apiOptions.pull_request_metadata ?? {}),
123
+ title: userCliOptions.pullRequestTitle,
124
+ };
125
+ }
126
+ if (userCliOptions.pullRequestUrl) {
127
+ apiOptions.pull_request_metadata = {
128
+ ...(apiOptions.pull_request_metadata ?? {}),
129
+ url: userCliOptions.pullRequestUrl,
130
+ };
131
+ }
132
+ if (userCliOptions.selfManagedScanners) {
133
+ apiOptions.self_managed_scanners = userCliOptions.selfManagedScanners;
134
+ }
135
+ if (userCliOptions.failOnDependencyScan != undefined) {
136
+ apiOptions.fail_on_dependency_scan = userCliOptions.failOnDependencyScan;
137
+ }
138
+ if (userCliOptions.failOnSastScan != undefined) {
139
+ apiOptions.fail_on_sast_scan = userCliOptions.failOnSastScan;
140
+ }
141
+ if (userCliOptions.failOnIacScan != undefined) {
142
+ apiOptions.fail_on_iac_scan = userCliOptions.failOnIacScan;
143
+ }
144
+ if (userCliOptions.minimumSeverityLevel) {
145
+ apiOptions.minimum_severity = userCliOptions.minimumSeverityLevel;
146
+ }
147
+ if (userCliOptions.pollInterval &&
148
+ (isNaN(userCliOptions.pollInterval) || userCliOptions.pollInterval <= 0)) {
149
+ outputError('Please provide a valid poll interval');
150
+ }
151
+ else if (userCliOptions.pollInterval) {
152
+ cliOptions.pollInterval = userCliOptions.pollInterval;
153
+ }
154
+ return { apiOptions, cliOptions };
155
+ };
156
+ const validateCommitId = (value) => {
157
+ const testCommitId = (commitId) => commitId.length === 40 && /^[0-9a-f]{40}$/.test(commitId);
158
+ if (testCommitId(value) === false) {
159
+ throw new InvalidArgumentError('Please provide a valid commit ID');
160
+ }
161
+ return value;
162
+ };
163
+ export const cliSetup = (program) => program
164
+ .command('scan')
165
+ .addArgument(new Argument('<repository_id>', 'The internal GitHub/Gitlab/Bitbucket/.. repository id you want to scan.').argRequired())
166
+ .addArgument(new Argument('<base_commit_id>', 'The base commit of the code you want to scan (e.g. the commit where you branched from for your PR or the initial commit of your repo)')
167
+ .argRequired()
168
+ .argParser(validateCommitId))
169
+ .addArgument(new Argument('<head_commit_id>', 'The latest commit you want to include in your scan (e.g. the latest commit id of your pull request)')
170
+ .argRequired()
171
+ .argParser(validateCommitId))
172
+ .addArgument(new Argument('<branch_name>', 'The branch name')
173
+ .argOptional()
174
+ .default('main'))
175
+ .option('--pull-request-title <title>', 'Your pull request title')
176
+ .option('--pull-request-url <url>', 'Your pull request URL')
177
+ .addOption(new Option('--self-managed-scanners <scanners...>', 'Set the minimum severity level. Accepted options are: LOW, MEDIUM, HIGH and CRITICAL.').choices(['checkov', 'json-sbom']))
178
+ .option('--expected-amount-json-sboms <amount>', 'The expected amount of json sbombs')
179
+ .addOption(new Option('--no-fail-on-dependency-scan', "Don't fail when scanning depedencies..."))
180
+ .option('--fail-on-sast-scan', 'Let Aikido fail when new static code analysis issues have been detected...')
181
+ .option('--fail-on-iac-scan', 'Let Aikido fail when new infrastructure as code issues have been detected...')
182
+ .addOption(new Option('--minimum-severity-level <level>', 'Set the minimum severity level. Accepted options are: LOW, MEDIUM, HIGH and CRITICAL.').choices(['LOW', 'MEDIUM', 'HIGH', 'CRITICAL']))
183
+ .addOption(new Option('--poll-interval [interval]', 'The poll interval when checking for an updated scan result')
184
+ .preset(5)
185
+ .argParser(parseFloat))
186
+ .description('Run a scan of an Aikido repo.')
187
+ .action(cli);
188
+ export default { cli, cliSetup, scan };
@@ -0,0 +1,23 @@
1
+ import { Command } from 'commander';
2
+ import { TUploadApiOptions, TUploadPayloadType, TUploadResult } from '../aikidoApi.js';
3
+ type TUploadArguments = {
4
+ data: TUploadApiOptions;
5
+ onUploadComplete?: (startResult: TUploadResult) => void | null;
6
+ onUploadFail?: (error: any) => void | null;
7
+ };
8
+ type TUploadUserCliOptions = {
9
+ scanId?: string | number;
10
+ repositoryId: string | number;
11
+ containerImage?: string;
12
+ type: TUploadPayloadType;
13
+ file?: string;
14
+ payload?: string;
15
+ };
16
+ declare function cli(options: TUploadUserCliOptions, command: string): Promise<void>;
17
+ export declare const upload: ({ data, onUploadComplete, onUploadFail, }: TUploadArguments) => Promise<void>;
18
+ export declare const cliSetup: (program: Command) => Command;
19
+ declare const _default: {
20
+ cli: typeof cli;
21
+ cliSetup: (program: Command) => Command;
22
+ };
23
+ export default _default;