From 8cc49eb5cc57bf1ffda899e118f79dd97b3e547a Mon Sep 17 00:00:00 2001 From: Sai Saran Vaidyanathan Date: Thu, 24 Oct 2024 11:37:32 -0700 Subject: [PATCH] Rateplan issues (#556) * fix for #555 * logic for expand * fix: bool check --- internal/client/products/rateplans.go | 10 ++++++++-- internal/cmd/products/crtrateplan.go | 2 +- internal/cmd/products/delrateplan.go | 10 +++++----- internal/cmd/products/exprateplan.go | 8 ++++---- internal/cmd/products/getrateplan.go | 10 +++++----- internal/cmd/products/listrateplan.go | 8 +++++--- internal/cmd/products/rateplans.go | 1 + 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/internal/client/products/rateplans.go b/internal/client/products/rateplans.go index f6e1c8e08..cd304d267 100644 --- a/internal/client/products/rateplans.go +++ b/internal/client/products/rateplans.go @@ -18,6 +18,7 @@ import ( "internal/apiclient" "net/url" "path" + "strconv" ) // CreateRatePlan @@ -45,9 +46,12 @@ func GetRatePlan(productName string, rateplan string) (respBody []byte, err erro } // ListRatePlan -func ListRatePlan(productName string) (respBody []byte, err error) { +func ListRatePlan(productName string, expand bool) (respBody []byte, err error) { u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans") + q := u.Query() + q.Set("expand", strconv.FormatBool(expand)) + u.RawQuery = q.Encode() respBody, err = apiclient.HttpClient(u.String()) return respBody, err } @@ -56,7 +60,9 @@ func ListRatePlan(productName string) (respBody []byte, err error) { func ExportRateplan(productName string) (respBody []byte, err error) { u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans") - + q := u.Query() + q.Set("expand", "true") + u.RawQuery = q.Encode() // don't print to sysout apiclient.ClientPrintHttpResponse.Set(false) defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) diff --git a/internal/cmd/products/crtrateplan.go b/internal/cmd/products/crtrateplan.go index 91efd3328..67d1d58ae 100644 --- a/internal/cmd/products/crtrateplan.go +++ b/internal/cmd/products/crtrateplan.go @@ -55,6 +55,6 @@ func init() { CreateRateplanCmd.Flags().StringVarP(&rateplanFile, "rateplan", "", "", "File containing Rate plane JSON. See samples for how to create the file") - _ = CreateRateplanCmd.MarkFlagRequired("apiproduct") + _ = CreateRateplanCmd.MarkFlagRequired("product") _ = CreateRateplanCmd.MarkFlagRequired("rateplan") } diff --git a/internal/cmd/products/delrateplan.go b/internal/cmd/products/delrateplan.go index a0f12da92..9eb686a95 100644 --- a/internal/cmd/products/delrateplan.go +++ b/internal/cmd/products/delrateplan.go @@ -33,17 +33,17 @@ var DelRatePlanCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { cmd.SilenceUsage = true - _, err = products.DeleteRatePlan(name, rateplan) + _, err = products.DeleteRatePlan(apiproduct, rateplan) return }, } func init() { - DelRatePlanCmd.Flags().StringVarP(&name, "name", "n", - "", "name of the API Product") - DelRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "p", + DelRatePlanCmd.Flags().StringVarP(&apiproduct, "product", "p", "", "name of the API Product") + DelRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "", + "", "Rate Plan Id") - _ = DelRatePlanCmd.MarkFlagRequired("name") + _ = DelRatePlanCmd.MarkFlagRequired("product") _ = DelRatePlanCmd.MarkFlagRequired("rateplan") } diff --git a/internal/cmd/products/exprateplan.go b/internal/cmd/products/exprateplan.go index dcda53e12..24d87a9a1 100644 --- a/internal/cmd/products/exprateplan.go +++ b/internal/cmd/products/exprateplan.go @@ -33,8 +33,8 @@ var ExpRateplanCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { cmd.SilenceUsage = true - exportFileName := "rateplan_" + name + ".json" - respBody, err := products.ExportRateplan(name) + exportFileName := "rateplan_" + apiproduct + ".json" + respBody, err := products.ExportRateplan(apiproduct) if err != nil { return err } @@ -43,8 +43,8 @@ var ExpRateplanCmd = &cobra.Command{ } func init() { - ExpRateplanCmd.Flags().StringVarP(&name, "name", "n", + ExpRateplanCmd.Flags().StringVarP(&apiproduct, "product", "p", "", "name of the API Product") - _ = ExpRateplanCmd.MarkFlagRequired("name") + _ = ExpRateplanCmd.MarkFlagRequired("product") } diff --git a/internal/cmd/products/getrateplan.go b/internal/cmd/products/getrateplan.go index 79c4e3035..c7bba80f7 100644 --- a/internal/cmd/products/getrateplan.go +++ b/internal/cmd/products/getrateplan.go @@ -33,17 +33,17 @@ var GetRatePlanCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { cmd.SilenceUsage = true - _, err = products.GetRatePlan(name, rateplan) + _, err = products.GetRatePlan(apiproduct, rateplan) return }, } func init() { - GetRatePlanCmd.Flags().StringVarP(&name, "name", "n", - "", "name of the API Product") - GetRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "p", + GetRatePlanCmd.Flags().StringVarP(&apiproduct, "product", "p", "", "name of the API Product") + GetRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "", + "", "Rate Plan Id") - _ = GetRatePlanCmd.MarkFlagRequired("name") + _ = GetRatePlanCmd.MarkFlagRequired("product") _ = GetRatePlanCmd.MarkFlagRequired("rateplan") } diff --git a/internal/cmd/products/listrateplan.go b/internal/cmd/products/listrateplan.go index 9c6c79a4e..5bf8e2ce0 100644 --- a/internal/cmd/products/listrateplan.go +++ b/internal/cmd/products/listrateplan.go @@ -33,14 +33,16 @@ var ListRatePlanCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { cmd.SilenceUsage = true - _, err = products.ListRatePlan(name) + _, err = products.ListRatePlan(apiproduct, expand) return }, } func init() { - ListRatePlanCmd.Flags().StringVarP(&name, "name", "n", + ListRatePlanCmd.Flags().StringVarP(&apiproduct, "product", "p", "", "name of the API Product") + ListRatePlanCmd.Flags().BoolVarP(&expand, "expand", "x", + false, "Expand Details") - _ = ListRatePlanCmd.MarkFlagRequired("name") + _ = ListRatePlanCmd.MarkFlagRequired("product") } diff --git a/internal/cmd/products/rateplans.go b/internal/cmd/products/rateplans.go index f657c30b3..fa65a7ef5 100644 --- a/internal/cmd/products/rateplans.go +++ b/internal/cmd/products/rateplans.go @@ -32,4 +32,5 @@ func init() { RatePlanCmd.AddCommand(ListRatePlanCmd) RatePlanCmd.AddCommand(GetRatePlanCmd) RatePlanCmd.AddCommand(DelRatePlanCmd) + RatePlanCmd.AddCommand(ExpRateplanCmd) }