func nodeContainerCreate(w http.ResponseWriter, r *http.Request, t auth.Token) error { err := r.ParseForm() if err != nil { return err } poolName := r.FormValue("pool") if poolName == "" { if !permission.Check(t, permission.PermNodecontainerCreate) { return permission.ErrUnauthorized } } else { if !permission.Check(t, permission.PermNodecontainerCreate, permission.Context(permission.CtxPool, poolName)) { return permission.ErrUnauthorized } } dec := form.NewDecoder(nil) dec.IgnoreUnknownKeys(true) dec.IgnoreCase(true) var config nodecontainer.NodeContainerConfig err = dec.DecodeValues(&config, r.Form) if err != nil { return err } err = nodecontainer.AddNewContainer(poolName, &config) if err != nil { if _, ok := err.(nodecontainer.ValidationErr); ok { return &errors.HTTP{ Code: http.StatusBadRequest, Message: err.Error(), } } return err } return nil }
func migrateBSEnvs() error { scheme, err := config.GetString("auth:scheme") if err != nil { scheme = "native" } app.AuthScheme, err = auth.GetScheme(scheme) if err != nil { return err } _, err = nodecontainer.InitializeBS() if err != nil { return err } conn, err := db.Conn() if err != nil { return err } defer conn.Close() var entry map[string]interface{} err = conn.Collection("bsconfig").FindId("bs").One(&entry) if err != nil { return err } image, _ := entry["image"].(string) envs, _ := entry["envs"].([]interface{}) var baseEnvs []string for _, envEntry := range envs { mapEntry, _ := envEntry.(map[string]interface{}) if mapEntry == nil { continue } name, _ := mapEntry["name"].(string) value, _ := mapEntry["value"].(string) baseEnvs = append(baseEnvs, fmt.Sprintf("%s=%s", name, value)) } bsNodeContainer, err := nodecontainer.LoadNodeContainer("", nodecontainer.BsDefaultName) if err != nil { return err } if len(baseEnvs) > 0 { bsNodeContainer.Config.Env = append(bsNodeContainer.Config.Env, baseEnvs...) } bsNodeContainer.PinnedImage = image err = nodecontainer.AddNewContainer("", bsNodeContainer) if err != nil { return err } pools, _ := entry["pools"].([]interface{}) for _, poolData := range pools { poolMap, _ := poolData.(map[string]interface{}) if poolMap == nil { continue } poolName, _ := poolMap["name"].(string) if poolName == "" { continue } envs, _ := poolMap["envs"].([]interface{}) var toAdd []string for _, envEntry := range envs { mapEntry, _ := envEntry.(map[string]interface{}) if mapEntry == nil { continue } name, _ := mapEntry["name"].(string) value, _ := mapEntry["value"].(string) toAdd = append(toAdd, fmt.Sprintf("%s=%s", name, value)) } if len(toAdd) > 0 { bsCont := nodecontainer.NodeContainerConfig{Name: nodecontainer.BsDefaultName} bsCont.Config.Env = append(bsCont.Config.Env, toAdd...) err = nodecontainer.AddNewContainer(poolName, &bsCont) if err != nil { return err } } } return nil }