forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.go
57 lines (48 loc) · 1.83 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package generator
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
buildapi "github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/build/api/validation"
)
func NewREST(generator *BuildGenerator) (*CloneREST, *InstantiateREST) {
return &CloneREST{generator: generator}, &InstantiateREST{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 *BuildGenerator
}
func (s *CloneREST) New() runtime.Object {
return &buildapi.BuildRequest{}
}
func (s *CloneREST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
request, ok := obj.(*buildapi.BuildRequest)
if !ok {
return nil, fmt.Errorf("not a buildRequest: %#v", obj)
}
if errs := validation.ValidateBuildRequest(request); len(errs) > 0 {
return nil, errors.NewInvalid("buildRequest", request.Name, errs)
}
return s.generator.Clone(ctx, request)
}
// InstantiateREST is a RESTStorage implementation for a BuildGenerator which supports only
// the Get operation (as the generator has no underlying storage object).
type InstantiateREST struct {
generator *BuildGenerator
}
func (s *InstantiateREST) New() runtime.Object {
return &buildapi.BuildRequest{}
}
func (s *InstantiateREST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
request, ok := obj.(*buildapi.BuildRequest)
if !ok {
return nil, fmt.Errorf("not a buildRequest: %#v", obj)
}
if errs := validation.ValidateBuildRequest(request); len(errs) > 0 {
return nil, errors.NewInvalid("buildRequest", request.Name, errs)
}
return s.generator.Instantiate(ctx, request)
}