Updated rule-update command
@@ -17,17 +17,18 @@ package commands
import (
"fmt"
- "github.com/amalgam8/amalgam8/cli/api"
"github.com/amalgam8/amalgam8/cli/common"
"github.com/amalgam8/amalgam8/cli/terminal"
"github.com/amalgam8/amalgam8/cli/utils"
+ ctrl "github.com/amalgam8/amalgam8/controller/client"
+ "github.com/amalgam8/amalgam8/pkg/api"
"github.com/urfave/cli"
)
// RuleUpdateCommand is used for the rule-update command.
type RuleUpdateCommand struct {
ctx *cli.Context
- controller api.ControllerClient
+ controller *ctrl.Client
term terminal.UI
}
@@ -80,7 +81,7 @@ func (cmd *RuleUpdateCommand) OnUsageError(ctx *cli.Context, err error, isSubcom
// https://godoc.org/github.com/urfave/cli#ActionFunc
func (cmd *RuleUpdateCommand) Action(ctx *cli.Context) error {
T := utils.Language(common.DefaultLanguage)
- controller, err := api.NewControllerClient(ctx)
+ controller, err := Controller(ctx)
if err != nil {
// Exit if the controller returned an error
return nil
@@ -94,15 +95,16 @@ func (cmd *RuleUpdateCommand) Action(ctx *cli.Context) error {
return err
}
- // Convert YAML to JSON
- if format == utils.YAML {
- reader, err = utils.YAMLToJSON(reader, &api.RuleList{})
+ rules := &api.RulesSet{}
+
+ // Read rules
+ err = utils.UnmarshallReader(reader, format, rules)
if err != nil {
return err
}
- }
+
// Add errors in client
- _, err = cmd.controller.UpdateRules(reader)
+ _, err = cmd.controller.UpdateRules(rules)
if err != nil {
return err
}
@@ -126,16 +128,16 @@ func (cmd *RuleUpdateCommand) DefaultAction(ctx *cli.Context) error {
return nil
}
- // Convert YAML to JSON
- if format == utils.YAML {
- reader, err = utils.YAMLToJSON(reader, &api.RuleList{})
+ rules := &api.RulesSet{}
+
+ // Read Rules
+ err = utils.UnmarshallReader(reader, format, rules)
if err != nil {
return err
}
- }
// TODO: return user-friendly errors
- _, err = cmd.controller.UpdateRules(reader)
+ _, err = cmd.controller.UpdateRules(rules)
if err != nil {
return err
}
