@contrast/contrast 1.0.9 → 1.0.12
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/README.md +2 -2
- package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +17 -17
- package/dist/audit/{languageAnalysisEngine/report → report}/commonReportingFunctions.js +56 -35
- package/dist/audit/report/models/reportGuidanceModel.js +6 -0
- package/dist/audit/{languageAnalysisEngine/report → report}/models/reportLibraryModel.js +0 -0
- package/dist/audit/{languageAnalysisEngine/report → report}/models/reportListModel.js +0 -0
- package/dist/audit/{languageAnalysisEngine/report → report}/models/reportOutputModel.js +1 -2
- package/dist/audit/{languageAnalysisEngine/report → report}/models/reportSeverityModel.js +0 -0
- package/dist/audit/{languageAnalysisEngine/report → report}/models/severityCountModel.js +1 -0
- package/dist/audit/{languageAnalysisEngine/report → report}/reportingFeature.js +12 -8
- package/dist/audit/{languageAnalysisEngine/report → report}/utils/reportUtils.js +3 -4
- package/dist/commands/audit/auditConfig.js +3 -3
- package/dist/commands/audit/help.js +3 -1
- package/dist/commands/audit/processAudit.js +4 -2
- package/dist/commands/auth/auth.js +1 -1
- package/dist/commands/config/config.js +2 -2
- package/dist/commands/scan/processScan.js +11 -4
- package/dist/commands/scan/sca/scaAnalysis.js +20 -9
- package/dist/common/HTTPClient.js +9 -0
- package/dist/common/commonHelp.js +19 -0
- package/dist/common/errorHandling.js +2 -2
- package/dist/common/fail.js +66 -0
- package/dist/common/versionChecker.js +4 -2
- package/dist/constants/constants.js +2 -2
- package/dist/constants/locales.js +26 -11
- package/dist/constants.js +52 -5
- package/dist/index.js +5 -2
- package/dist/lambda/help.js +2 -3
- package/dist/scaAnalysis/common/scaParserForGoAndJava.js +32 -0
- package/dist/scaAnalysis/common/treeUpload.js +20 -5
- package/dist/scaAnalysis/dotnet/analysis.js +15 -3
- package/dist/scaAnalysis/go/goAnalysis.js +8 -2
- package/dist/scaAnalysis/java/analysis.js +10 -6
- package/dist/scaAnalysis/java/index.js +7 -1
- package/dist/scaAnalysis/java/javaBuildDepsParser.js +19 -3
- package/dist/scaAnalysis/javascript/index.js +3 -0
- package/dist/scaAnalysis/php/analysis.js +1 -1
- package/dist/scaAnalysis/php/index.js +12 -6
- package/dist/scaAnalysis/php/phpNewServicesMapper.js +62 -0
- package/dist/scaAnalysis/python/analysis.js +43 -5
- package/dist/scaAnalysis/python/index.js +7 -2
- package/dist/scaAnalysis/ruby/analysis.js +14 -4
- package/dist/scan/autoDetection.js +5 -13
- package/dist/scan/formatScanOutput.js +6 -5
- package/dist/scan/help.js +2 -3
- package/dist/scan/populateProjectIdAndProjectName.js +5 -0
- package/dist/scan/scan.js +4 -0
- package/dist/scan/scanConfig.js +4 -4
- package/dist/scan/scanResults.js +46 -3
- package/dist/telemetry/telemetry.js +137 -0
- package/dist/utils/commonApi.js +1 -1
- package/dist/utils/getConfig.js +2 -4
- package/dist/utils/parsedCLIOptions.js +3 -1
- package/dist/utils/requestUtils.js +7 -1
- package/package.json +4 -2
- package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +22 -29
- package/src/audit/{languageAnalysisEngine/report → report}/commonReportingFunctions.ts +80 -44
- package/src/audit/report/models/reportGuidanceModel.ts +5 -0
- package/src/audit/{languageAnalysisEngine/report → report}/models/reportLibraryModel.ts +0 -0
- package/src/audit/{languageAnalysisEngine/report → report}/models/reportListModel.ts +0 -0
- package/src/audit/{languageAnalysisEngine/report → report}/models/reportOutputModel.ts +1 -7
- package/src/audit/{languageAnalysisEngine/report → report}/models/reportSeverityModel.ts +0 -0
- package/src/audit/{languageAnalysisEngine/report → report}/models/severityCountModel.ts +2 -0
- package/src/audit/{languageAnalysisEngine/report → report}/reportingFeature.ts +16 -9
- package/src/audit/{languageAnalysisEngine/report → report}/utils/reportUtils.ts +4 -4
- package/src/commands/audit/auditConfig.ts +10 -3
- package/src/commands/audit/help.ts +3 -1
- package/src/commands/audit/processAudit.ts +16 -2
- package/src/commands/auth/auth.js +3 -1
- package/src/commands/config/config.js +4 -2
- package/src/commands/scan/processScan.js +18 -4
- package/src/commands/scan/sca/scaAnalysis.js +27 -10
- package/src/common/HTTPClient.js +15 -0
- package/src/common/commonHelp.ts +13 -0
- package/src/common/errorHandling.ts +2 -3
- package/src/common/fail.js +75 -0
- package/src/common/versionChecker.ts +4 -4
- package/src/constants/constants.js +2 -2
- package/src/constants/locales.js +35 -13
- package/src/constants.js +56 -6
- package/src/index.ts +17 -2
- package/src/lambda/help.ts +2 -3
- package/src/scaAnalysis/common/scaParserForGoAndJava.js +41 -0
- package/src/scaAnalysis/common/treeUpload.js +21 -5
- package/src/scaAnalysis/dotnet/analysis.js +21 -3
- package/src/scaAnalysis/go/goAnalysis.js +9 -2
- package/src/scaAnalysis/java/analysis.js +11 -6
- package/src/scaAnalysis/java/index.js +9 -1
- package/src/scaAnalysis/java/javaBuildDepsParser.js +25 -6
- package/src/scaAnalysis/javascript/index.js +3 -0
- package/src/scaAnalysis/php/analysis.js +1 -1
- package/src/scaAnalysis/php/index.js +12 -6
- package/src/scaAnalysis/php/phpNewServicesMapper.js +77 -0
- package/src/scaAnalysis/python/analysis.js +49 -5
- package/src/scaAnalysis/python/index.js +7 -2
- package/src/scaAnalysis/ruby/analysis.js +16 -4
- package/src/scan/autoDetection.js +6 -13
- package/src/scan/formatScanOutput.ts +7 -5
- package/src/scan/help.js +2 -3
- package/src/scan/populateProjectIdAndProjectName.js +5 -1
- package/src/scan/scan.ts +4 -0
- package/src/scan/scanConfig.js +6 -4
- package/src/scan/scanResults.js +52 -3
- package/src/telemetry/telemetry.ts +154 -0
- package/src/utils/commonApi.js +1 -1
- package/src/utils/getConfig.ts +2 -11
- package/src/utils/parsedCLIOptions.js +14 -1
- package/src/utils/requestUtils.js +8 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { getHttpClient } from '../utils/commonApi'
|
|
2
|
+
import * as crypto from 'crypto'
|
|
3
|
+
import { ContrastConf } from '../utils/getConfig'
|
|
4
|
+
|
|
5
|
+
export const TELEMETRY_CLI_COMMANDS_EVENT = 'CLI_COMMANDS'
|
|
6
|
+
export const TELEMETRY_CLI_TIME_TO_AUTH_EVENT = 'CLI_TIME_TO_AUTH'
|
|
7
|
+
|
|
8
|
+
export const sendTelemetryConfigAsConfObj = async (
|
|
9
|
+
config: ContrastConf,
|
|
10
|
+
command: string,
|
|
11
|
+
argv: string[],
|
|
12
|
+
result: string,
|
|
13
|
+
language: string
|
|
14
|
+
) => {
|
|
15
|
+
const hostParam = '--host'
|
|
16
|
+
const hostParamAlias = '-h'
|
|
17
|
+
const orgIdParam = '--organization-id'
|
|
18
|
+
const orgIdParamAlias = '-o'
|
|
19
|
+
const authParam = '--authorization'
|
|
20
|
+
const apiKeyParam = '--api-key'
|
|
21
|
+
|
|
22
|
+
let configToUse
|
|
23
|
+
|
|
24
|
+
if (
|
|
25
|
+
paramExists(argv, hostParam, hostParamAlias) &&
|
|
26
|
+
paramExists(argv, orgIdParam, orgIdParamAlias) &&
|
|
27
|
+
paramExists(argv, authParam, null) &&
|
|
28
|
+
paramExists(argv, apiKeyParam, null)
|
|
29
|
+
) {
|
|
30
|
+
//if the user has passed the values as params
|
|
31
|
+
configToUse = {
|
|
32
|
+
host: findParamValueFromArgs(argv, hostParam, hostParamAlias),
|
|
33
|
+
organizationId: findParamValueFromArgs(argv, orgIdParam, orgIdParamAlias),
|
|
34
|
+
authorization: findParamValueFromArgs(argv, authParam, null),
|
|
35
|
+
apiKey: findParamValueFromArgs(argv, apiKeyParam, null)
|
|
36
|
+
}
|
|
37
|
+
} else if (
|
|
38
|
+
config &&
|
|
39
|
+
config.get('host') &&
|
|
40
|
+
config.get('organizationId') &&
|
|
41
|
+
config.get('authorization') &&
|
|
42
|
+
config.get('apiKey')
|
|
43
|
+
) {
|
|
44
|
+
configToUse = {
|
|
45
|
+
host: config.get('host')?.slice(0, -1), //slice off extra / in url, will 404 on teamserver if we don't
|
|
46
|
+
organizationId: config.get('organizationId'),
|
|
47
|
+
authorization: config.get('authorization'),
|
|
48
|
+
apiKey: config.get('apiKey')
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
//return when unable to get config
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return await sendTelemetryConfigAsObject(
|
|
56
|
+
configToUse,
|
|
57
|
+
command,
|
|
58
|
+
argv,
|
|
59
|
+
result,
|
|
60
|
+
language
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const sendTelemetryConfigAsObject = async (
|
|
65
|
+
config: any,
|
|
66
|
+
command: string,
|
|
67
|
+
argv: string[],
|
|
68
|
+
result: string,
|
|
69
|
+
language: string
|
|
70
|
+
) => {
|
|
71
|
+
const obfuscatedParams = obfuscateParams(argv)
|
|
72
|
+
|
|
73
|
+
const requestBody = {
|
|
74
|
+
event: TELEMETRY_CLI_COMMANDS_EVENT,
|
|
75
|
+
details: {
|
|
76
|
+
ip_address: '',
|
|
77
|
+
account_name: '',
|
|
78
|
+
account_host: '',
|
|
79
|
+
company_domain: '',
|
|
80
|
+
command: `contrast ${command} ${obfuscatedParams}`,
|
|
81
|
+
app_id:
|
|
82
|
+
config && config.applicationId
|
|
83
|
+
? sha1Base64Value(config.applicationId)
|
|
84
|
+
: 'undefined',
|
|
85
|
+
project_id:
|
|
86
|
+
config && config.projectId
|
|
87
|
+
? sha1Base64Value(config.projectId)
|
|
88
|
+
: 'undefined',
|
|
89
|
+
language: language,
|
|
90
|
+
result: result,
|
|
91
|
+
additional_info: '',
|
|
92
|
+
timestamp: new Date().toUTCString()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return await sendTelemetryRequest(config, requestBody)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const sendTelemetryRequest = async (config: any, requestBody: any) => {
|
|
100
|
+
const client = getHttpClient(config)
|
|
101
|
+
return client
|
|
102
|
+
.postTelemetry(config, requestBody)
|
|
103
|
+
.then((res: any) => {
|
|
104
|
+
if (res.statusCode !== 200 && config.debug === true) {
|
|
105
|
+
console.log('Telemetry failed to send with status', res.statusCode)
|
|
106
|
+
}
|
|
107
|
+
return { statusCode: res.statusCode, statusMessage: res.statusMessage }
|
|
108
|
+
})
|
|
109
|
+
.catch((err: any) => {
|
|
110
|
+
return
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const obfuscateParams = (argv: string[]) => {
|
|
115
|
+
return argv
|
|
116
|
+
.join(' ')
|
|
117
|
+
.replace(/--(authorization [A-Z0-9]+)/gi, '--authorization *****')
|
|
118
|
+
.replace(/-(o [A-Z0-9-]+)/gi, '-o *****')
|
|
119
|
+
.replace(/--(organization-id [A-Z0-9-]+)/gi, '--organization-id *****')
|
|
120
|
+
.replace(/--(api-key [A-Z0-9]+)/gi, '--api-key *****')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const paramExists = (
|
|
124
|
+
argv: string[],
|
|
125
|
+
param: string,
|
|
126
|
+
paramAlias: string | null
|
|
127
|
+
) => {
|
|
128
|
+
return argv.find((arg: string) => arg === param || arg === paramAlias)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const findParamValueFromArgs = (
|
|
132
|
+
argv: string[],
|
|
133
|
+
param: string,
|
|
134
|
+
paramAlias: string | null
|
|
135
|
+
) => {
|
|
136
|
+
let paramAsValue
|
|
137
|
+
|
|
138
|
+
argv.forEach((arg: string, index: number) => {
|
|
139
|
+
if (
|
|
140
|
+
arg === param ||
|
|
141
|
+
(arg === paramAlias &&
|
|
142
|
+
argv[index + 1] !== undefined &&
|
|
143
|
+
argv[index + 1] !== null)
|
|
144
|
+
) {
|
|
145
|
+
paramAsValue = argv[index + 1]
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
return paramAsValue
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const sha1Base64Value = (value: any) => {
|
|
153
|
+
return crypto.createHash('sha1').update(value).digest('base64')
|
|
154
|
+
}
|
package/src/utils/commonApi.js
CHANGED
package/src/utils/getConfig.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Conf from 'conf'
|
|
2
|
+
import { CE_URL } from '../constants/constants'
|
|
2
3
|
|
|
3
4
|
type ContrastConfOptions = Partial<{
|
|
4
5
|
version: string
|
|
@@ -7,7 +8,6 @@ type ContrastConfOptions = Partial<{
|
|
|
7
8
|
orgId: string
|
|
8
9
|
authHeader: string
|
|
9
10
|
numOfRuns: number
|
|
10
|
-
updateMessageHidden: boolean
|
|
11
11
|
}>
|
|
12
12
|
|
|
13
13
|
type ContrastConf = Conf<ContrastConfOptions>
|
|
@@ -18,17 +18,8 @@ const localConfig = (name: string, version: string) => {
|
|
|
18
18
|
})
|
|
19
19
|
config.set('version', version)
|
|
20
20
|
|
|
21
|
-
if (process.env.CONTRAST_CODSEC_DISABLE_UPDATE_MESSAGE) {
|
|
22
|
-
config.set(
|
|
23
|
-
'updateMessageHidden',
|
|
24
|
-
JSON.parse(
|
|
25
|
-
process.env.CONTRAST_CODSEC_DISABLE_UPDATE_MESSAGE.toLowerCase()
|
|
26
|
-
)
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
21
|
if (!config.has('host')) {
|
|
31
|
-
config.set('host',
|
|
22
|
+
config.set('host', CE_URL)
|
|
32
23
|
}
|
|
33
24
|
return config
|
|
34
25
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
const commandLineArgs = require('command-line-args')
|
|
2
|
+
const { sendTelemetryConfigAsConfObj } = require('../telemetry/telemetry')
|
|
2
3
|
|
|
3
|
-
const getCommandLineArgsCustom = (
|
|
4
|
+
const getCommandLineArgsCustom = async (
|
|
5
|
+
contrastConf,
|
|
6
|
+
command,
|
|
7
|
+
parameterList,
|
|
8
|
+
optionDefinitions
|
|
9
|
+
) => {
|
|
4
10
|
try {
|
|
5
11
|
return commandLineArgs(optionDefinitions, {
|
|
6
12
|
argv: parameterList,
|
|
@@ -9,6 +15,13 @@ const getCommandLineArgsCustom = (parameterList, optionDefinitions) => {
|
|
|
9
15
|
caseInsensitive: true
|
|
10
16
|
})
|
|
11
17
|
} catch (e) {
|
|
18
|
+
await sendTelemetryConfigAsConfObj(
|
|
19
|
+
contrastConf,
|
|
20
|
+
command,
|
|
21
|
+
parameterList,
|
|
22
|
+
'FAILURE',
|
|
23
|
+
'undefined'
|
|
24
|
+
)
|
|
12
25
|
console.log(e.message.toString())
|
|
13
26
|
process.exit(1)
|
|
14
27
|
}
|
|
@@ -15,8 +15,15 @@ const sleep = ms => {
|
|
|
15
15
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const timeOutError = (ms, reject) => {
|
|
19
|
+
return setTimeout(() => {
|
|
20
|
+
reject(new Error(`No input detected after 30s`))
|
|
21
|
+
}, ms)
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
module.exports = {
|
|
19
25
|
sendRequest: sendRequest,
|
|
20
26
|
sleep: sleep,
|
|
21
|
-
millisToSeconds: millisToSeconds
|
|
27
|
+
millisToSeconds: millisToSeconds,
|
|
28
|
+
timeOutError: timeOutError
|
|
22
29
|
}
|