Skip to content

Commit

Permalink
Rateplan issues (#556)
Browse files Browse the repository at this point in the history
* fix for #555

* logic for expand

* fix:
bool check
  • Loading branch information
ssvaidyanathan authored Oct 24, 2024
1 parent e45d035 commit 8cc49eb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
10 changes: 8 additions & 2 deletions internal/client/products/rateplans.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"internal/apiclient"
"net/url"
"path"
"strconv"
)

// CreateRatePlan
Expand Down Expand Up @@ -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
}
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/products/crtrateplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
10 changes: 5 additions & 5 deletions internal/cmd/products/delrateplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
8 changes: 4 additions & 4 deletions internal/cmd/products/exprateplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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")
}
10 changes: 5 additions & 5 deletions internal/cmd/products/getrateplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
8 changes: 5 additions & 3 deletions internal/cmd/products/listrateplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
1 change: 1 addition & 0 deletions internal/cmd/products/rateplans.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ func init() {
RatePlanCmd.AddCommand(ListRatePlanCmd)
RatePlanCmd.AddCommand(GetRatePlanCmd)
RatePlanCmd.AddCommand(DelRatePlanCmd)
RatePlanCmd.AddCommand(ExpRateplanCmd)
}

0 comments on commit 8cc49eb

Please sign in to comment.