forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
37 lines (29 loc) · 1.11 KB
/
rest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package buildclone
import (
"k8s.io/apimachinery/pkg/runtime"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
"github.com/openshift/origin/pkg/build/generator"
)
// NewStorage creates a new storage object for build generation
func NewStorage(generator *generator.BuildGenerator) *CloneREST {
return &CloneREST{generator: generator}
}
// CloneREST is a RESTStorage implementation for a BuildGenerator which supports only
// the Get operation (as the generator has no underlying storage object).
type CloneREST struct {
generator *generator.BuildGenerator
}
var _ rest.Creater = &CloneREST{}
// New creates a new build clone request
func (s *CloneREST) New() runtime.Object {
return &buildapi.BuildRequest{}
}
// Create instantiates a new build from an existing build
func (s *CloneREST) Create(ctx apirequest.Context, obj runtime.Object, _ bool) (runtime.Object, error) {
if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil {
return nil, err
}
return s.generator.Clone(ctx, obj.(*buildapi.BuildRequest))
}