-
Notifications
You must be signed in to change notification settings - Fork 16
/
plugin_lint.go
53 lines (45 loc) · 1.34 KB
/
plugin_lint.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
//nolint:dupl
package cmd
import (
"log"
"github.com/gatewayd-io/gatewayd/config"
"github.com/getsentry/sentry-go"
"github.com/spf13/cobra"
)
// pluginLintCmd represents the plugin lint command.
var pluginLintCmd = &cobra.Command{
Use: "lint",
Short: "Lint the GatewayD plugins config",
Run: func(cmd *cobra.Command, _ []string) {
// Enable Sentry.
if enableSentry {
// Initialize Sentry.
err := sentry.Init(sentry.ClientOptions{
Dsn: DSN,
TracesSampleRate: config.DefaultTraceSampleRate,
AttachStacktrace: config.DefaultAttachStacktrace,
})
if err != nil {
cmd.Println("Sentry initialization failed: ", err)
return
}
// Flush buffered events before the program terminates.
defer sentry.Flush(config.DefaultFlushTimeout)
// Recover from panics and report the error to Sentry.
defer sentry.Recover()
}
if err := lintConfig(Plugins, pluginConfigFile); err != nil {
log.Fatal(err)
}
cmd.Println("plugins config is valid")
},
}
func init() {
pluginCmd.AddCommand(pluginLintCmd)
pluginLintCmd.Flags().StringVarP(
&pluginConfigFile, // Already exists in run.go
"plugin-config", "p", config.GetDefaultConfigFilePath(config.PluginsConfigFilename),
"Plugin config file")
pluginLintCmd.Flags().BoolVar(
&enableSentry, "sentry", true, "Enable Sentry") // Already exists in run.go
}