mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-11-03 09:37:34 +00:00
pkg/api: do not register decoder in endpoint handler
Since the decoder is shared registering the decoder inside a single endpoint will also register it for all others. Also the problem with that is the it will register it everytime this endpoint is called which is wrong. Instead we should register it once like the other custom decoder functions. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
c441a1756b
commit
bbb10bb52d
2 changed files with 10 additions and 8 deletions
|
|
@ -21,6 +21,7 @@ func NewAPIDecoder() *schema.Decoder {
|
|||
d.RegisterConverter(map[string][]string{}, convertURLValuesString)
|
||||
d.RegisterConverter(time.Time{}, convertTimeString)
|
||||
d.RegisterConverter(define.ContainerStatus(0), convertContainerStatusString)
|
||||
d.RegisterConverter(map[string]string{}, convertStringMap)
|
||||
|
||||
var Signal syscall.Signal
|
||||
d.RegisterConverter(Signal, convertSignal)
|
||||
|
|
@ -48,6 +49,15 @@ func convertURLValuesString(query string) reflect.Value {
|
|||
return reflect.ValueOf(f)
|
||||
}
|
||||
|
||||
func convertStringMap(query string) reflect.Value {
|
||||
res := make(map[string]string)
|
||||
err := json.Unmarshal([]byte(query), &res)
|
||||
if err != nil {
|
||||
logrus.Infof("convertStringMap: Failed to Unmarshal %s: %s", query, err.Error())
|
||||
}
|
||||
return reflect.ValueOf(res)
|
||||
}
|
||||
|
||||
func convertContainerStatusString(query string) reflect.Value {
|
||||
result, err := define.StringToContainerStatus(query)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package libpod
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"github.com/containers/podman/v4/libpod"
|
||||
"github.com/containers/podman/v4/pkg/api/handlers/utils"
|
||||
|
|
@ -20,12 +18,6 @@ func CreateSecret(w http.ResponseWriter, r *http.Request) {
|
|||
decoder = r.Context().Value(api.DecoderKey).(*schema.Decoder)
|
||||
)
|
||||
|
||||
decoder.RegisterConverter(map[string]string{}, func(str string) reflect.Value {
|
||||
res := make(map[string]string)
|
||||
json.Unmarshal([]byte(str), &res)
|
||||
return reflect.ValueOf(res)
|
||||
})
|
||||
|
||||
query := struct {
|
||||
Name string `schema:"name"`
|
||||
Driver string `schema:"driver"`
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue