-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathagent.go
More file actions
63 lines (53 loc) · 1.54 KB
/
agent.go
File metadata and controls
63 lines (53 loc) · 1.54 KB
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
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/jetstack/preflight/pkg/agent"
"github.com/jetstack/preflight/pkg/permissions"
)
var agentCmd = &cobra.Command{
Use: "agent",
Short: "start the preflight agent",
Long: `The agent will periodically gather data for the configured data
gatherers and send it to a remote backend for evaluation`,
RunE: agent.Run,
}
var agentInfoCmd = &cobra.Command{
Use: "info",
Short: "print several internal parameters of the agent",
Long: `Print several internal parameters of the agent, as the built-in OAuth2 client ID.`,
Run: func(cmd *cobra.Command, args []string) {
printVersion(true)
fmt.Println()
printOAuth2Config()
},
}
var agentRBACCmd = &cobra.Command{
Use: "rbac",
Short: "print the agent's minimal RBAC manifest",
Long: `Print RBAC string by reading GVRs`,
RunE: func(cmd *cobra.Command, args []string) error {
b, err := os.ReadFile(agent.Flags.ConfigFilePath)
if err != nil {
return fmt.Errorf("Failed to read config file: %s", err)
}
cfg, err := agent.ParseConfig(b)
if err != nil {
return fmt.Errorf("Failed to parse config file: %s", err)
}
err = agent.ValidateDataGatherers(cfg.DataGatherers)
if err != nil {
return fmt.Errorf("Failed to validate data gatherers: %s", err)
}
out := permissions.GenerateFullManifest(cfg.DataGatherers)
fmt.Print(out)
return nil
},
}
func init() {
rootCmd.AddCommand(agentCmd)
agentCmd.AddCommand(agentInfoCmd)
agentCmd.AddCommand(agentRBACCmd)
agent.InitAgentCmdFlags(agentCmd, &agent.Flags)
}