File tree 3 files changed +6
-3
lines changed
3 files changed +6
-3
lines changed Original file line number Diff line number Diff line change 6
6
"io/fs"
7
7
"path/filepath"
8
8
"strings"
9
+ "sync"
9
10
10
11
"github.com/open-policy-agent/opa/ast"
11
12
@@ -14,8 +15,7 @@ import (
14
15
"github.com/aquasecurity/trivy/pkg/log"
15
16
)
16
17
17
- func init () {
18
-
18
+ var LoadAndRegister = sync .OnceFunc (func () {
19
19
modules , err := LoadEmbeddedPolicies ()
20
20
if err != nil {
21
21
// we should panic as the policies were not embedded properly
@@ -30,7 +30,7 @@ func init() {
30
30
}
31
31
32
32
RegisterRegoRules (modules )
33
- }
33
+ })
34
34
35
35
func RegisterRegoRules (modules map [string ]* ast.Module ) {
36
36
ctx := context .TODO ()
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
15
15
)
16
16
17
17
func Test_EmbeddedLoading (t * testing.T ) {
18
+ LoadAndRegister ()
18
19
19
20
frameworkRules := rules .GetRegistered ()
20
21
var found bool
Original file line number Diff line number Diff line change @@ -152,6 +152,8 @@ type DynamicMetadata struct {
152
152
}
153
153
154
154
func NewScanner (source types.Source , opts ... options.ScannerOption ) * Scanner {
155
+ LoadAndRegister ()
156
+
155
157
schema , ok := schemas .SchemaMap [source ]
156
158
if ! ok {
157
159
schema = schemas .Anything
You can’t perform that action at this time.
0 commit comments