Skip to content

Commit

Permalink
PA-12267 add argument parser base (#15)
Browse files Browse the repository at this point in the history
[PA-12267](https://soos.atlassian.net/browse/PA-12267)

add argument parser base
  • Loading branch information
SOOS-GSteen authored Dec 12, 2023
1 parent 1780d47 commit 0be65b7
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 12 deletions.
35 changes: 25 additions & 10 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@soos-io/api-client",
"version": "0.2.7",
"version": "0.2.8",
"description": "This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -38,11 +38,13 @@
"author": "soos",
"license": "MIT",
"dependencies": {
"argparse": "^2.0.1",
"axios": "^1.6.2",
"form-data": "^4.0.0",
"tslib": "^2.6.2"
},
"devDependencies": {
"@types/argparse": "^2.0.14",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.4",
"jest": "^29.7.0",
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const SOOS_CONSTANTS = {
Projects: "https://api-projects.soos.io/api/",
User: "https://api-user.soos.io/api/",
},
App: {
Home: "https://app.soos.io/",
},
},
Status: {
DelayTime: 5000,
Expand Down
159 changes: 159 additions & 0 deletions src/services/AnalysisArgumentParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { ArgumentParser } from "argparse";
import {
ContributingDeveloperSource,
IntegrationName,
IntegrationType,
LogLevel,
ScanType,
} from "../enums";
import { SOOS_CONSTANTS } from "../constants";
import { ensureEnumValue, ensureNonEmptyValue, getEnvVariable } from "../utilities";

const getIntegrateUrl = (scanType: ScanType) =>
`${SOOS_CONSTANTS.Urls.App.Home}integrate/${
scanType == ScanType.CSA ? "containers" : scanType.toLowerCase()
}`;

class AnalysisArgumentParser {
public scanType: ScanType;
public scriptVersion: string;
public argumentParser: ArgumentParser;

constructor(scanType: ScanType, scriptVersion: string, argumentParser: ArgumentParser) {
this.scanType = scanType;
this.scriptVersion = scriptVersion;
this.argumentParser = argumentParser;
}

static create(scanType: ScanType, scriptVersion: string): AnalysisArgumentParser {
const parser = new ArgumentParser({ description: `SOOS ${scanType}` });
return new AnalysisArgumentParser(scanType, scriptVersion, parser);
}

addBaseScanArguments() {
this.argumentParser.add_argument("--apiKey", {
help: `SOOS API Key - get yours from ${getIntegrateUrl(this.scanType)}`,
default: getEnvVariable(SOOS_CONSTANTS.EnvironmentVariables.ApiKey),
required: false,
});

this.argumentParser.add_argument("--apiURL", {
help: "SOOS API URL - Intended for internal use only, do not modify.",
default: SOOS_CONSTANTS.Urls.API.Analysis,
required: false,
type: (value: string) => {
return ensureNonEmptyValue(value, "apiURL");
},
});

this.argumentParser.add_argument("--appVersion", {
help: "App Version - Intended for internal use only.",
required: false,
});

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

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

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

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

this.argumentParser.add_argument("--clientId", {
help: `SOOS Client ID - get yours from ${getIntegrateUrl(this.scanType)}`,
default: getEnvVariable(SOOS_CONSTANTS.EnvironmentVariables.ClientId),
required: false,
});

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

this.argumentParser.add_argument("--contributingDeveloperId", {
help: "Contributing Developer ID - Intended for internal use only.",
required: false,
});

this.argumentParser.add_argument("--contributingDeveloperSource", {
help: "Contributing Developer Source - Intended for internal use only.",
required: false,
type: (value: string) => {
return ensureEnumValue(ContributingDeveloperSource, value);
},
default: ContributingDeveloperSource.Unknown,
});

this.argumentParser.add_argument("--contributingDeveloperSourceName", {
help: "Contributing Developer Source Name - Intended for internal use only.",
required: false,
});

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

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

this.argumentParser.add_argument("--logLevel", {
help: "Minimum level to show logs: PASS, IGNORE, INFO, WARN or FAIL.",
default: LogLevel.INFO,
required: false,
type: (value: string) => {
return ensureEnumValue(LogLevel, value);
},
});

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

this.argumentParser.add_argument("--projectName", {
help: "Project Name - this is what will be displayed in the SOOS app.",
required: true,
type: (value: string) => {
return ensureNonEmptyValue(value, "projectName");
},
});

this.argumentParser.add_argument("--scriptVersion", {
help: "Script Version - Intended for internal use only.",
required: false,
default: this.scriptVersion,
});

this.argumentParser.add_argument("--verbose", {
help: "Enable verbose logging.",
action: "store_true",
default: false,
required: false,
});
}
}

export default AnalysisArgumentParser;
1 change: 0 additions & 1 deletion src/services/AnalysisService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,4 @@ class AnalysisService {
}

export { GeneratedScanTypes };

export default AnalysisService;
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./AnalysisService";
export * from "./AnalysisArgumentParser";

0 comments on commit 0be65b7

Please sign in to comment.