api/volume.go
func volumeCreate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var inputVolume volume.Volume
	err = ParseInput(r, &inputVolume)
	if err != nil {
		return err
	}
	inputVolume.Plan.Opts = nil
	inputVolume.Status = ""
	canCreate := permission.Check(t, permission.PermVolumeCreate,
		permission.Context(permTypes.CtxTeam, inputVolume.TeamOwner),
		permission.Context(permTypes.CtxPool, inputVolume.Pool),
	)
	if !canCreate {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeVolume, Value: inputVolume.Name},
		Kind:       permission.PermVolumeCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermVolumeReadEvents, contextsForVolume(&inputVolume)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	_, err = volume.Load(inputVolume.Name)
	if err == nil {
		return &errors.HTTP{Code: http.StatusConflict, Message: "volume already exists"}
	}
	err = inputVolume.Create()
	if err != nil {
		return err
	}
	w.WriteHeader(http.StatusCreated)
	return nil
}
func volumeCreate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var inputVolume volume.Volume
	err = ParseInput(r, &inputVolume)
	if err != nil {
		return err
	}
	inputVolume.Plan.Opts = nil
	inputVolume.Status = ""
	canCreate := permission.Check(t, permission.PermVolumeCreate,
		permission.Context(permTypes.CtxTeam, inputVolume.TeamOwner),
		permission.Context(permTypes.CtxPool, inputVolume.Pool),
	)
	if !canCreate {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeVolume, Value: inputVolume.Name},
		Kind:       permission.PermVolumeCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermVolumeReadEvents, contextsForVolume(&inputVolume)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	_, err = volume.Load(inputVolume.Name)
	if err == nil {
		return &errors.HTTP{Code: http.StatusConflict, Message: "volume already exists"}
	}
	err = inputVolume.Create()
	if err != nil {
		return err
	}
	w.WriteHeader(http.StatusCreated)
	return nil
}
// title: volume create
// path: /volumes
// method: POST
// produce: application/json
// responses:
//   201: Volume created
//   401: Unauthorized
//   409: Volume already exists