func addRoleVars(res http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) role, err := ri.Get(vars["role"]) if err != nil { helpers.Respond(res, req, http.StatusNotFound, err.Error()) return } var roleVars map[string]interface{} err = helpers.ParseBodyAsMap(req, &roleVars) if err != nil { helpers.Respond(res, req, http.StatusBadRequest, err.Error()) return } v := entities.VarBucket{ Prio: 0, Vars: roleVars, Name: "native", } role.Vars.AddOrReplaceBucket(v) err = ri.Save(role) if err != nil { helpers.Respond(res, req, http.StatusInternalServerError, err.Error()) return } helpers.Respond(res, req, http.StatusCreated, role) }
func replaceNodeVars(res http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) node, err := ni.Get(vars["node"]) if err != nil { helpers.Respond(res, req, http.StatusNotFound, err.Error()) return } var nodeVars map[string]interface{} err = helpers.ParseBodyAsMap(req, &nodeVars) if err != nil { helpers.Respond(res, req, http.StatusBadRequest, err.Error()) return } vb := entities.VarBucket{ Prio: 0, Name: "native", } for _, b := range node.Vars { if b.Name == "native" { vb = b } } for key, val := range nodeVars { vb.Vars[key] = val } node.Vars.AddOrReplaceBucket(vb) err = ni.Save(node) if err != nil { helpers.Respond(res, req, http.StatusInternalServerError, err.Error()) return } helpers.Respond(res, req, http.StatusOK, node) }