Skip to content

Commit

Permalink
Merge pull request #497 from apigee/issue496
Browse files Browse the repository at this point in the history
bug: fixes type conversion for kvm entries #496
  • Loading branch information
ssvaidyanathan authored Jul 7, 2024
2 parents 485afef + b450bda commit d23221b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/cmd/kvm/crtentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var CreateEntryCmd = &cobra.Command{
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
value = getKVMString(value)
_, err = kvm.CreateEntry(proxyName, mapName, keyName, []byte(value))
return
},
Expand Down
16 changes: 16 additions & 0 deletions internal/cmd/kvm/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package kvm

import (
"fmt"
"strconv"

"github.com/spf13/cobra"
)

Expand All @@ -36,3 +39,16 @@ func init() {
EntryCmd.AddCommand(ImpEntryCmd)
EntryCmd.AddCommand(UpdateEntryCmd)
}

func getKVMString(value string) string {
var err error
// convert any boolean, float or integer to string
if _, err = strconv.ParseBool(value); err == nil {
value = fmt.Sprintf("\"%s\"", value)
} else if _, err = strconv.ParseInt(value, 10, 0); err == nil {
value = fmt.Sprintf("\"%s\"", value)
} else if _, err = strconv.ParseFloat(value, 0); err == nil {
value = fmt.Sprintf("\"%s\"", value)
}
return value
}
1 change: 1 addition & 0 deletions internal/cmd/kvm/updentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var UpdateEntryCmd = &cobra.Command{
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
value = getKVMString(value)
_, err = kvm.UpdateEntry(proxyName, mapName, keyName, []byte(value))
return
},
Expand Down

0 comments on commit d23221b

Please sign in to comment.