Skip to content

Commit

Permalink
feat(scanresult): resource cleanup state refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtagscherer committed Sep 13, 2023
1 parent 3eef08c commit 32281e6
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 171 deletions.
99 changes: 70 additions & 29 deletions api/models/models.gen.go

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

25 changes: 25 additions & 0 deletions api/models/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package models

import "fmt"

type ResourceCleanupStateMachine map[ResourceCleanupStatusState][]ResourceCleanupStatusState

var ResourceCleanupStatusStateValidTransitions = ResourceCleanupStateMachine{
ResourceCleanupStatusStatePending: {
ResourceCleanupStatusStateSkipped,
ResourceCleanupStatusStateFailed,
ResourceCleanupStatusStateDone,
},
}

func (rcs *ResourceCleanupStatus) UpdateState(toState ResourceCleanupStatusState) error {
transitions := ResourceCleanupStatusStateValidTransitions[*rcs.State]
for _, transition := range transitions {
if transition == toState {
rcs.State = &toState
return nil
}
}

return fmt.Errorf("invalid transition, from: %s to: %s", *rcs.State, toState)
}
46 changes: 37 additions & 9 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2030,13 +2030,41 @@ components:
$ref: '#/components/schemas/AssetScan'
readOnly: true

ResourceCleanupState:
type: string
enum:
- Pending
- Skipped
- Failed
- Done
CommonStatus:
type: object
properties:
reason:
type: string
description: Machine readable message.
message:
type: string
description: Human readable message.
lastTransitionTime:
type: string
format: date-time
description: Last date time when the status has changed.

ResourceCleanupStatus:
allOf:
- $ref: '#/components/schemas/CommonStatus'
- type: object
properties:
state:
type: string
enum:
- Pending
- Skipped
- Failed
- Done
description: |
Describes the state of resource cleanup.
| State | Description |
| ------- | ---------------------------------------------------------- |
| Pending | Initial state for cleaning up resources |
| Skipped | Resource cleanup has been skipped due to Delete Job Policy |
| Failed | Cleaning up resources has been failed |
| Done | Resources have been successfully cleaned up |
AssetScanTemplate:
type: object
Expand Down Expand Up @@ -2090,7 +2118,7 @@ components:
findingsProcessed:
type: boolean
resourceCleanup:
$ref: '#/components/schemas/ResourceCleanupState'
$ref: '#/components/schemas/ResourceCleanupStatus'
stats:
$ref: '#/components/schemas/AssetScanStats'
summary:
Expand Down Expand Up @@ -2210,7 +2238,7 @@ components:
type: boolean
readOnly: true
resourceCleanup:
$ref: '#/components/schemas/ResourceCleanupState'
$ref: '#/components/schemas/ResourceCleanupStatus'
readOnly: true
stats:
$ref: '#/components/schemas/AssetScanStats'
Expand Down
Loading

0 comments on commit 32281e6

Please sign in to comment.