forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
42 lines (33 loc) · 1.25 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
38
39
40
41
42
package buildclone
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"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 context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil {
return nil, err
}
if err := createValidation(obj); err != nil {
return nil, err
}
return s.generator.CloneInternal(ctx, obj.(*buildapi.BuildRequest))
}