From 265bdb46e6875cb5c75e6db8e98a38775da69391 Mon Sep 17 00:00:00 2001 From: earrage Date: Mon, 5 Nov 2018 11:49:36 -0800 Subject: Add ability to read controller nodeport IP from file - Formalize use of cloverctl config file using viper - Default name of config file is '.cloverctl.yaml' - Look for file in home directory or relative to cloverctl executable - Single value in config is for 'ControllerIP: ' - Still try and retrieve port value of clover-controller nodeport automatically - Still try and retrieve IP address of clover-controller LB if GKE environment is being used and override config file value if found in current kube context - Improve error messaging if controller connect fails - Clean up the CLI help output - Modify jmeter 'get testresult' command to avoid the use of flags and use arguments instead Change-Id: Id95d1b3d1079ac84996681db62da1f9b6b8a88b5 Signed-off-by: earrage --- clover/cloverctl/src/cloverctl/cmd/create_idsrules.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'clover/cloverctl/src/cloverctl/cmd/create_idsrules.go') diff --git a/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go b/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go index bc0d8d5..6e59297 100644 --- a/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go +++ b/clover/cloverctl/src/cloverctl/cmd/create_idsrules.go @@ -9,6 +9,7 @@ package cmd import ( "fmt" + "os" "io/ioutil" "gopkg.in/resty.v1" "github.com/ghodss/yaml" @@ -18,7 +19,7 @@ import ( var idsrulesCmd = &cobra.Command{ Use: "idsrules", - Short: "Create one or many IDS rules from yaml file", + Short: "Create one or many snort IDS rules from yaml file", Long: ``, Run: func(cmd *cobra.Command, args []string) { createIDSRules() @@ -27,30 +28,32 @@ var idsrulesCmd = &cobra.Command{ func init() { createCmd.AddCommand(idsrulesCmd) - idsrulesCmd.Flags().StringVarP(&cloverFile, "file", "f", "", "Input yaml file to add IDS rules") + idsrulesCmd.Flags().StringVarP(&cloverFile, "file", "f", "", + "Input yaml file to add IDS rules") idsrulesCmd.MarkFlagRequired("file") } func createIDSRules() { + checkControllerIP() url := controllerIP + "/snort/addrule" in, err := ioutil.ReadFile(cloverFile) if err != nil { fmt.Println("Please specify a valid rule definition yaml file") - return + os.Exit(1) } out_json, err := yaml.YAMLToJSON(in) if err != nil { - panic(err.Error()) + fmt.Printf("Invalid yaml: %v\n", err) + os.Exit(1) } resp, err := resty.R(). SetHeader("Content-Type", "application/json"). SetBody(out_json). Post(url) if err != nil { - panic(err.Error()) + fmt.Printf("Cannot connect to controller: %v\n", err) + os.Exit(1) } fmt.Printf("\n%v\n", resp) - //fmt.Println(string(out_json)) - } -- cgit 1.2.3-korg