func platformAdd(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	name := InputValue(r, "name")
	file, _, err := r.FormFile("dockerfile_content")
	if err != nil {
		return &tErrors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	defer file.Close()
	data, err := ioutil.ReadAll(file)
	if err != nil {
		return err
	}
	if len(data) == 0 {
		return &tErrors.HTTP{Code: http.StatusBadRequest, Message: appTypes.ErrMissingFileContent.Error()}
	}
	args := make(map[string]string)
	for key, values := range r.Form {
		args[key] = values[0]
	}
	canCreatePlatform := permission.Check(t, permission.PermPlatformCreate)
	if !canCreatePlatform {
		return permission.ErrUnauthorized
	}
	w.Header().Set("Content-Type", "application/x-json-stream")
	keepAliveWriter := io.NewKeepAliveWriter(w, 30*time.Second, "")
	defer keepAliveWriter.Stop()
	writer := &io.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePlatform, Value: name},
		Kind:       permission.PermPlatformCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPlatformReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	evt.SetLogWriter(writer)
	ctx, cancel := evt.CancelableContext(context.Background())
	err = servicemanager.Platform.Create(appTypes.PlatformOptions{
		Name:   name,
		Args:   args,
		Data:   data,
		Output: evt,
		Ctx:    ctx,
	})
	cancel()
	if err != nil {
		return err
	}
	writer.Write([]byte("Platform successfully added!\n"))
	return nil
}
func platformAdd(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	name := InputValue(r, "name")
	file, _, err := r.FormFile("dockerfile_content")
	if err != nil {
		return &tErrors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	defer file.Close()
	data, err := ioutil.ReadAll(file)
	if err != nil {
		return err
	}
	if len(data) == 0 {
		return &tErrors.HTTP{Code: http.StatusBadRequest, Message: appTypes.ErrMissingFileContent.Error()}
	}
	args := make(map[string]string)
	for key, values := range r.Form {
		args[key] = values[0]
	}
	canCreatePlatform := permission.Check(t, permission.PermPlatformCreate)
	if !canCreatePlatform {
		return permission.ErrUnauthorized
	}
	w.Header().Set("Content-Type", "application/x-json-stream")
	keepAliveWriter := io.NewKeepAliveWriter(w, 30*time.Second, "")
	defer keepAliveWriter.Stop()
	writer := &io.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePlatform, Value: name},
		Kind:       permission.PermPlatformCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPlatformReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	evt.SetLogWriter(writer)
	ctx, cancel := evt.CancelableContext(context.Background())
	err = servicemanager.Platform.Create(appTypes.PlatformOptions{
		Name:   name,
		Args:   args,
		Data:   data,
		Output: evt,
		Ctx:    ctx,
	})
	cancel()
	if err != nil {
		return err
	}
	writer.Write([]byte("Platform successfully added!\n"))
	return nil
}
// title: add platform
// path: /platforms
// method: POST
// consume: multipart/form-data
// produce: application/x-json-stream
// responses:
//   200: Platform created
//   400: Invalid data
//   401: Unauthorized