@soos-io/api-client
Advanced tools
Comparing version
@@ -49,5 +49,3 @@ "use strict"; | ||
} | ||
throw new Error(`${apiClientName} ${rejectedResponse.request?.method?.toLocaleUpperCase()} ${rejectedResponse | ||
.config?.url}: ${rejectedResponse.response?.data?.message} (${rejectedResponse | ||
.response?.data?.code})`); | ||
throw new Error(`${apiClientName} ${rejectedResponse.request?.method?.toLocaleUpperCase()} ${rejectedResponse.config?.url}: ${rejectedResponse.response?.data?.message} (${rejectedResponse.response?.data?.code})`); | ||
} | ||
@@ -54,0 +52,0 @@ return Promise.reject(rejectedResponse); |
@@ -12,2 +12,3 @@ /// <reference types="node" /> | ||
Files: { | ||
ContributorAuditOutput: string; | ||
SoosDirectoryExclusionGlobPattern: string; | ||
@@ -19,2 +20,3 @@ SarifOutput: string; | ||
Analysis: string; | ||
Hooks: string; | ||
Projects: string; | ||
@@ -21,0 +23,0 @@ User: string; |
@@ -14,2 +14,3 @@ "use strict"; | ||
Files: { | ||
ContributorAuditOutput: "soos_contributor_audit.json", | ||
SoosDirectoryExclusionGlobPattern: "**/soos/**", | ||
@@ -21,2 +22,3 @@ SarifOutput: "results.sarif", | ||
Analysis: "https://api.soos.io/api/", | ||
Hooks: "https://api-hooks.soos.io/api/", | ||
Projects: "https://api-projects.soos.io/api/", | ||
@@ -23,0 +25,0 @@ User: "https://api-user.soos.io/api/", |
@@ -87,2 +87,5 @@ export declare enum ContributingDeveloperSource { | ||
} | ||
export declare enum ScmType { | ||
GitHub = "GitHub" | ||
} | ||
export declare enum SeverityEnum { | ||
@@ -89,0 +92,0 @@ Unknown = "Unknown", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OnFailure = exports.OutputFormat = exports.LogLevel = exports.SeverityEnum = exports.ScanType = exports.ScanStatus = exports.ManifestStatus = exports.PackageManagerType = exports.IntegrationType = exports.IntegrationName = exports.ContributingDeveloperSource = void 0; | ||
exports.OnFailure = exports.OutputFormat = exports.LogLevel = exports.SeverityEnum = exports.ScmType = exports.ScanType = exports.ScanStatus = exports.ManifestStatus = exports.PackageManagerType = exports.IntegrationType = exports.IntegrationName = exports.ContributingDeveloperSource = void 0; | ||
var ContributingDeveloperSource; | ||
@@ -97,2 +97,6 @@ (function (ContributingDeveloperSource) { | ||
})(ScanType || (exports.ScanType = ScanType = {})); | ||
var ScmType; | ||
(function (ScmType) { | ||
ScmType["GitHub"] = "GitHub"; | ||
})(ScmType || (exports.ScmType = ScmType = {})); | ||
var SeverityEnum; | ||
@@ -99,0 +103,0 @@ (function (SeverityEnum) { |
import { ArgumentParser } from "argparse"; | ||
import { ContributingDeveloperSource, IntegrationName, IntegrationType, LogLevel, OnFailure, ScanType } from "../enums"; | ||
interface IBaseScanArguments { | ||
apiKey: string; | ||
apiURL: string; | ||
import { ContributingDeveloperSource, IntegrationName, IntegrationType, OnFailure, ScanType } from "../enums"; | ||
import { ArgumentParserBase, ICommonArguments } from "./ArgumentParserBase"; | ||
interface IBaseScanArguments extends ICommonArguments { | ||
appVersion: string; | ||
@@ -11,3 +10,2 @@ branchName: string; | ||
buildVersion: string; | ||
clientId: string; | ||
commitHash: string; | ||
@@ -19,20 +17,16 @@ contributingDeveloperId: string; | ||
integrationType: IntegrationType; | ||
logLevel: LogLevel; | ||
onFailure: OnFailure; | ||
operatingEnvironment: string; | ||
projectName: string; | ||
scriptVersion: string; | ||
verbose: boolean; | ||
} | ||
declare class AnalysisArgumentParser { | ||
declare class AnalysisArgumentParser extends ArgumentParserBase { | ||
scanType: ScanType; | ||
argumentParser: ArgumentParser; | ||
constructor(scanType: ScanType, argumentParser: ArgumentParser); | ||
static create(scanType: ScanType): AnalysisArgumentParser; | ||
addBaseScanArguments(integrationName: IntegrationName, integrationType: IntegrationType, scriptVersion: string): void; | ||
addEnumArgument(parser: ArgumentParser, argName: string, enumObject: Record<string, unknown>, options?: {}, allowMultipleValues?: boolean): void; | ||
parseArguments(): any; | ||
ensureRequiredArguments(args: any): void; | ||
scriptVersion: string; | ||
integrationName: IntegrationName; | ||
integrationType: IntegrationType; | ||
constructor(argumentParser: ArgumentParser, integrationName: IntegrationName, integrationType: IntegrationType, scanType: ScanType, scriptVersion: string); | ||
static create(integrationName: IntegrationName, integrationType: IntegrationType, scanType: ScanType, scriptVersion: string): AnalysisArgumentParser; | ||
addBaseScanArguments(): void; | ||
} | ||
export default AnalysisArgumentParser; | ||
export { IBaseScanArguments }; | ||
export { IBaseScanArguments, ICommonArguments }; |
@@ -5,28 +5,17 @@ "use strict"; | ||
const enums_1 = require("../enums"); | ||
const constants_1 = require("../constants"); | ||
const utilities_1 = require("../utilities"); | ||
const getIntegrateUrl = (scanType) => `${constants_1.SOOS_CONSTANTS.Urls.App.Home}integrate/${scanType == enums_1.ScanType.CSA ? "containers" : scanType.toLowerCase()}`; | ||
class AnalysisArgumentParser { | ||
constructor(scanType, argumentParser) { | ||
const ArgumentParserBase_1 = require("./ArgumentParserBase"); | ||
class AnalysisArgumentParser extends ArgumentParserBase_1.ArgumentParserBase { | ||
constructor(argumentParser, integrationName, integrationType, scanType, scriptVersion) { | ||
super(argumentParser); | ||
this.integrationName = integrationName; | ||
this.integrationType = integrationType; | ||
this.scanType = scanType; | ||
this.argumentParser = argumentParser; | ||
this.scriptVersion = scriptVersion; | ||
} | ||
static create(scanType) { | ||
static create(integrationName, integrationType, scanType, scriptVersion) { | ||
const parser = new argparse_1.ArgumentParser({ description: `SOOS ${scanType}` }); | ||
return new AnalysisArgumentParser(scanType, parser); | ||
return new AnalysisArgumentParser(parser, integrationName, integrationType, scanType, scriptVersion); | ||
} | ||
addBaseScanArguments(integrationName, integrationType, scriptVersion) { | ||
this.argumentParser.add_argument("--apiKey", { | ||
help: `SOOS API Key - get yours from ${getIntegrateUrl(this.scanType)}`, | ||
default: (0, utilities_1.getEnvVariable)(constants_1.SOOS_CONSTANTS.EnvironmentVariables.ApiKey), | ||
required: false, | ||
}); | ||
this.argumentParser.add_argument("--apiURL", { | ||
help: "SOOS API URL - Intended for internal use only, do not modify.", | ||
default: constants_1.SOOS_CONSTANTS.Urls.API.Analysis, | ||
required: false, | ||
type: (value) => { | ||
return (0, utilities_1.ensureNonEmptyValue)(value, "apiURL"); | ||
}, | ||
}); | ||
addBaseScanArguments() { | ||
this.argumentParser.add_argument("--appVersion", { | ||
@@ -52,7 +41,2 @@ help: "App Version - Intended for internal use only.", | ||
}); | ||
this.argumentParser.add_argument("--clientId", { | ||
help: `SOOS Client ID - get yours from ${getIntegrateUrl(this.scanType)}`, | ||
default: (0, utilities_1.getEnvVariable)(constants_1.SOOS_CONSTANTS.EnvironmentVariables.ClientId), | ||
required: false, | ||
}); | ||
this.argumentParser.add_argument("--commitHash", { | ||
@@ -75,17 +59,2 @@ help: "The commit hash value from the SCM System.", | ||
}); | ||
this.addEnumArgument(this.argumentParser, "--integrationName", enums_1.IntegrationName, { | ||
help: "Integration Name - Intended for internal use only.", | ||
required: false, | ||
default: integrationName, | ||
}); | ||
this.addEnumArgument(this.argumentParser, "--integrationType", enums_1.IntegrationType, { | ||
help: "Integration Type - Intended for internal use only.", | ||
required: false, | ||
default: integrationType, | ||
}); | ||
this.addEnumArgument(this.argumentParser, "--logLevel", enums_1.LogLevel, { | ||
help: "Minimum level to show logs: PASS, IGNORE, INFO, WARN or FAIL.", | ||
default: enums_1.LogLevel.INFO, | ||
required: false, | ||
}); | ||
this.addEnumArgument(this.argumentParser, "--onFailure", enums_1.OnFailure, { | ||
@@ -107,40 +76,4 @@ help: "Action to perform when the scan fails. Options: fail_the_build, continue_on_failure.", | ||
}); | ||
this.argumentParser.add_argument("--scriptVersion", { | ||
help: "Script Version - Intended for internal use only.", | ||
required: false, | ||
default: scriptVersion, | ||
}); | ||
this.argumentParser.add_argument("--verbose", { | ||
help: "Enable verbose logging.", | ||
action: "store_true", | ||
default: false, | ||
required: false, | ||
}); | ||
} | ||
addEnumArgument(parser, argName, enumObject, options = {}, allowMultipleValues = false) { | ||
parser.add_argument(argName, { | ||
...options, | ||
type: (value) => { | ||
if (allowMultipleValues) { | ||
return value | ||
.split(",") | ||
.map((v) => v.trim()) | ||
.filter((v) => v !== "") | ||
.map((v) => (0, utilities_1.ensureEnumValue)(enumObject, v, argName)); | ||
} | ||
return (0, utilities_1.ensureEnumValue)(enumObject, value, argName); | ||
}, | ||
}); | ||
} | ||
parseArguments() { | ||
const args = this.argumentParser.parse_args(); | ||
this.ensureRequiredArguments(args); | ||
return args; | ||
} | ||
ensureRequiredArguments(args) { | ||
(0, utilities_1.ensureNonEmptyValue)(args.clientId, "clientId"); | ||
(0, utilities_1.ensureNonEmptyValue)(args.apiKey, "apiKey"); | ||
(0, utilities_1.ensureNonEmptyValue)(args.projectName, "projectName"); | ||
} | ||
} | ||
exports.default = AnalysisArgumentParser; |
@@ -6,2 +6,3 @@ import SOOSAnalysisApiClient, { ICreateScanRequestContributingDeveloperAudit, ICreateScanResponse } from "../api/SOOSAnalysisApiClient"; | ||
import FormData from "form-data"; | ||
import SOOSHooksApiClient from "../api/SOOSHooksApiClient"; | ||
interface IGenerateFormattedOutputParams { | ||
@@ -62,3 +63,4 @@ clientId: string; | ||
userApiClient: SOOSUserApiClient; | ||
constructor(analysisApiClient: SOOSAnalysisApiClient, projectsApiClient: SOOSProjectsApiClient, userApiClient: SOOSUserApiClient); | ||
hooksApiClient: SOOSHooksApiClient; | ||
constructor(analysisApiClient: SOOSAnalysisApiClient, projectsApiClient: SOOSProjectsApiClient, userApiClient: SOOSUserApiClient, hooksApiClient: SOOSHooksApiClient); | ||
static create(apiKey: string, apiURL: string): AnalysisService; | ||
@@ -65,0 +67,0 @@ private logStatusMessage; |
@@ -16,2 +16,3 @@ "use strict"; | ||
const Glob = tslib_1.__importStar(require("glob")); | ||
const SOOSHooksApiClient_1 = tslib_1.__importDefault(require("../api/SOOSHooksApiClient")); | ||
const integrationNameToEnvVariable = { | ||
@@ -38,6 +39,7 @@ [enums_1.IntegrationName.AzureDevOps]: "Build.RequestedFor", | ||
class AnalysisService { | ||
constructor(analysisApiClient, projectsApiClient, userApiClient) { | ||
constructor(analysisApiClient, projectsApiClient, userApiClient, hooksApiClient) { | ||
this.analysisApiClient = analysisApiClient; | ||
this.projectsApiClient = projectsApiClient; | ||
this.userApiClient = userApiClient; | ||
this.hooksApiClient = hooksApiClient; | ||
} | ||
@@ -48,3 +50,4 @@ static create(apiKey, apiURL) { | ||
const userApiClient = new SOOSUserApiClient_1.default(apiKey, apiURL.replace("api.", "api-user.")); | ||
return new AnalysisService(analysisApiClient, projectsApiClient, userApiClient); | ||
const hooksApiClient = new SOOSHooksApiClient_1.default(apiKey, apiURL.replace("api.", "api-hooks.")); | ||
return new AnalysisService(analysisApiClient, projectsApiClient, userApiClient, hooksApiClient); | ||
} | ||
@@ -51,0 +54,0 @@ logStatusMessage(message) { |
export * from "./AnalysisService"; | ||
export * from "./AnalysisArgumentParser"; | ||
export * from "./ArgumentParserBase"; | ||
export * from "./ContributorAuditService"; | ||
export * from "./ContributorAuditArgumentParser"; |
@@ -6,1 +6,4 @@ "use strict"; | ||
tslib_1.__exportStar(require("./AnalysisArgumentParser"), exports); | ||
tslib_1.__exportStar(require("./ArgumentParserBase"), exports); | ||
tslib_1.__exportStar(require("./ContributorAuditService"), exports); | ||
tslib_1.__exportStar(require("./ContributorAuditArgumentParser"), exports); |
@@ -16,2 +16,6 @@ import { IntegrationName, OnFailure, ScanStatus } from "./enums"; | ||
}; | ||
declare const DateUtilities: { | ||
getDate: (daysAgo?: number) => Date; | ||
getDateFromUnixUTC: (unixUTC: number) => Date; | ||
}; | ||
declare const StringUtilities: { | ||
@@ -26,2 +30,2 @@ pluralizeWord: (count: number | null | undefined, singular: string, plural?: string) => string; | ||
}; | ||
export { isNil, ensureValue, ensureEnumValue, ensureNonEmptyValue, sleep, isUrlAvailable, obfuscateProperties, convertStringToBase64, getEnvVariable, formatBytes, getAnalysisExitCodeWithMessage, StringUtilities, }; | ||
export { isNil, ensureValue, ensureEnumValue, ensureNonEmptyValue, sleep, isUrlAvailable, obfuscateProperties, convertStringToBase64, getEnvVariable, formatBytes, getAnalysisExitCodeWithMessage, DateUtilities, StringUtilities, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StringUtilities = exports.getAnalysisExitCodeWithMessage = exports.formatBytes = exports.getEnvVariable = exports.convertStringToBase64 = exports.obfuscateProperties = exports.isUrlAvailable = exports.sleep = exports.ensureNonEmptyValue = exports.ensureEnumValue = exports.ensureValue = exports.isNil = void 0; | ||
exports.StringUtilities = exports.DateUtilities = exports.getAnalysisExitCodeWithMessage = exports.formatBytes = exports.getEnvVariable = exports.convertStringToBase64 = exports.obfuscateProperties = exports.isUrlAvailable = exports.sleep = exports.ensureNonEmptyValue = exports.ensureEnumValue = exports.ensureValue = exports.isNil = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -126,2 +126,13 @@ const axios_1 = tslib_1.__importStar(require("axios")); | ||
exports.getAnalysisExitCodeWithMessage = getAnalysisExitCodeWithMessage; | ||
const DateUtilities = { | ||
getDate: (daysAgo = 0) => { | ||
const date = new Date(); | ||
date.setDate(date.getDate() - daysAgo); | ||
return date; | ||
}, | ||
getDateFromUnixUTC: (unixUTC) => { | ||
return new Date(unixUTC * 1000); | ||
}, | ||
}; | ||
exports.DateUtilities = DateUtilities; | ||
const StringUtilities = { | ||
@@ -128,0 +139,0 @@ pluralizeWord: (count, singular, plural = `${singular}s`) => { |
{ | ||
"name": "@soos-io/api-client", | ||
"version": "0.2.29", | ||
"version": "0.2.30", | ||
"description": "This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform.", | ||
@@ -17,3 +17,4 @@ "main": "dist/index.js", | ||
"test": "jest", | ||
"check": "npm run format && npm run typecheck && npm run test && npm outdated" | ||
"check": "npm run format && npm run typecheck && npm run test && npm outdated", | ||
"build:link": "npm run build && npm link" | ||
}, | ||
@@ -20,0 +21,0 @@ "publishConfig": { |
107253
32.37%64
68.42%2322
33.53%4
33.33%