@soos-io/api-client
Version:
This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform. Register for a free trial today at https://app.soos.io/register
116 lines (115 loc) • 7.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const enums_1 = require("../enums");
const utilities_1 = require("../utilities");
const ArgumentParserBase_1 = require("./ArgumentParserBase");
class AnalysisArgumentParser extends ArgumentParserBase_1.ArgumentParserBase {
constructor(integrationName, integrationType, scanType, scriptVersion) {
super(`SOOS ${scanType}`, scanType, scriptVersion, integrationName, integrationType);
this.addBaseScanArguments();
}
static create(integrationName, integrationType, scanType, scriptVersion) {
return new AnalysisArgumentParser(integrationName, integrationType, scanType, scriptVersion);
}
addBaseScanArguments() {
this.addArgument("appVersion", "App Version", { internal: true });
this.addArgument("branchName", "The name of the branch from the SCM System.");
this.addArgument("branchURI", "The URI to the branch from the SCM System.");
this.addArgument("buildURI", "URI to CI build info.");
this.addArgument("buildVersion", "Version of application build artifacts.");
this.addArgument("commitHash", "The commit hash value from the SCM System.");
this.addArgument("contributingDeveloperId", "Contributing Developer ID", { internal: true });
this.addEnumArgument("contributingDeveloperSource", enums_1.ContributingDeveloperSource, "Contributing Developer Source", {
defaultValue: enums_1.ContributingDeveloperSource.Unknown,
excludeDefault: enums_1.ContributingDeveloperSource.Unknown,
internal: true,
});
this.addArgument("contributingDeveloperSourceName", "Contributing Developer Source Name", {
internal: true,
});
this.addEnumArgument("exportFileType", enums_1.AttributionFileTypeEnum, "The report export file type (NOTE: not all file types are available for all export formats).", {
defaultValue: enums_1.AttributionFileTypeEnum.Unknown,
excludeDefault: enums_1.AttributionFileTypeEnum.Unknown,
});
this.addEnumArgument("exportFormat", enums_1.AttributionFormatEnum, "The report export format.", {
defaultValue: enums_1.AttributionFormatEnum.Unknown,
excludeDefault: enums_1.AttributionFormatEnum.Unknown,
});
this.addEnumArgument("onFailure", enums_1.OnFailure, "Action to perform when the scan fails.", {
defaultValue: enums_1.OnFailure.Continue,
});
this.addArgument("operatingEnvironment", "Set Operating environment for information purposes only.");
this.addArgument("projectName", "Project Name - this is what will be displayed in the SOOS app.", {
required: true,
});
}
validateExportArguments(scanType, format, fileType) {
const isGeneratedScanType = scanType && utilities_1.generatedScanTypes.includes(scanType);
if (!isGeneratedScanType &&
[
enums_1.AttributionFormatEnum.CsafVex,
enums_1.AttributionFormatEnum.CycloneDx,
enums_1.AttributionFormatEnum.SoosLicenses,
enums_1.AttributionFormatEnum.SoosPackages,
enums_1.AttributionFormatEnum.SoosVulnerabilities,
enums_1.AttributionFormatEnum.Spdx,
].some((f) => f === format)) {
return `This scan type is not supported for ${format}.`;
}
switch (format) {
case enums_1.AttributionFormatEnum.CsafVex:
return fileType === enums_1.AttributionFileTypeEnum.Json
? null
: `${format} only supports ${enums_1.AttributionFileTypeEnum.Json} export.`;
case enums_1.AttributionFormatEnum.CycloneDx:
return fileType === enums_1.AttributionFileTypeEnum.Json || fileType === enums_1.AttributionFileTypeEnum.Xml
? null
: `${format} only supports ${enums_1.AttributionFileTypeEnum.Json} or ${enums_1.AttributionFileTypeEnum.Xml} export.`;
case enums_1.AttributionFormatEnum.Sarif:
return fileType === enums_1.AttributionFileTypeEnum.Json
? null
: `${format} only supports ${enums_1.AttributionFileTypeEnum.Json} export.`;
case enums_1.AttributionFormatEnum.SoosIssues:
return fileType === enums_1.AttributionFileTypeEnum.Html || fileType === enums_1.AttributionFileTypeEnum.Csv
? null
: `${format} only supports ${enums_1.AttributionFileTypeEnum.Html} or ${enums_1.AttributionFileTypeEnum.Csv} export.`;
case enums_1.AttributionFormatEnum.SoosLicenses:
case enums_1.AttributionFormatEnum.SoosPackages:
case enums_1.AttributionFormatEnum.SoosVulnerabilities:
return fileType === enums_1.AttributionFileTypeEnum.Html || fileType === enums_1.AttributionFileTypeEnum.Csv
? null
: `${format} only supports ${enums_1.AttributionFileTypeEnum.Html} or ${enums_1.AttributionFileTypeEnum.Csv} export.`;
case enums_1.AttributionFormatEnum.Spdx:
return fileType === enums_1.AttributionFileTypeEnum.Json ||
fileType === enums_1.AttributionFileTypeEnum.Text
? null
: `${format} only supports ${enums_1.AttributionFileTypeEnum.Json} or ${enums_1.AttributionFileTypeEnum.Text} export.`;
default:
return "Change the export format and file type to a supported combination.";
}
}
ensureValidExportArguments(args) {
const exportKbMessage = "See https://kb.soos.io/project-exports-and-reports for valid options.";
const hasExportFormat = !(0, utilities_1.isNil)(args.exportFormat) && args.exportFormat !== enums_1.AttributionFormatEnum.Unknown;
const hasExportFileType = !(0, utilities_1.isNil)(args.exportFileType) && args.exportFileType !== enums_1.AttributionFileTypeEnum.Unknown;
if (!hasExportFormat && !hasExportFileType) {
return;
}
if (!hasExportFormat && hasExportFileType) {
throw new Error(`Please provide a value for --exportFormat when specifying --exportFileType. ${exportKbMessage}`);
}
if (hasExportFormat && !hasExportFileType) {
throw new Error(`Please provide a value for --exportFileType when specifying --exportFormat. ${exportKbMessage}`);
}
const validationMessage = this.validateExportArguments(this.scanType, args.exportFormat, args.exportFileType);
if (validationMessage !== null) {
throw new Error(`Invalid export arguments. ${validationMessage} ${exportKbMessage}`);
}
}
parseArguments(argv) {
const args = super.parseArguments(argv);
this.ensureValidExportArguments(args);
return args;
}
}
exports.default = AnalysisArgumentParser;
;