func handleUpdate(r *ranch.Ranch) http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		logrus.WithField("handler", "handleUpdate").Infof("From %v", req.RemoteAddr)

		if req.Method != http.MethodPost {
			msg := fmt.Sprintf("Method %v, /update only accepts POST.", req.Method)
			logrus.Warning(msg)
			http.Error(res, msg, http.StatusMethodNotAllowed)
			return
		}

		name := req.URL.Query().Get("name")
		owner := req.URL.Query().Get("owner")
		state := req.URL.Query().Get("state")

		if name == "" || owner == "" || state == "" {
			msg := fmt.Sprintf("Name: %v, owner: %v, state : %v, all of them must be set in the request.", name, owner, state)
			logrus.Warning(msg)
			http.Error(res, msg, http.StatusBadRequest)
			return
		}

		var userData common.UserData

		if req.Body != nil {
			err := json.NewDecoder(req.Body).Decode(&userData)
			switch {
			case err == io.EOF:
				// empty body
			case err != nil:
				logrus.WithError(err).Warning("Unable to read from response body")
				http.Error(res, err.Error(), http.StatusBadRequest)
				return
			}
		}

		if err := r.Update(name, owner, state, &userData); err != nil {
			logrus.WithError(err).Errorf("Update failed: %v - %v (%v)", name, state, owner)
			http.Error(res, err.Error(), ErrorToStatus(err))
			return
		}

		logrus.Infof("Updated resource %v", name)
	}
}
func handleUpdate(r *ranch.Ranch) http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		logrus.WithField("handler", "handleUpdate").Infof("From %v", req.RemoteAddr)

		if req.Method != http.MethodPost {
			msg := fmt.Sprintf("Method %v, /update only accepts POST.", req.Method)
			logrus.Warning(msg)
			http.Error(res, msg, http.StatusMethodNotAllowed)
			return
		}

		name := req.URL.Query().Get("name")
		owner := req.URL.Query().Get("owner")
		state := req.URL.Query().Get("state")

		if name == "" || owner == "" || state == "" {
			msg := fmt.Sprintf("Name: %v, owner: %v, state : %v, all of them must be set in the request.", name, owner, state)
			logrus.Warning(msg)
			http.Error(res, msg, http.StatusBadRequest)
			return
		}

		var userData common.UserData

		if req.Body != nil {
			err := json.NewDecoder(req.Body).Decode(&userData)
			switch {
			case err == io.EOF:
				// empty body
			case err != nil:
				logrus.WithError(err).Warning("Unable to read from response body")
				http.Error(res, err.Error(), http.StatusBadRequest)
				return
			}
		}

		if err := r.Update(name, owner, state, &userData); err != nil {
			logrus.WithError(err).Errorf("Update failed: %v - %v (%v)", name, state, owner)
			http.Error(res, err.Error(), ErrorToStatus(err))
			return
		}

		logrus.Infof("Updated resource %v", name)
	}
}
//  handleUpdate: Handler for /update
//  Method: POST
//  URLParams
//		Required: name=[string]              : name of target resource
//		Required: owner=[string]             : owner of the resource
//		Required: state=[string]             : current state of the resource
//		Optional: userData=[common.UserData] : user data id to update