Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Add ability to configure timeout for Scans
Browse files Browse the repository at this point in the history
Through the scan configuration a maximum number of seconds
(timeoutSeconds) can be configured.

When a scan is triggered from a configuration this number of seconds
will be added to the start time and saved as timeoutTime on the Scan
object.

If while the Scan is running the current time exceeds the timeoutTime
then the scan is automatically failed and any remaining AssetScans will
be terminated.

If no timeoutTime is provided on a scan it will be automatically timed
out 48 hours after the start time of the scan.
  • Loading branch information
Tehsmash authored and chrisgacsal committed Jun 7, 2023
1 parent 8ff44f5 commit 26f8e7e
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 100 deletions.
16 changes: 16 additions & 0 deletions api/models/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions api/models/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package models

import "time"

func (s *Scan) GetState() (ScanState, bool) {
var state ScanState
var ok bool
Expand Down Expand Up @@ -47,3 +49,25 @@ func (s *Scan) GetScanConfigScope() (ScanScopeType, bool) {

return scope, ok
}

func (s *Scan) GetTimeoutTime() (time.Time, bool) {
var timeoutTime time.Time
var ok bool

if s.TimeoutTime != nil {
timeoutTime, ok = *s.TimeoutTime, true
}

return timeoutTime, ok
}

func (s *Scan) GetTimeoutSeconds() (int, bool) {
var timeoutSec int
var ok bool

if s.ScanConfigSnapshot != nil {
timeoutSec, ok = s.ScanConfigSnapshot.GetTimeoutSeconds()
}

return timeoutSec, ok
}
11 changes: 11 additions & 0 deletions api/models/scanconfigsnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ func (s *ScanConfigSnapshot) GetMaxParallelScanners() int {

return DefaultMaxParallelScanners
}

func (s *ScanConfigSnapshot) GetTimeoutSeconds() (int, bool) {
var timeoutSec int
var ok bool

if s.TimeoutSeconds != nil {
timeoutSec, ok = *s.TimeoutSeconds, true
}

return timeoutSec, ok
}
24 changes: 24 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1056,10 +1056,18 @@ components:
endTime:
type: string
format: date-time
timeoutTime:
description: |
A time in the future when this Scan will be automatically aborted
if it is still in progress.
type: string
format: date-time
scanConfig:
$ref: '#/components/schemas/ScanConfigRelationship'
readOnly: true
scanConfigSnapshot:
$ref: '#/components/schemas/ScanConfigSnapshot'
readOnly: true
targetIDs:
description: List of target IDs that are targeted for scanning as part of this scan
type: array
Expand Down Expand Up @@ -1237,6 +1245,11 @@ components:
$ref: '#/components/schemas/ScanFamiliesConfig'
scope:
$ref: '#/components/schemas/ScanScopeType'
timeoutSeconds:
type: integer
description: |
The maximum time in seconds that a scan started from this config
should run for before being automatically aborted.
scheduled:
$ref: '#/components/schemas/RuntimeScheduleScanConfig'
maxParallelScanners:
Expand Down Expand Up @@ -1281,6 +1294,12 @@ components:
scope:
$ref: '#/components/schemas/ScanScopeType'
readOnly: true
timeoutSeconds:
type: integer
description: |
The maximum time in seconds that a scan started from this config
should run for before being automatically aborted.
readOnly: true
scheduled:
$ref: '#/components/schemas/RuntimeScheduleScanConfig'
readOnly: true
Expand Down Expand Up @@ -1315,6 +1334,11 @@ components:
$ref: '#/components/schemas/ScanFamiliesConfig'
scope:
$ref: '#/components/schemas/ScanScopeType'
timeoutSeconds:
type: integer
description: |
The maximum time in seconds that a scan started from this config
should run for before being automatically aborted.
scheduled:
$ref: '#/components/schemas/RuntimeScheduleScanConfig'
maxParallelScanners:
Expand Down
Loading

0 comments on commit 26f8e7e

Please sign in to comment.