-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathconfig.go
executable file
·126 lines (112 loc) · 3.07 KB
/
config.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
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
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright 2016 Skippbox, Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/bitnami-labs/kubewatch/config"
"github.com/bitnami-labs/kubewatch/pkg/client"
"github.com/bitnami-labs/kubewatch/pkg/event"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
const kubewatchConfigFile = ".kubewatch.yaml"
// configCmd represents the config command
var configCmd = &cobra.Command{
Use: "config",
Short: "modify kubewatch configuration",
Long: `
config command allows configuration of ~/.kubewatch.yaml for running kubewatch`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
var configAddCmd = &cobra.Command{
Use: "add",
Short: "add webhook config to ~/.kubewatch.yaml",
Long: `
Adds webhook config to ~/.kubewatch.yaml`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
var configTestCmd = &cobra.Command{
Use: "test",
Short: "test handler config present in ~/.kubewatch.yaml",
Long: `
Tests handler configs present in ~/.kubewatch.yaml by sending test messages`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Testing Handler configs from .kubewatch.yaml")
conf, err := config.New()
if err != nil {
logrus.Fatal(err)
}
eventHandler := client.ParseEventHandler(conf)
e := event.Event{
Namespace: "testNamespace",
Name: "testResource",
Kind: "testKind",
Component: "testComponent",
Host: "testHost",
Reason: "Tested",
Status: "Normal",
}
eventHandler.Handle(e)
},
}
var configSampleCmd = &cobra.Command{
Use: "sample",
Short: "Show a sample config file",
Long: `
Print a sample config file which can be put in ~/.kubewatch.yaml`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(config.ConfigSample)
},
}
var configViewCmd = &cobra.Command{
Use: "view",
Short: "view ~/.kubewatch.yaml",
Long: `
Display the contents of the contents of ~/.kubewatch.yaml`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stderr, "Contents of ~/.kubewatch.yaml")
configFile, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), kubewatchConfigFile))
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Print(string(configFile))
},
}
func init() {
RootCmd.AddCommand(configCmd)
configCmd.AddCommand(
configAddCmd,
configTestCmd,
configSampleCmd,
configViewCmd,
)
configAddCmd.AddCommand(
slackConfigCmd,
slackwebhookConfigCmd,
hipchatConfigCmd,
mattermostConfigCmd,
flockConfigCmd,
webhookConfigCmd,
cloudEventConfigCmd,
msteamsConfigCmd,
smtpConfigCmd,
larkConfigCmd,
)
}