Skip to content

Commit

Permalink
package update / parameter changes (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
SOOS-GSteen committed Dec 12, 2023
1 parent ebd98b9 commit ac57f17
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 53 deletions.
41 changes: 21 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@soos-io/soos-sast",
"version": "0.1.1",
"version": "0.1.2",
"description": "SOOS Static Application Security Testing (SAST) scanning support.",
"main": "bin/index.js",
"scripts": {
Expand All @@ -26,16 +26,16 @@
},
"homepage": "https://github.com/soos-io/soos-sast#readme",
"dependencies": {
"@soos-io/api-client": "^0.1.9",
"@soos-io/api-client": "^0.2.7",
"argparse": "^2.0.1",
"tslib": "^2.6.2"
},
"devDependencies": {
"@types/argparse": "^2.0.14",
"@types/glob": "^8.1.0",
"@types/node": "^20.9.4",
"prettier": "^2.8.8",
"typescript": "^5.3.2"
"@types/node": "^20.10.4",
"prettier": "^3.1.1",
"typescript": "^5.3.3"
},
"bin": {
"soos-sast": "bin/index.js"
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SOOS_SAST_CONSTANTS = {
FilePatternRegex: /\.sarif\.json$/,
};
51 changes: 33 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#!/usr/bin/env node
import { LogLevel, SOOS_CONSTANTS, ScanStatus, ScanType, soosLogger } from "@soos-io/api-client";
import {
IntegrationName,
IntegrationType,
LogLevel,
SOOS_CONSTANTS,
ScanStatus,
ScanType,
soosLogger,
} from "@soos-io/api-client";
import {
getEnvVariable,
obfuscateProperties,
ensureEnumValue,
ensureValue,
ensureNonEmptyValue,
} from "@soos-io/api-client/dist/utilities";
import { ArgumentParser } from "argparse";
import * as FileSystem from "fs";
import * as Path from "path";
import FormData from "form-data";
import { CONSTANTS } from "./utils/constants";
import { exit } from "process";
import SOOSAnalysisApiClient from "@soos-io/api-client/dist/api/SOOSAnalysisApiClient";
import { SOOS_SAST_CONSTANTS } from "./constants";
import { version } from "../package.json";

interface SOOSSASTAnalysisArgs {
apiKey: string;
Expand All @@ -24,8 +34,8 @@ interface SOOSSASTAnalysisArgs {
buildVersion: string;
clientId: string;
commitHash: string;
integrationName: string;
integrationType: string;
integrationName: IntegrationName;
integrationType: IntegrationType;
logLevel: LogLevel;
operatingEnvironment: string;
projectName: string;
Expand All @@ -42,14 +52,17 @@ class SOOSSASTAnalysis {

parser.add_argument("--apiKey", {
help: "SOOS API Key - get yours from https://app.soos.io/integrate/sast",
default: getEnvVariable(CONSTANTS.SOOS.API_KEY_ENV_VAR),
default: getEnvVariable(SOOS_CONSTANTS.EnvironmentVariables.ApiKey),
required: false,
});

parser.add_argument("--apiURL", {
help: "SOOS API URL - Intended for internal use only, do not modify.",
default: "https://api.soos.io/api/",
required: false,
type: (value: string) => {
return ensureNonEmptyValue(value, "apiURL");
},
});

parser.add_argument("--appVersion", {
Expand All @@ -59,49 +72,51 @@ class SOOSSASTAnalysis {

parser.add_argument("--branchName", {
help: "The name of the branch from the SCM System.",
default: null,
required: false,
});

parser.add_argument("--branchURI", {
help: "The URI to the branch from the SCM System.",
default: null,
required: false,
});

parser.add_argument("--buildURI", {
help: "URI to CI build info.",
default: null,
required: false,
});

parser.add_argument("--buildVersion", {
help: "Version of application build artifacts.",
default: null,
required: false,
});

parser.add_argument("--clientId", {
help: "SOOS Client ID - get yours from https://app.soos.io/integrate/sast",
default: getEnvVariable(CONSTANTS.SOOS.CLIENT_ID_ENV_VAR),
default: getEnvVariable(SOOS_CONSTANTS.EnvironmentVariables.ClientId),
required: false,
});

parser.add_argument("--commitHash", {
help: "The commit hash value from the SCM System.",
default: null,
required: false,
});

parser.add_argument("--integrationName", {
help: "Integration Name - Intended for internal use only.",
required: false,
type: (value: string) => {
return ensureEnumValue(IntegrationName, value);
},
default: IntegrationName.SoosSast,
});

parser.add_argument("--integrationType", {
help: "Integration Type - Intended for internal use only.",
required: false,
default: CONSTANTS.SOOS.DEFAULT_INTEGRATION_TYPE,
type: (value: string) => {
return ensureEnumValue(IntegrationType, value);
},
default: IntegrationType.Script,
});

parser.add_argument("--logLevel", {
Expand All @@ -115,7 +130,6 @@ class SOOSSASTAnalysis {

parser.add_argument("--operatingEnvironment", {
help: "Set Operating environment for information purposes only.",
default: null,
required: false,
});

Expand All @@ -127,6 +141,7 @@ class SOOSSASTAnalysis {
parser.add_argument("--scriptVersion", {
help: "Script Version - Intended for internal use only.",
required: false,
default: version,
});

parser.add_argument("--verbose", {
Expand Down Expand Up @@ -201,7 +216,7 @@ class SOOSSASTAnalysis {

soosLogger.logLineSeparator();
soosLogger.info(
`Analysis scan started successfully, to see the results visit: ${result.scanUrl}`
`Analysis scan started successfully, to see the results visit: ${result.scanUrl}`,
);
} catch (error) {
if (projectHash && branchHash && analysisId)
Expand Down Expand Up @@ -239,7 +254,7 @@ class SOOSSASTAnalysis {

if (sastPathStat.isDirectory()) {
const files = await FileSystem.promises.readdir(this.args.sastPath);
const sastFile = files.find((file) => CONSTANTS.SAST.FILE_REGEX.test(file));
const sastFile = files.find((file) => SOOS_SAST_CONSTANTS.FilePatternRegex.test(file));

if (!sastFile) {
throw new Error("No SAST file found in the directory.");
Expand All @@ -248,7 +263,7 @@ class SOOSSASTAnalysis {
return Path.join(this.args.sastPath, sastFile);
}

if (!CONSTANTS.SAST.FILE_REGEX.test(this.args.sastPath)) {
if (!SOOS_SAST_CONSTANTS.FilePatternRegex.test(this.args.sastPath)) {
throw new Error("The file does not match the required SAST pattern.");
}

Expand All @@ -267,8 +282,8 @@ class SOOSSASTAnalysis {
JSON.stringify(
obfuscateProperties(args as unknown as Record<string, unknown>, ["apiKey"]),
null,
2
)
2,
),
);
ensureValue(args.clientId, "clientId");
ensureValue(args.apiKey, "apiKey");
Expand Down
10 changes: 0 additions & 10 deletions src/utils/constants.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"skipLibCheck": false, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"resolveJsonModule": true,
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit ac57f17

Please sign in to comment.