Skip to content

Commit 779e838

Browse files
committed
Add detector inputs
Optional but if any are provided, then all are required
1 parent e0dcc85 commit 779e838

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ inputs:
2727
correlator:
2828
description: 'An optional identifier to distinguish between multiple dependency snapshots of the same type.'
2929
required: false
30+
detector-name:
31+
description: 'The name of the detector. If provided, detector-version and detector-url must also be provided.'
32+
required: false
33+
detector-version:
34+
description: 'The version of the detector. If provided, detector-name and detector-url must also be provided.'
35+
required: false
36+
detector-url:
37+
description: 'The URL of the detector. If provided, detector-name and detector-version must also be provided.'
38+
required: false
3039
runs:
3140
using: 'node20'
3241
main: 'dist/index.js'

index.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,49 @@ import {
1313
import ComponentDetection from './componentDetection';
1414

1515
async function run() {
16-
let manifests = await ComponentDetection.scanAndGetManifests(core.getInput('filePath'));
17-
const correlatorInput = core.getInput('correlator')?.trim() || github.context.job;
18-
19-
let snapshot = new Snapshot({
20-
name: "Component Detection",
21-
version: "0.0.1",
22-
url: "https://github.com/advanced-security/component-detection-dependency-submission-action",
23-
},
24-
github.context,
25-
{
16+
let manifests = await ComponentDetection.scanAndGetManifests(
17+
core.getInput("filePath")
18+
);
19+
const correlatorInput =
20+
core.getInput("correlator")?.trim() || github.context.job;
21+
22+
// Get detector configuration inputs
23+
const detectorName = core.getInput("detector-name")?.trim();
24+
const detectorVersion = core.getInput("detector-version")?.trim();
25+
const detectorUrl = core.getInput("detector-url")?.trim();
26+
27+
// Validate that if any detector config is provided, all must be provided
28+
const hasAnyDetectorInput = detectorName || detectorVersion || detectorUrl;
29+
const hasAllDetectorInputs = detectorName && detectorVersion && detectorUrl;
30+
31+
if (hasAnyDetectorInput && !hasAllDetectorInputs) {
32+
core.setFailed(
33+
"If any detector configuration is provided (detector-name, detector-version, detector-url), all three must be provided."
34+
);
35+
return;
36+
}
37+
38+
// Use provided detector config or defaults
39+
const detector = hasAllDetectorInputs
40+
? {
41+
name: detectorName,
42+
version: detectorVersion,
43+
url: detectorUrl,
44+
}
45+
: {
46+
name: "Component Detection",
47+
version: "0.0.1",
48+
url: "https://github.com/advanced-security/component-detection-dependency-submission-action",
49+
};
50+
51+
let snapshot = new Snapshot(detector, github.context, {
2652
correlator: correlatorInput,
27-
id: github.context.runId.toString()
53+
id: github.context.runId.toString(),
2854
});
2955

3056
core.debug(`Manifests: ${manifests?.length}`);
3157

32-
manifests?.forEach(manifest => {
58+
manifests?.forEach((manifest) => {
3359
core.debug(`Manifest: ${JSON.stringify(manifest)}`);
3460
snapshot.addManifest(manifest);
3561
});

0 commit comments

Comments
 (0)