mirror of
https://github.com/rancher/steve.git
synced 2025-04-27 02:51:10 +00:00
34 lines
800 B
Go
34 lines
800 B
Go
package handlers
|
|
|
|
import (
|
|
"github.com/rancher/steve/pkg/schemaserver/httperror"
|
|
"github.com/rancher/steve/pkg/schemaserver/parse"
|
|
"github.com/rancher/steve/pkg/schemaserver/types"
|
|
"github.com/rancher/wrangler/pkg/schemas/validation"
|
|
)
|
|
|
|
func CreateHandler(apiOp *types.APIRequest) (types.APIObject, error) {
|
|
var err error
|
|
|
|
if err := apiOp.AccessControl.CanCreate(apiOp, apiOp.Schema); err != nil {
|
|
return types.APIObject{}, err
|
|
}
|
|
|
|
data, err := parse.Body(apiOp.Request)
|
|
if err != nil {
|
|
return types.APIObject{}, err
|
|
}
|
|
|
|
store := apiOp.Schema.Store
|
|
if store == nil {
|
|
return types.APIObject{}, httperror.NewAPIError(validation.NotFound, "no store found")
|
|
}
|
|
|
|
data, err = store.Create(apiOp, apiOp.Schema, data)
|
|
if err != nil {
|
|
return types.APIObject{}, err
|
|
}
|
|
|
|
return data, nil
|
|
}
|