FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
secureCodeBox/operator/utils/orderedhookgroups.go at v5.6.0 · secureCodeBox/secureCodeBox · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
secureCodeBox
/
secureCodeBox
Public
Notifications
You must be signed in to change notification settings
Fork
183
Star
985
Code
Issues
61
Pull requests
3
Discussions
Actions
Projects
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
secureCodeBox
/
operator
/
utils
/
orderedhookgroups.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
114 lines (95 loc) · 3.11 KB
Breadcrumbs
secureCodeBox
/
operator
/
utils
/
orderedhookgroups.go
Copy path
File metadata and controls
114 lines (95 loc) · 3.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
package
utils
import
(
"fmt"
"sort"
executionv1
"github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
)
func
CurrentHookGroup
(
orderedHookGroup
[][]
*
executionv1.
HookStatus
) ([]
*
executionv1.
HookStatus
,
error
) {
for
_
,
group
:=
range
orderedHookGroup
{
for
_
,
hookStatus
:=
range
group
{
switch
hookStatus
.
State
{
case
executionv1
.
Pending
:
return
group
,
nil
case
executionv1
.
InProgress
:
return
group
,
nil
case
executionv1
.
Failed
:
return
nil
,
fmt
.
Errorf
(
"hook %s failed to be executed"
,
hookStatus
.
HookName
)
case
executionv1
.
Cancelled
:
return
nil
,
fmt
.
Errorf
(
"hook %s was cancelled while it was executed"
,
hookStatus
.
HookName
)
case
executionv1
.
Completed
:
// continue to next group
}
}
}
return
nil
,
nil
}
func
FromUnorderedList
(
hookStatuses
[]
*
executionv1.
HookStatus
) [][]
*
executionv1.
HookStatus
{
// Group hookStatuses into a map by their prio class
hooksByPrioClass
:=
map
[
int
][]
*
executionv1.
HookStatus
{}
// keep a list of existing classes
prioClasses
:=
[]
int
{}
for
_
,
hookStatus
:=
range
hookStatuses
{
prio
:=
hookStatus
.
Priority
if
_
,
ok
:=
hooksByPrioClass
[
prio
];
ok
{
hooksByPrioClass
[
prio
]
=
append
(
hooksByPrioClass
[
prio
],
hookStatus
)
}
else
{
hooksByPrioClass
[
prio
]
=
[]
*
executionv1.
HookStatus
{
hookStatus
}
prioClasses
=
append
(
prioClasses
,
prio
)
}
}
// sort prio classes in decending order
sort
.
Slice
(
prioClasses
,
func
(
i
,
j
int
)
bool
{
return
prioClasses
[
i
]
>
prioClasses
[
j
]
})
groups
:=
[][]
*
executionv1.
HookStatus
{}
for
_
,
prioClass
:=
range
prioClasses
{
groups
=
append
(
groups
,
OrderHookStatusesInsideAPrioClass
(
hooksByPrioClass
[
prioClass
])
...
)
}
return
groups
}
func
MapHooksToHookStatus
(
hooks
[]executionv1.
ScanCompletionHook
) []
*
executionv1.
HookStatus
{
hookStatuses
:=
[]
*
executionv1.
HookStatus
{}
for
_
,
hook
:=
range
hooks
{
hookStatuses
=
append
(
hookStatuses
,
&
executionv1.
HookStatus
{
HookName
:
hook
.
Name
,
State
:
executionv1
.
Pending
,
Priority
:
hook
.
Spec
.
Priority
,
Type
:
hook
.
Spec
.
Type
,
})
}
return
hookStatuses
}
func
MapClusterHooksToHookStatus
(
hooks
[]executionv1.
ClusterScanCompletionHook
) []
*
executionv1.
HookStatus
{
hookStatuses
:=
[]
*
executionv1.
HookStatus
{}
for
_
,
hook
:=
range
hooks
{
hookStatuses
=
append
(
hookStatuses
,
&
executionv1.
HookStatus
{
HookName
:
hook
.
Name
,
State
:
executionv1
.
Pending
,
Priority
:
hook
.
Spec
.
Priority
,
Type
:
hook
.
Spec
.
Type
,
})
}
return
hookStatuses
}
func
OrderHookStatusesInsideAPrioClass
(
hookStatuses
[]
*
executionv1.
HookStatus
) [][]
*
executionv1.
HookStatus
{
groups
:=
[][]
*
executionv1.
HookStatus
{}
readOnlyGroups
:=
[]
*
executionv1.
HookStatus
{}
for
_
,
hookStatus
:=
range
hookStatuses
{
switch
hookStatus
.
Type
{
case
executionv1
.
ReadAndWrite
:
groups
=
append
(
groups
, []
*
executionv1.
HookStatus
{
hookStatus
,
})
case
executionv1
.
ReadOnly
:
readOnlyGroups
=
append
(
readOnlyGroups
,
hookStatus
)
}
}
// Append the ReadOnly Hook Group at the end if existent
if
len
(
readOnlyGroups
)
!=
0
{
groups
=
append
(
groups
,
readOnlyGroups
)
}
return
groups
}
Back
|
FazBrowse Home
|
New Git URL