diff --git a/cmd/manager/deployments.go b/cmd/manager/deployments.go index a1de5e80a..c64f99439 100644 --- a/cmd/manager/deployments.go +++ b/cmd/manager/deployments.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "encoding/json" "errors" "fmt" "io" @@ -298,19 +297,11 @@ func getPathVariable(w http.ResponseWriter, r *http.Request, variable, handler s func getTemplate(w http.ResponseWriter, r *http.Request, handler string) *common.Template { util.LogHandlerEntry(handler, r) - j, err := getJSONFromRequest(w, r, handler) - - if err != nil { - return nil - } - t := &common.Template{} - if err := json.Unmarshal(j, t); err != nil { - e := fmt.Errorf("%v\n%v", err, string(j)) - util.LogAndReturnError(handler, http.StatusBadRequest, e, w) + if err := httputil.Decode(w, r, t); err != nil { + httputil.BadRequest(w, r, err) return nil } - return t } @@ -479,18 +470,12 @@ func getRegistryHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Co func getRegistry(w http.ResponseWriter, r *http.Request, handler string) *common.Registry { util.LogHandlerEntry(handler, r) - j, err := getJSONFromRequest(w, r, handler) - if err != nil { - return nil - } t := &common.Registry{} - if err := json.Unmarshal(j, t); err != nil { - e := fmt.Errorf("%v\n%v", err, string(j)) - util.LogAndReturnError(handler, http.StatusBadRequest, e, w) + if err := httputil.Decode(w, r, t); err != nil { + httputil.BadRequest(w, r, err) return nil } - return t } @@ -611,18 +596,11 @@ func getFileHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Contex func getCredential(w http.ResponseWriter, r *http.Request, handler string) *common.RegistryCredential { util.LogHandlerEntry(handler, r) - j, err := getJSONFromRequest(w, r, handler) - if err != nil { - return nil - } - t := &common.RegistryCredential{} - if err := json.Unmarshal(j, t); err != nil { - e := fmt.Errorf("%v\n%v", err, string(j)) - util.LogAndReturnError(handler, http.StatusBadRequest, e, w) + if err := httputil.Decode(w, r, t); err != nil { + httputil.BadRequest(w, r, err) return nil } - return t } diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 126e9ed77..7005b888c 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -17,14 +17,15 @@ limitations under the License. package main import ( - "github.com/kubernetes/helm/cmd/manager/router" - "github.com/kubernetes/helm/pkg/version" - "flag" "fmt" "log" "net/http" "os" + + "github.com/kubernetes/helm/cmd/manager/router" + "github.com/kubernetes/helm/pkg/httputil" + "github.com/kubernetes/helm/pkg/version" ) var ( @@ -52,6 +53,8 @@ func main() { os.Exit(1) } + httputil.DefaultEncoder.MaxReadLen = c.Config.MaxTemplateLength + // Set up routes handler := router.NewHandler(c) registerDeploymentRoutes(c, handler)