Skip to content

Commit f9ee293

Browse files
authored
Merge pull request #11 from datatheorem/support-polling-timeout
Add POLLING_TIMEOUT configuration option
2 parents adcae8e + c8d99ee commit f9ee293

4 files changed

Lines changed: 49 additions & 9 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ When `WARN_ON_SEVERITY` is specified, the action will:
6060
- `MEDIUM`: Block on medium and high severity vulnerabilities
6161
- `LOW`: Block on all severity vulnerabilities (low, medium, high)
6262

63+
### `POLLING_TIMEOUT`
64+
When `POLLING_TIMEOUT` is specified, the action will stop polling the scan result after the specified time in seconds.
65+
Defaults to 300 seconds (5 minutes).
66+
67+
6368
### Example with Vulnerability Blocking
6469
```yaml
6570
- name: Upload to Data Theorem with blocking if high or medium vulnerabilities are found
@@ -130,5 +135,6 @@ jobs:
130135
EXTERNAL_ID: "App_12230045"
131136
BLOCK_ON_SEVERITY: "HIGH" # Optional: Block build on high severity vulnerabilities
132137
WARN_ON_SEVERITY: "MEDIUM" # Optional: Warn on medium severity vulnerabilities
138+
POLLING_TIMEOUT: 300 # Optional: Stop polling the scan result after the specified time
133139

134140
```

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ inputs:
6464
Valid values: HIGH, MEDIUM, LOW. If not specified, no warnings will be shown.
6565
This requires a Data Theorem Mobile Results API Key to be set.
6666
required: false
67+
POLLING_TIMEOUT:
68+
description: >
69+
Stop polling the scan result after the specified time in seconds, default is 5 minutes.
70+
required: false
6771
runs:
6872
using: 'node20'
6973
main: 'main.js'

main.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ function run() {
105105
const external_id = core.getInput("EXTERNAL_ID");
106106
const block_on_severity = core.getInput("BLOCK_ON_SEVERITY");
107107
const warn_on_severity = core.getInput("WARN_ON_SEVERITY");
108+
const polling_timeout = core.getInput("POLLING_TIMEOUT");
109+
var parsed_polling_timeout;
110+
if (polling_timeout) {
111+
parsed_polling_timeout = parseInt(polling_timeout, 10);
112+
if (isNaN(parsed_polling_timeout)) {
113+
throw new Error("POLLING_TIMEOUT must be a number");
114+
}
115+
if (parsed_polling_timeout <= 0) {
116+
throw new Error("POLLING_TIMEOUT must be greater than 0");
117+
}
118+
}
108119
// Validate severity levels
109120
if (block_on_severity &&
110121
!["HIGH", "MEDIUM", "LOW"].includes(block_on_severity.toUpperCase())) {
@@ -259,8 +270,11 @@ function run() {
259270
}
260271
for (const scan of scan_info) {
261272
const { mobile_app_id, scan_id } = scan;
262-
// Poll for scan completion with 30-second intervals
263-
const maxWaitTime = 300000; // 5 minutes
273+
var maxWaitTime = 300000; // 5 minutes
274+
if (parsed_polling_timeout) {
275+
maxWaitTime = parsed_polling_timeout * 1000;
276+
}
277+
// Poll for scan completion with 23-second intervals
264278
const pollInterval = 23000; // 23 seconds
265279
const startTime = Date.now();
266280
console.log(`Waiting for scan ${scan_id} to complete...`);
@@ -277,8 +291,9 @@ function run() {
277291
continue;
278292
}
279293
const status_data = yield status_response.json();
280-
if (status_data.static_scan &&
281-
status_data.static_scan.status === "FAILED") {
294+
const scan_status = status_data.static_scan.status || status_data.status;
295+
if (scan_status &&
296+
["FAILED", "SCAN_ATTEMPT_ERROR", "CANCELLED"].includes(scan_status)) {
282297
console.log(`Scan ${scan_id} failed, skipping vulnerability check`);
283298
break;
284299
}

main.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ async function run() {
125125
const external_id = core.getInput("EXTERNAL_ID");
126126
const block_on_severity = core.getInput("BLOCK_ON_SEVERITY");
127127
const warn_on_severity = core.getInput("WARN_ON_SEVERITY");
128+
const polling_timeout = core.getInput("POLLING_TIMEOUT");
129+
var parsed_polling_timeout;
130+
if (polling_timeout) {
131+
parsed_polling_timeout = parseInt(polling_timeout, 10);
132+
if (isNaN(parsed_polling_timeout)) {
133+
throw new Error("POLLING_TIMEOUT must be a number");
134+
}
135+
if (parsed_polling_timeout <= 0) {
136+
throw new Error("POLLING_TIMEOUT must be greater than 0");
137+
}
138+
}
128139

129140
// Validate severity levels
130141
if (
@@ -317,8 +328,12 @@ async function run() {
317328
for (const scan of scan_info) {
318329
const { mobile_app_id, scan_id } = scan;
319330

320-
// Poll for scan completion with 30-second intervals
321-
const maxWaitTime = 300000; // 5 minutes
331+
var maxWaitTime = 300000; // 5 minutes
332+
if (parsed_polling_timeout) {
333+
maxWaitTime = parsed_polling_timeout * 1000;
334+
}
335+
336+
// Poll for scan completion with 23-second intervals
322337
const pollInterval = 23000; // 23 seconds
323338
const startTime = Date.now();
324339

@@ -348,10 +363,10 @@ async function run() {
348363
}
349364

350365
const status_data = await status_response.json();
351-
366+
const scan_status = status_data.static_scan.status || status_data.status;
352367
if (
353-
status_data.static_scan &&
354-
status_data.static_scan.status === "FAILED"
368+
scan_status &&
369+
["FAILED", "SCAN_ATTEMPT_ERROR", "CANCELLED"].includes(scan_status)
355370
) {
356371
console.log(`Scan ${scan_id} failed, skipping vulnerability check`);
357372
break;

0 commit comments

Comments
 (0)