@fabasoad/sarif-to-slack 1.1.0 → 1.2.1
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/.github/workflows/security.yml +10 -2
- package/.github/workflows/send-sarif-to-slack.yml +6 -1
- package/.tool-versions +1 -1
- package/dist/SarifToSlackClient.d.ts.map +1 -1
- package/dist/SarifToSlackClient.js +8 -10
- package/dist/index.cjs +158 -93
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/model/Color.d.ts +5 -2
- package/dist/model/Color.d.ts.map +1 -1
- package/dist/model/Color.js +26 -17
- package/dist/model/Finding.js +3 -3
- package/dist/model/FindingArray.d.ts +2 -0
- package/dist/model/FindingArray.d.ts.map +1 -0
- package/dist/model/FindingArray.js +24 -0
- package/dist/model/SendIf.d.ts +116 -0
- package/dist/model/SendIf.d.ts.map +1 -0
- package/dist/model/SendIf.js +176 -0
- package/dist/model/SlackMessage.d.ts +23 -0
- package/dist/model/SlackMessage.d.ts.map +1 -0
- package/dist/model/SlackMessage.js +99 -0
- package/dist/representations/CompactGroupByRepresentation.js +1 -1
- package/dist/representations/CompactGroupByRunPerLevelRepresentation.js +1 -1
- package/dist/representations/CompactGroupByRunPerSeverityRepresentation.js +1 -1
- package/dist/representations/CompactGroupByRunRepresentation.js +1 -1
- package/dist/representations/CompactGroupBySarifRepresentation.js +1 -1
- package/dist/representations/CompactGroupByToolNameRepresentation.js +1 -1
- package/dist/representations/CompactTotalRepresentation.js +1 -1
- package/dist/representations/Representation.js +3 -3
- package/dist/sarif-to-slack.d.ts +14 -3
- package/dist/types.d.ts +1 -130
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -117
- package/etc/sarif-to-slack.api.md +1 -0
- package/package.json +1 -1
- package/src/SarifToSlackClient.ts +8 -12
- package/src/index.ts +12 -4
- package/src/model/Color.ts +37 -25
- package/src/model/Finding.ts +3 -3
- package/src/model/{FindingsArray.ts → FindingArray.ts} +3 -3
- package/src/model/SendIf.ts +175 -0
- package/src/{SlackMessageBuilder.ts → model/SlackMessage.ts} +31 -6
- package/src/processors/CodeQLProcessor.ts +1 -1
- package/src/representations/CompactGroupByRepresentation.ts +2 -2
- package/src/representations/CompactGroupByRunPerLevelRepresentation.ts +1 -1
- package/src/representations/CompactGroupByRunPerSeverityRepresentation.ts +1 -1
- package/src/representations/CompactGroupByRunRepresentation.ts +2 -2
- package/src/representations/CompactGroupBySarifRepresentation.ts +2 -2
- package/src/representations/CompactGroupByToolNameRepresentation.ts +2 -2
- package/src/representations/CompactTotalRepresentation.ts +2 -2
- package/src/representations/Representation.ts +4 -4
- package/src/types.ts +3 -134
- package/src/utils/Comparators.ts +1 -1
- package/test-data/sarif/osv-scanner-yarn.sarif +4 -4
- package/tests/integration/SendSarifToSlack.spec.ts +21 -5
- package/dist/SlackMessageBuilder.d.ts +0 -2
- package/dist/SlackMessageBuilder.d.ts.map +0 -1
- package/dist/SlackMessageBuilder.js +0 -91
- package/dist/model/FindingsArray.d.ts +0 -2
- package/dist/model/FindingsArray.d.ts.map +0 -1
- package/dist/model/FindingsArray.js +0 -24
|
@@ -10,4 +10,4 @@ export default class CompactGroupByRunPerSeverityRepresentation extends CompactG
|
|
|
10
10
|
return this.composeByProperty('severity');
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29tcGFjdEdyb3VwQnlSdW5QZXJTZXZlcml0eVJlcHJlc2VudGF0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3JlcHJlc2VudGF0aW9ucy9Db21wYWN0R3JvdXBCeVJ1blBlclNldmVyaXR5UmVwcmVzZW50YXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTywrQkFBK0IsTUFBTSxtQ0FBbUMsQ0FBQTtBQUUvRTs7Ozs7R0FLRztBQUNILE1BQU0sQ0FBQyxPQUFPLE9BQU8sMENBQTJDLFNBQVEsK0JBQStCO0lBRXJGLE9BQU87UUFDckIsT0FBTyxJQUFJLENBQUMsaUJBQWlCLENBQUMsVUFBVSxDQUFDLENBQUE7SUFDM0MsQ0FBQztDQUNGIn0=
|
|
@@ -10,10 +10,10 @@ import CompactGroupByRepresentation from './CompactGroupByRepresentation';
|
|
|
10
10
|
* [Run 2] Grype
|
|
11
11
|
* Warning: 1, Note: 20
|
|
12
12
|
* ```
|
|
13
|
-
* @internal
|
|
14
13
|
* It is an abstract class, so the only question that derived classes should
|
|
15
14
|
* "answer" is what property should be used in the compact representation, such
|
|
16
15
|
* as "level" and "severity".
|
|
16
|
+
* @internal
|
|
17
17
|
*/
|
|
18
18
|
export default class CompactGroupByRunRepresentation extends CompactGroupByRepresentation {
|
|
19
19
|
constructor(model) {
|
|
@@ -11,10 +11,10 @@ import CompactGroupByRepresentation from './CompactGroupByRepresentation';
|
|
|
11
11
|
* grype-results-02.sarif
|
|
12
12
|
* Warning: 1, Note: 20
|
|
13
13
|
* ```
|
|
14
|
-
* @internal
|
|
15
14
|
* It is an abstract class, so the only question that derived classes should
|
|
16
15
|
* "answer" is what property should be used in the compact representation, such
|
|
17
16
|
* as "level" and "severity".
|
|
17
|
+
* @internal
|
|
18
18
|
*/
|
|
19
19
|
export default class CompactGroupBySarifRepresentation extends CompactGroupByRepresentation {
|
|
20
20
|
constructor(model) {
|
|
@@ -10,10 +10,10 @@ import CompactGroupByRepresentation from './CompactGroupByRepresentation';
|
|
|
10
10
|
* Trivy
|
|
11
11
|
* Warning: 1, Note: 20
|
|
12
12
|
* ```
|
|
13
|
-
* @internal
|
|
14
13
|
* It is an abstract class, so the only question that derived classes should
|
|
15
14
|
* "answer" is what property should be used in the compact representation, such
|
|
16
15
|
* as "level" and "severity".
|
|
16
|
+
* @internal
|
|
17
17
|
*/
|
|
18
18
|
export default class CompactGroupByToolNameRepresentation extends CompactGroupByRepresentation {
|
|
19
19
|
constructor(model) {
|
|
@@ -8,10 +8,10 @@ import CompactGroupByRepresentation from './CompactGroupByRepresentation';
|
|
|
8
8
|
* Total
|
|
9
9
|
* Warning: 1, Note: 20
|
|
10
10
|
* ```
|
|
11
|
-
* @internal
|
|
12
11
|
* It is an abstract class, so the only question that derived classes should
|
|
13
12
|
* "answer" is what property should be used in the compact representation, such
|
|
14
13
|
* as "level" and "severity".
|
|
14
|
+
* @internal
|
|
15
15
|
*/
|
|
16
16
|
export default class CompactTotalRepresentation extends CompactGroupByRepresentation {
|
|
17
17
|
groupFindings() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { findingsComparatorByKey } from '../utils/Comparators';
|
|
2
|
-
import
|
|
2
|
+
import FindingArray from '../model/FindingArray';
|
|
3
3
|
/**
|
|
4
4
|
* The most base abstract class for the representation. Every representation class
|
|
5
5
|
* must be derived from this class implicitly or explicitly.
|
|
@@ -16,7 +16,7 @@ export default class Representation {
|
|
|
16
16
|
.reduce((arr, f) => {
|
|
17
17
|
arr.push(f);
|
|
18
18
|
return arr;
|
|
19
|
-
}, new
|
|
19
|
+
}, new FindingArray());
|
|
20
20
|
}
|
|
21
21
|
bold(text) {
|
|
22
22
|
return `*${text}*`;
|
|
@@ -25,4 +25,4 @@ export default class Representation {
|
|
|
25
25
|
return `_${text}_`;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVwcmVzZW50YXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcmVwcmVzZW50YXRpb25zL1JlcHJlc2VudGF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSx1QkFBdUIsRUFBRSxNQUFNLHNCQUFzQixDQUFBO0FBQzlELE9BQU8sWUFBWSxNQUFNLHVCQUF1QixDQUFBO0FBRWhEOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsT0FBTyxPQUFnQixjQUFjO0lBQ3ZCLE1BQU0sQ0FBWTtJQUVyQyxZQUFtQixLQUFpQixFQUFFLGlCQUFnQyxPQUFPO1FBQzNFLElBQUksQ0FBQyxNQUFNLEdBQUcsS0FBSyxDQUFBO1FBQ25CLElBQUksQ0FBQyxNQUFNLENBQUMsUUFBUSxHQUFHLEtBQUs7YUFDekIsUUFBUTthQUNSLEdBQUcsQ0FBQyxDQUFDLENBQVUsRUFBVyxFQUFFLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO2FBQ3ZDLElBQUksQ0FBQyx1QkFBdUIsQ0FBQyxjQUFjLENBQUMsQ0FBQzthQUM3QyxNQUFNLENBQUMsQ0FBQyxHQUFpQixFQUFFLENBQVUsRUFBZ0IsRUFBRTtZQUN0RCxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFBO1lBQ1gsT0FBTyxHQUFHLENBQUE7UUFDWixDQUFDLEVBQUUsSUFBSSxZQUFZLEVBQUUsQ0FBQyxDQUFBO0lBQzFCLENBQUM7SUFFUyxJQUFJLENBQUMsSUFBWTtRQUN6QixPQUFPLElBQUksSUFBSSxHQUFHLENBQUE7SUFDcEIsQ0FBQztJQUVTLE1BQU0sQ0FBQyxJQUFZO1FBQzNCLE9BQU8sSUFBSSxJQUFJLEdBQUcsQ0FBQTtJQUNwQixDQUFDO0NBR0YifQ==
|
package/dist/sarif-to-slack.d.ts
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
* username: 'SARIF to Slack Bot',
|
|
22
22
|
* iconUrl: 'https://example.com/icon.png',
|
|
23
23
|
* color: {
|
|
24
|
+
* default: new Color('failure'),
|
|
25
|
+
* empty: new Color('success'),
|
|
24
26
|
* bySeverity: {
|
|
25
27
|
* critical: new Color('#ff0000'),
|
|
26
28
|
* high: new Color('#ff4500'),
|
|
@@ -28,7 +30,13 @@
|
|
|
28
30
|
* low: new Color('#ffff00'),
|
|
29
31
|
* none: new Color('#808080'),
|
|
30
32
|
* unknown: new Color('#800080'),
|
|
31
|
-
*
|
|
33
|
+
* },
|
|
34
|
+
* byLevel: {
|
|
35
|
+
* error: new Color('#ff0000'),
|
|
36
|
+
* warning: new Color('#ffa500'),
|
|
37
|
+
* note: new Color('#ffff00'),
|
|
38
|
+
* none: new Color('#808080'),
|
|
39
|
+
* unknown: new Color('#800080'),
|
|
32
40
|
* },
|
|
33
41
|
* },
|
|
34
42
|
* sarif: {
|
|
@@ -88,7 +96,7 @@ export declare class Color {
|
|
|
88
96
|
* Returns a valid string that represents a color in hex format, or undefined.
|
|
89
97
|
*/
|
|
90
98
|
get value(): string | undefined;
|
|
91
|
-
private
|
|
99
|
+
private assertHexColor;
|
|
92
100
|
private mapColor;
|
|
93
101
|
}
|
|
94
102
|
|
|
@@ -127,7 +135,6 @@ export declare type ColorGroupBySeverity = ColorGroupCommon & {
|
|
|
127
135
|
declare type ColorGroupCommon = {
|
|
128
136
|
none?: Color;
|
|
129
137
|
unknown?: Color;
|
|
130
|
-
empty?: Color;
|
|
131
138
|
};
|
|
132
139
|
|
|
133
140
|
/**
|
|
@@ -149,6 +156,10 @@ export declare type ColorOptions = {
|
|
|
149
156
|
* Color scheme for the findings where certain severity is presented.
|
|
150
157
|
*/
|
|
151
158
|
bySeverity?: ColorGroupBySeverity;
|
|
159
|
+
/**
|
|
160
|
+
* Color when no findings are found.
|
|
161
|
+
*/
|
|
162
|
+
empty?: Color;
|
|
152
163
|
};
|
|
153
164
|
|
|
154
165
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { ColorOptions } from './model/Color';
|
|
2
|
-
|
|
3
|
-
* Interface for a Slack message that can be sent.
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export interface SlackMessage {
|
|
7
|
-
/**
|
|
8
|
-
* Sends the Slack message.
|
|
9
|
-
* @returns A promise that resolves to the response from the Slack webhook.
|
|
10
|
-
*/
|
|
11
|
-
send: () => Promise<string>;
|
|
12
|
-
withActor(actor?: string): void;
|
|
13
|
-
withFooter(text?: string, type?: FooterType): void;
|
|
14
|
-
withHeader(header?: string): void;
|
|
15
|
-
withRun(): void;
|
|
16
|
-
}
|
|
2
|
+
import { SendIf } from './model/SendIf';
|
|
17
3
|
/**
|
|
18
4
|
* Enum representing log levels for the service.
|
|
19
5
|
* @public
|
|
@@ -208,121 +194,6 @@ export type SarifOptions = {
|
|
|
208
194
|
recursive?: boolean;
|
|
209
195
|
extension?: SarifFileExtension;
|
|
210
196
|
};
|
|
211
|
-
/**
|
|
212
|
-
* This enum represents the condition on when message should be sent. If this
|
|
213
|
-
* condition is satisfied then message is sent, otherwise - message is not sent.
|
|
214
|
-
* @public
|
|
215
|
-
*/
|
|
216
|
-
export declare enum SendIf {
|
|
217
|
-
/**
|
|
218
|
-
* Send message only if there is at least one finding with "Critical" severity.
|
|
219
|
-
* Since it is the higher possible severity, it is the same as "Critical" or
|
|
220
|
-
* higher.
|
|
221
|
-
*/
|
|
222
|
-
SeverityCritical = 0,
|
|
223
|
-
/**
|
|
224
|
-
* Send message only if there is at least one finding with "High" severity.
|
|
225
|
-
*/
|
|
226
|
-
SeverityHigh = 1,
|
|
227
|
-
/**
|
|
228
|
-
* Send message only if there is at least one finding with "High" severity or
|
|
229
|
-
* higher, that includes "High" and "Critical".
|
|
230
|
-
*/
|
|
231
|
-
SeverityHighOrHigher = 2,
|
|
232
|
-
/**
|
|
233
|
-
* Send message only if there is at least one finding with "Medium" severity.
|
|
234
|
-
*/
|
|
235
|
-
SeverityMedium = 3,
|
|
236
|
-
/**
|
|
237
|
-
* Send message only if there is at least one finding with "Medium" severity
|
|
238
|
-
* or higher, that includes "Medium", "High" and "Critical".
|
|
239
|
-
*/
|
|
240
|
-
SeverityMediumOrHigher = 4,
|
|
241
|
-
/**
|
|
242
|
-
* Send message only if there is at least one finding with "Low" severity.
|
|
243
|
-
*/
|
|
244
|
-
SeverityLow = 5,
|
|
245
|
-
/**
|
|
246
|
-
* Send message only if there is at least one finding with "Low" severity or
|
|
247
|
-
* higher, that includes "Low", "Medium", "High" and "Critical".
|
|
248
|
-
*/
|
|
249
|
-
SeverityLowOrHigher = 6,
|
|
250
|
-
/**
|
|
251
|
-
* Send message only if there is at least one finding with "None" severity.
|
|
252
|
-
*/
|
|
253
|
-
SeverityNone = 7,
|
|
254
|
-
/**
|
|
255
|
-
* Send message only if there is at least one finding with "None" severity or
|
|
256
|
-
* higher, that includes "None", "Low", "Medium", "High" and "Critical".
|
|
257
|
-
*/
|
|
258
|
-
SeverityNoneOrHigher = 8,
|
|
259
|
-
/**
|
|
260
|
-
* Send message only if there is at least one finding with "Unknown" severity.
|
|
261
|
-
*/
|
|
262
|
-
SeverityUnknown = 9,
|
|
263
|
-
/**
|
|
264
|
-
* Send message only if there is at least one finding with "Unknown" severity
|
|
265
|
-
* or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
|
|
266
|
-
*/
|
|
267
|
-
SeverityUnknownOrHigher = 10,
|
|
268
|
-
/**
|
|
269
|
-
* Send message only if there is at least one finding with "Error" level.
|
|
270
|
-
* Since it is the higher possible level, it is the same as "Error" or higher.
|
|
271
|
-
*/
|
|
272
|
-
LevelError = 11,
|
|
273
|
-
/**
|
|
274
|
-
* Send message only if there is at least one finding with "Warning" level.
|
|
275
|
-
*/
|
|
276
|
-
LevelWarning = 12,
|
|
277
|
-
/**
|
|
278
|
-
* Send message only if there is at least one finding with "Warning" level or
|
|
279
|
-
* higher, that includes "Warning" and "Error".
|
|
280
|
-
*/
|
|
281
|
-
LevelWarningOrHigher = 13,
|
|
282
|
-
/**
|
|
283
|
-
* Send message only if there is at least one finding with "Note" level.
|
|
284
|
-
*/
|
|
285
|
-
LevelNote = 14,
|
|
286
|
-
/**
|
|
287
|
-
* Send message only if there is at least one finding with "Note" level or
|
|
288
|
-
* higher, that includes "Note", "Warning" and "Error.
|
|
289
|
-
*/
|
|
290
|
-
LevelNoteOrHigher = 15,
|
|
291
|
-
/**
|
|
292
|
-
* Send message only if there is at least one finding with "None" level.
|
|
293
|
-
*/
|
|
294
|
-
LevelNone = 16,
|
|
295
|
-
/**
|
|
296
|
-
* Send message only if there is at least one finding with "None" level or
|
|
297
|
-
* higher, that includes "None", "Note", "Warning" and "Error.
|
|
298
|
-
*/
|
|
299
|
-
LevelNoneOrHigher = 17,
|
|
300
|
-
/**
|
|
301
|
-
* Send message only if there is at least one finding with "Unknown" level.
|
|
302
|
-
*/
|
|
303
|
-
LevelUnknown = 18,
|
|
304
|
-
/**
|
|
305
|
-
* Send message only if there is at least one finding with "Unknown" level or
|
|
306
|
-
* higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
|
|
307
|
-
*/
|
|
308
|
-
LevelUnknownOrHigher = 19,
|
|
309
|
-
/**
|
|
310
|
-
* Always send a message.
|
|
311
|
-
*/
|
|
312
|
-
Always = 20,
|
|
313
|
-
/**
|
|
314
|
-
* Send a message if at least 1 vulnerability is found.
|
|
315
|
-
*/
|
|
316
|
-
Some = 21,
|
|
317
|
-
/**
|
|
318
|
-
* Send a message only if no vulnerabilities are found.
|
|
319
|
-
*/
|
|
320
|
-
Empty = 22,
|
|
321
|
-
/**
|
|
322
|
-
* Never send a message.
|
|
323
|
-
*/
|
|
324
|
-
Never = 23
|
|
325
|
-
}
|
|
326
197
|
/**
|
|
327
198
|
* Options for the SarifToSlackClient.
|
|
328
199
|
* @public
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"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C,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,CAAA;AAEjD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,MAAM,CAAC,EAAE,4BAA4B,CAAC;IACtC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,4BAA4B,CAAC;IACrC,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAA"}
|
package/dist/types.js
CHANGED
|
@@ -144,122 +144,6 @@ export var RepresentationType;
|
|
|
144
144
|
*/
|
|
145
145
|
RepresentationType[RepresentationType["CompactTotalPerSeverity"] = 7] = "CompactTotalPerSeverity";
|
|
146
146
|
})(RepresentationType || (RepresentationType = {}));
|
|
147
|
-
/**
|
|
148
|
-
* This enum represents the condition on when message should be sent. If this
|
|
149
|
-
* condition is satisfied then message is sent, otherwise - message is not sent.
|
|
150
|
-
* @public
|
|
151
|
-
*/
|
|
152
|
-
export var SendIf;
|
|
153
|
-
(function (SendIf) {
|
|
154
|
-
/**
|
|
155
|
-
* Send message only if there is at least one finding with "Critical" severity.
|
|
156
|
-
* Since it is the higher possible severity, it is the same as "Critical" or
|
|
157
|
-
* higher.
|
|
158
|
-
*/
|
|
159
|
-
SendIf[SendIf["SeverityCritical"] = 0] = "SeverityCritical";
|
|
160
|
-
/**
|
|
161
|
-
* Send message only if there is at least one finding with "High" severity.
|
|
162
|
-
*/
|
|
163
|
-
SendIf[SendIf["SeverityHigh"] = 1] = "SeverityHigh";
|
|
164
|
-
/**
|
|
165
|
-
* Send message only if there is at least one finding with "High" severity or
|
|
166
|
-
* higher, that includes "High" and "Critical".
|
|
167
|
-
*/
|
|
168
|
-
SendIf[SendIf["SeverityHighOrHigher"] = 2] = "SeverityHighOrHigher";
|
|
169
|
-
/**
|
|
170
|
-
* Send message only if there is at least one finding with "Medium" severity.
|
|
171
|
-
*/
|
|
172
|
-
SendIf[SendIf["SeverityMedium"] = 3] = "SeverityMedium";
|
|
173
|
-
/**
|
|
174
|
-
* Send message only if there is at least one finding with "Medium" severity
|
|
175
|
-
* or higher, that includes "Medium", "High" and "Critical".
|
|
176
|
-
*/
|
|
177
|
-
SendIf[SendIf["SeverityMediumOrHigher"] = 4] = "SeverityMediumOrHigher";
|
|
178
|
-
/**
|
|
179
|
-
* Send message only if there is at least one finding with "Low" severity.
|
|
180
|
-
*/
|
|
181
|
-
SendIf[SendIf["SeverityLow"] = 5] = "SeverityLow";
|
|
182
|
-
/**
|
|
183
|
-
* Send message only if there is at least one finding with "Low" severity or
|
|
184
|
-
* higher, that includes "Low", "Medium", "High" and "Critical".
|
|
185
|
-
*/
|
|
186
|
-
SendIf[SendIf["SeverityLowOrHigher"] = 6] = "SeverityLowOrHigher";
|
|
187
|
-
/**
|
|
188
|
-
* Send message only if there is at least one finding with "None" severity.
|
|
189
|
-
*/
|
|
190
|
-
SendIf[SendIf["SeverityNone"] = 7] = "SeverityNone";
|
|
191
|
-
/**
|
|
192
|
-
* Send message only if there is at least one finding with "None" severity or
|
|
193
|
-
* higher, that includes "None", "Low", "Medium", "High" and "Critical".
|
|
194
|
-
*/
|
|
195
|
-
SendIf[SendIf["SeverityNoneOrHigher"] = 8] = "SeverityNoneOrHigher";
|
|
196
|
-
/**
|
|
197
|
-
* Send message only if there is at least one finding with "Unknown" severity.
|
|
198
|
-
*/
|
|
199
|
-
SendIf[SendIf["SeverityUnknown"] = 9] = "SeverityUnknown";
|
|
200
|
-
/**
|
|
201
|
-
* Send message only if there is at least one finding with "Unknown" severity
|
|
202
|
-
* or higher, that includes "Unknown", "None", "Low", "Medium", "High" and "Critical".
|
|
203
|
-
*/
|
|
204
|
-
SendIf[SendIf["SeverityUnknownOrHigher"] = 10] = "SeverityUnknownOrHigher";
|
|
205
|
-
/**
|
|
206
|
-
* Send message only if there is at least one finding with "Error" level.
|
|
207
|
-
* Since it is the higher possible level, it is the same as "Error" or higher.
|
|
208
|
-
*/
|
|
209
|
-
SendIf[SendIf["LevelError"] = 11] = "LevelError";
|
|
210
|
-
/**
|
|
211
|
-
* Send message only if there is at least one finding with "Warning" level.
|
|
212
|
-
*/
|
|
213
|
-
SendIf[SendIf["LevelWarning"] = 12] = "LevelWarning";
|
|
214
|
-
/**
|
|
215
|
-
* Send message only if there is at least one finding with "Warning" level or
|
|
216
|
-
* higher, that includes "Warning" and "Error".
|
|
217
|
-
*/
|
|
218
|
-
SendIf[SendIf["LevelWarningOrHigher"] = 13] = "LevelWarningOrHigher";
|
|
219
|
-
/**
|
|
220
|
-
* Send message only if there is at least one finding with "Note" level.
|
|
221
|
-
*/
|
|
222
|
-
SendIf[SendIf["LevelNote"] = 14] = "LevelNote";
|
|
223
|
-
/**
|
|
224
|
-
* Send message only if there is at least one finding with "Note" level or
|
|
225
|
-
* higher, that includes "Note", "Warning" and "Error.
|
|
226
|
-
*/
|
|
227
|
-
SendIf[SendIf["LevelNoteOrHigher"] = 15] = "LevelNoteOrHigher";
|
|
228
|
-
/**
|
|
229
|
-
* Send message only if there is at least one finding with "None" level.
|
|
230
|
-
*/
|
|
231
|
-
SendIf[SendIf["LevelNone"] = 16] = "LevelNone";
|
|
232
|
-
/**
|
|
233
|
-
* Send message only if there is at least one finding with "None" level or
|
|
234
|
-
* higher, that includes "None", "Note", "Warning" and "Error.
|
|
235
|
-
*/
|
|
236
|
-
SendIf[SendIf["LevelNoneOrHigher"] = 17] = "LevelNoneOrHigher";
|
|
237
|
-
/**
|
|
238
|
-
* Send message only if there is at least one finding with "Unknown" level.
|
|
239
|
-
*/
|
|
240
|
-
SendIf[SendIf["LevelUnknown"] = 18] = "LevelUnknown";
|
|
241
|
-
/**
|
|
242
|
-
* Send message only if there is at least one finding with "Unknown" level or
|
|
243
|
-
* higher, that includes "Unknown", "None", "Note", "Warning" and "Error.
|
|
244
|
-
*/
|
|
245
|
-
SendIf[SendIf["LevelUnknownOrHigher"] = 19] = "LevelUnknownOrHigher";
|
|
246
|
-
/**
|
|
247
|
-
* Always send a message.
|
|
248
|
-
*/
|
|
249
|
-
SendIf[SendIf["Always"] = 20] = "Always";
|
|
250
|
-
/**
|
|
251
|
-
* Send a message if at least 1 vulnerability is found.
|
|
252
|
-
*/
|
|
253
|
-
SendIf[SendIf["Some"] = 21] = "Some";
|
|
254
|
-
/**
|
|
255
|
-
* Send a message only if no vulnerabilities are found.
|
|
256
|
-
*/
|
|
257
|
-
SendIf[SendIf["Empty"] = 22] = "Empty";
|
|
258
|
-
/**
|
|
259
|
-
* Never send a message.
|
|
260
|
-
*/
|
|
261
|
-
SendIf[SendIf["Never"] = 23] = "Never";
|
|
262
|
-
})(SendIf || (SendIf = {}));
|
|
263
147
|
/**
|
|
264
148
|
* Enum of security severity.
|
|
265
149
|
* @privateRemarks Order should remain unchanged. It is used in multiple places,
|
|
@@ -291,4 +175,4 @@ export var SecurityLevel;
|
|
|
291
175
|
SecurityLevel[SecurityLevel["Warning"] = 3] = "Warning";
|
|
292
176
|
SecurityLevel[SecurityLevel["Error"] = 4] = "Error";
|
|
293
177
|
})(SecurityLevel || (SecurityLevel = {}));
|
|
294
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
178
|
+
//# sourceMappingURL=data:application/json;base64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ozs7Ozs7T0FVRztJQUNILCtHQUFrQyxDQUFBO0lBQ2xDOzs7Ozs7O09BT0c7SUFDSCwyRkFBd0IsQ0FBQTtJQUN4Qjs7Ozs7OztPQU9HO0lBQ0gsaUdBQTJCLENBQUE7QUFDN0IsQ0FBQyxFQWxGVyxrQkFBa0IsS0FBbEIsa0JBQWtCLFFBa0Y3QjtBQW1ERDs7Ozs7O0dBTUc7QUFDSCxNQUFNLENBQU4sSUFBWSxnQkFPWDtBQVBELFdBQVksZ0JBQWdCO0lBQzFCLDZEQUFXLENBQUE7SUFDWCx1REFBUSxDQUFBO0lBQ1IscURBQU8sQ0FBQTtJQUNQLDJEQUFVLENBQUE7SUFDVix1REFBUSxDQUFBO0lBQ1IsK0RBQVksQ0FBQTtBQUNkLENBQUMsRUFQVyxnQkFBZ0IsS0FBaEIsZ0JBQWdCLFFBTzNCO0FBRUQ7Ozs7OztHQU1HO0FBQ0gsTUFBTSxDQUFOLElBQVksYUFNWDtBQU5ELFdBQVksYUFBYTtJQUN2Qix1REFBVyxDQUFBO0lBQ1gsaURBQVEsQ0FBQTtJQUNSLGlEQUFRLENBQUE7SUFDUix1REFBVyxDQUFBO0lBQ1gsbURBQVMsQ0FBQTtBQUNYLENBQUMsRUFOVyxhQUFhLEtBQWIsYUFBYSxRQU14QiJ9
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from 'fs'
|
|
2
2
|
import { Log } from 'sarif'
|
|
3
3
|
import Logger from './Logger'
|
|
4
|
-
import { SlackMessageBuilder } from './SlackMessageBuilder'
|
|
5
4
|
import {
|
|
6
5
|
LogOptions,
|
|
7
6
|
RunData,
|
|
@@ -9,9 +8,7 @@ import {
|
|
|
9
8
|
SarifOptions,
|
|
10
9
|
SarifToSlackClientOptions,
|
|
11
10
|
SecurityLevel,
|
|
12
|
-
SecuritySeverity
|
|
13
|
-
SendIf,
|
|
14
|
-
SlackMessage
|
|
11
|
+
SecuritySeverity
|
|
15
12
|
} from './types'
|
|
16
13
|
import System from './System'
|
|
17
14
|
import { extractListOfFiles } from './utils/FileUtils'
|
|
@@ -19,7 +16,9 @@ import { createRepresentation } from './representations/RepresentationFactory'
|
|
|
19
16
|
import { createFinding } from './model/Finding'
|
|
20
17
|
import { findToolComponent, findToolComponentDriver } from './utils/SarifUtils'
|
|
21
18
|
import { identifyColor } from './model/Color'
|
|
22
|
-
import
|
|
19
|
+
import FindingArray from './model/FindingArray'
|
|
20
|
+
import { createSlackMessage, SlackMessage } from './model/SlackMessage'
|
|
21
|
+
import { SendIf, sendIfLogMessage } from './model/SendIf'
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* Service to convert SARIF files to Slack messages and send them.
|
|
@@ -45,13 +44,10 @@ export class SarifToSlackClient {
|
|
|
45
44
|
|
|
46
45
|
public static async create(opts: SarifToSlackClientOptions): Promise<SarifToSlackClient> {
|
|
47
46
|
const instance = new SarifToSlackClient(opts.log)
|
|
48
|
-
Logger.trace('opts', opts)
|
|
49
47
|
instance._sendIf = opts.sendIf ?? instance._sendIf
|
|
50
48
|
instance._sarifModel = await SarifToSlackClient.buildModel(opts.sarif)
|
|
51
|
-
Logger.trace('instance._sarifModel', instance._sarifModel)
|
|
52
49
|
instance._message = await SarifToSlackClient.initialize(instance._sarifModel, opts)
|
|
53
|
-
|
|
54
|
-
return instance;
|
|
50
|
+
return instance
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
private static async buildModel(sarifOpts: SarifOptions): Promise<SarifModel> {
|
|
@@ -60,7 +56,7 @@ export class SarifToSlackClient {
|
|
|
60
56
|
throw new Error(`No SARIF files found at the provided path: ${sarifOpts.path}`)
|
|
61
57
|
}
|
|
62
58
|
|
|
63
|
-
const model: SarifModel = { sarifFiles, runs: [], findings: new
|
|
59
|
+
const model: SarifModel = { sarifFiles, runs: [], findings: new FindingArray() }
|
|
64
60
|
const runIdGenerator: Generator<number> = SarifToSlackClient.createRunIdGenerator()
|
|
65
61
|
for (const sarifPath of sarifFiles) {
|
|
66
62
|
const sarifJson: string = await fs.readFile(sarifPath, 'utf8')
|
|
@@ -99,7 +95,7 @@ export class SarifToSlackClient {
|
|
|
99
95
|
sarifModel: SarifModel,
|
|
100
96
|
opts: Omit<SarifToSlackClientOptions, 'sarif' | 'log' | 'sendIf'>
|
|
101
97
|
): Promise<SlackMessage> {
|
|
102
|
-
const message: SlackMessage =
|
|
98
|
+
const message: SlackMessage = createSlackMessage(opts.webhookUrl, {
|
|
103
99
|
username: opts.username,
|
|
104
100
|
iconUrl: opts.iconUrl,
|
|
105
101
|
color: identifyColor(sarifModel.findings, opts.color),
|
|
@@ -137,7 +133,7 @@ export class SarifToSlackClient {
|
|
|
137
133
|
const text: string = await this._message.send()
|
|
138
134
|
Logger.info('Message sent. Status:', text)
|
|
139
135
|
} else {
|
|
140
|
-
Logger.info(
|
|
136
|
+
Logger.info(sendIfLogMessage(this._sendIf))
|
|
141
137
|
}
|
|
142
138
|
}
|
|
143
139
|
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
* username: 'SARIF to Slack Bot',
|
|
24
24
|
* iconUrl: 'https://example.com/icon.png',
|
|
25
25
|
* color: {
|
|
26
|
+
* default: new Color('failure'),
|
|
27
|
+
* empty: new Color('success'),
|
|
26
28
|
* bySeverity: {
|
|
27
29
|
* critical: new Color('#ff0000'),
|
|
28
30
|
* high: new Color('#ff4500'),
|
|
@@ -30,7 +32,13 @@
|
|
|
30
32
|
* low: new Color('#ffff00'),
|
|
31
33
|
* none: new Color('#808080'),
|
|
32
34
|
* unknown: new Color('#800080'),
|
|
33
|
-
*
|
|
35
|
+
* },
|
|
36
|
+
* byLevel: {
|
|
37
|
+
* error: new Color('#ff0000'),
|
|
38
|
+
* warning: new Color('#ffa500'),
|
|
39
|
+
* note: new Color('#ffff00'),
|
|
40
|
+
* none: new Color('#808080'),
|
|
41
|
+
* unknown: new Color('#800080'),
|
|
34
42
|
* },
|
|
35
43
|
* },
|
|
36
44
|
* sarif: {
|
|
@@ -75,6 +83,8 @@ export {
|
|
|
75
83
|
ColorGroupByLevel,
|
|
76
84
|
ColorGroupBySeverity
|
|
77
85
|
} from './model/Color'
|
|
86
|
+
export { SendIf } from './model/SendIf'
|
|
87
|
+
export { SlackMessage } from './model/SlackMessage'
|
|
78
88
|
export { SarifToSlackClient } from './SarifToSlackClient'
|
|
79
89
|
export {
|
|
80
90
|
FooterOptions,
|
|
@@ -86,7 +96,5 @@ export {
|
|
|
86
96
|
RepresentationType,
|
|
87
97
|
SarifFileExtension,
|
|
88
98
|
SarifOptions,
|
|
89
|
-
SarifToSlackClientOptions
|
|
90
|
-
SendIf,
|
|
91
|
-
SlackMessage,
|
|
99
|
+
SarifToSlackClientOptions
|
|
92
100
|
} from './types'
|