feat(scan): add state filter for scans endpoints (#5980)

This commit is contained in:
Víctor Fernández Poyatos
2024-12-01 15:03:28 +01:00
committed by GitHub
parent 333f74dba0
commit 2a13301d35
4 changed files with 58 additions and 1 deletions
+4
View File
@@ -166,6 +166,10 @@ class ScanFilter(ProviderRelationshipFilterSet):
started_at = DateFilter(field_name="started_at", lookup_expr="date")
next_scan_at = DateFilter(field_name="next_scan_at", lookup_expr="date")
trigger = ChoiceFilter(choices=Scan.TriggerChoices.choices)
state = ChoiceFilter(choices=StateChoices.choices)
state__in = ChoiceInFilter(
field_name="state", choices=StateChoices.choices, lookup_expr="in"
)
class Meta:
model = Scan
+48
View File
@@ -2761,6 +2761,7 @@ paths:
- duration
- provider
- task
- inserted_at
- started_at
- completed_at
- scheduled_at
@@ -2906,6 +2907,48 @@ paths:
schema:
type: string
format: date-time
- in: query
name: filter[state]
schema:
type: string
enum:
- available
- cancelled
- completed
- executing
- failed
- scheduled
description: |-
* `available` - Available
* `scheduled` - Scheduled
* `executing` - Executing
* `completed` - Completed
* `failed` - Failed
* `cancelled` - Cancelled
- in: query
name: filter[state__in]
schema:
type: array
items:
type: string
enum:
- available
- cancelled
- completed
- executing
- failed
- scheduled
description: |-
Multiple values may be separated by commas.
* `available` - Available
* `scheduled` - Scheduled
* `executing` - Executing
* `completed` - Completed
* `failed` - Failed
* `cancelled` - Cancelled
explode: false
style: form
- in: query
name: filter[trigger]
schema:
@@ -3014,6 +3057,7 @@ paths:
- duration
- provider
- task
- inserted_at
- started_at
- completed_at
- scheduled_at
@@ -7091,6 +7135,10 @@ components:
maximum: 2147483647
minimum: -2147483648
nullable: true
inserted_at:
type: string
format: date-time
readOnly: true
started_at:
type: string
format: date-time
+5
View File
@@ -16,6 +16,7 @@ from api.models import (
ProviderGroupMembership,
ProviderSecret,
Scan,
StateChoices,
User,
)
from api.rls import Tenant
@@ -1933,6 +1934,10 @@ class TestScanViewSet:
("started_at.gte", "2024-01-01", 3),
("started_at.lte", "2024-01-01", 0),
("trigger", Scan.TriggerChoices.MANUAL, 1),
("state", StateChoices.AVAILABLE, 2),
("state", StateChoices.FAILED, 1),
("state.in", f"{StateChoices.FAILED},{StateChoices.AVAILABLE}", 3),
("trigger", Scan.TriggerChoices.MANUAL, 1),
]
),
)
+1 -1
View File
@@ -127,7 +127,7 @@ def perform_scheduled_scan_task(self, tenant_id: str, provider_id: str):
"tenant_id": tenant_id,
"scan_id": str(scan_instance.id),
}
),
)
return result