Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: allow setting continueOnErr to false or not at all #546 #548

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/client/flowhooks/flowhook_test.go
Original file line number Diff line number Diff line change
@@ -37,7 +37,9 @@ func TestAttach(t *testing.T) {
if _, err := sharedflows.Create(name, path.Join(cliPath, testFolder, "test_flow.zip")); err != nil {
t.Fatalf("%v", err)
}
if _, err := Attach("PreProxyFlowHook", "test description", name, true); err != nil {
cPtr := new(bool)
*cPtr = true
if _, err := Attach("PreProxyFlowHook", "test description", name, cPtr); err != nil {
t.Fatalf("%v", err)
}
}
6 changes: 3 additions & 3 deletions internal/client/flowhooks/flowhooks.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import (
)

// Attach
func Attach(name string, description string, sharedflow string, continueOnErr bool) (respBody []byte, err error) {
func Attach(name string, description string, sharedflow string, continueOnErr *bool) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())

flowhook := []string{}
@@ -36,8 +36,8 @@ func Attach(name string, description string, sharedflow string, continueOnErr bo

flowhook = append(flowhook, "\"sharedFlow\":\""+sharedflow+"\"")

if continueOnErr {
flowhook = append(flowhook, "\"continueOnError\":"+strconv.FormatBool(continueOnErr))
if continueOnErr != nil {
flowhook = append(flowhook, "\"continueOnError\":"+strconv.FormatBool(*continueOnErr))
}

payload := "{" + strings.Join(flowhook, ",") + "}"
19 changes: 14 additions & 5 deletions internal/cmd/flowhooks/crtfh.go
Original file line number Diff line number Diff line change
@@ -15,8 +15,10 @@
package flowhooks

import (
"fmt"
"internal/apiclient"
"internal/client/flowhooks"
"strconv"

"github.com/spf13/cobra"
)
@@ -34,14 +36,21 @@ var CreateCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true

_, err = flowhooks.Attach(name, description, sharedflow, continueOnErr)
if continueOnErrStr != "" {
continueOnErrPtr = new(bool)
*continueOnErrPtr, err = strconv.ParseBool(continueOnErrStr)
if err != nil {
return fmt.Errorf("continueOnErr should be a boolean value: %v", err)
}
}
_, err = flowhooks.Attach(name, description, sharedflow, continueOnErrPtr)
return
},
}

var (
description, sharedflow string
continueOnErr bool
continueOnErrPtr *bool
description, sharedflow, continueOnErrStr string
)

func init() {
@@ -51,8 +60,8 @@ func init() {
"", "Description for the flowhook")
CreateCmd.Flags().StringVarP(&sharedflow, "sharedflow", "s",
"", "Sharedflow name")
CreateCmd.Flags().BoolVarP(&continueOnErr, "continue", "c",
true, "Continue on error")
CreateCmd.Flags().StringVarP(&continueOnErrStr, "continue", "c",
"", "Continue on error")

_ = CreateCmd.MarkFlagRequired("name")
_ = CreateCmd.MarkFlagRequired("sharedflow")
Loading