From 7a87205431d630c6c08c5758c2f9dc7c1918d340 Mon Sep 17 00:00:00 2001 From: srinandan Date: Wed, 25 Sep 2024 22:38:49 +0000 Subject: [PATCH 1/2] bug: allow setting continueOnErr to false or not at all #546 --- internal/client/flowhooks/flowhooks.go | 6 +++--- internal/cmd/flowhooks/crtfh.go | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/client/flowhooks/flowhooks.go b/internal/client/flowhooks/flowhooks.go index cbc3c0e8e..dc73bf9fb 100644 --- a/internal/client/flowhooks/flowhooks.go +++ b/internal/client/flowhooks/flowhooks.go @@ -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, ",") + "}" diff --git a/internal/cmd/flowhooks/crtfh.go b/internal/cmd/flowhooks/crtfh.go index fea3f23b0..1c5b1f2c7 100644 --- a/internal/cmd/flowhooks/crtfh.go +++ b/internal/cmd/flowhooks/crtfh.go @@ -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") From 0d2c81734c24c5cb4f4454886f4c6d17a3c53d23 Mon Sep 17 00:00:00 2001 From: srinandan Date: Wed, 25 Sep 2024 22:39:56 +0000 Subject: [PATCH 2/2] chore: update unit tests #546 --- internal/client/flowhooks/flowhook_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/client/flowhooks/flowhook_test.go b/internal/client/flowhooks/flowhook_test.go index bbba65ea7..f7a4b0a35 100644 --- a/internal/client/flowhooks/flowhook_test.go +++ b/internal/client/flowhooks/flowhook_test.go @@ -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) } }