This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
/
main.go
78 lines (63 loc) · 2.23 KB
/
main.go
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
package main
import (
"errors"
"fmt"
"os"
"github.com/datreeio/datree/pkg/evaluation"
"github.com/datreeio/datree/bl/files"
"github.com/datreeio/datree/pkg/ciContext"
"github.com/datreeio/datree/pkg/deploymentConfig"
"github.com/datreeio/datree/pkg/executor"
"github.com/datreeio/datree/pkg/fileReader"
"github.com/datreeio/datree/pkg/jsonSchemaValidator"
"github.com/datreeio/datree/pkg/networkValidator"
"github.com/datreeio/datree/pkg/cliClient"
"github.com/datreeio/datree/pkg/localConfig"
"github.com/datreeio/datree/pkg/printer"
"github.com/datreeio/datree/pkg/utils"
"github.com/datreeio/datree/bl/errorReporter"
"github.com/datreeio/datree/bl/messager"
"github.com/datreeio/datree/bl/validation"
"github.com/datreeio/datree/cmd"
"github.com/datreeio/datree/cmd/test"
)
const DEFAULT_ERR_EXIT_CODE = 1
const VIOLATIONS_FOUND_EXIT_CODE = 2
func main() {
validator := networkValidator.NewNetworkValidator()
cliClient := cliClient.NewCliClient(deploymentConfig.URL, validator)
localConfig := localConfig.NewLocalConfigClient(cliClient, validator)
ciContext := ciContext.Extract()
reporter := errorReporter.NewErrorReporter(cliClient, localConfig)
globalPrinter := printer.CreateNewPrinter()
app := &cmd.App{
Context: &cmd.Context{
LocalConfig: localConfig,
CiContext: ciContext,
Evaluator: evaluation.New(cliClient, ciContext),
CliClient: cliClient,
Messager: messager.New(cliClient),
Printer: globalPrinter,
Reader: fileReader.CreateFileReader(nil),
K8sValidator: validation.New(),
JSONSchemaValidator: jsonSchemaValidator.New(),
CommandRunner: executor.CreateNewCommandRunner(),
FilesExtractor: files.New(),
},
}
cmd := cmd.NewRootCommand(app)
defer func() {
if panicErr := recover(); panicErr != nil {
reporter.ReportPanicError(panicErr)
globalPrinter.PrintMessage(fmt.Sprintf("Unexpected error: %s\n", utils.ParseErrorToString(panicErr)), "error")
os.Exit(DEFAULT_ERR_EXIT_CODE)
}
}()
if err := cmd.Execute(); err != nil {
if errors.Is(err, test.ViolationsFoundError) {
os.Exit(VIOLATIONS_FOUND_EXIT_CODE)
}
reporter.ReportUnexpectedError(err)
os.Exit(DEFAULT_ERR_EXIT_CODE)
}
}