forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
35 lines (28 loc) · 1.03 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
package buildclone
import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/runtime"
buildapi "github.com/openshift/origin/pkg/build/api"
"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
}
// 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 kapi.Context, obj runtime.Object) (runtime.Object, error) {
if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil {
return nil, err
}
return s.generator.Clone(ctx, obj.(*buildapi.BuildRequest))
}