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
Show file tree
Hide file tree
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
Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/client/flowhooks/flowhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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, ",") + "}"
Expand Down
19 changes: 14 additions & 5 deletions internal/cmd/flowhooks/crtfh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package flowhooks

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

"github.com/spf13/cobra"
)
Expand All @@ -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() {
Expand All @@ -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")
Expand Down
Loading