forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
64 lines (56 loc) · 1.73 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
58
59
60
61
62
63
64
package imagesecret
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
kapi "k8s.io/kubernetes/pkg/api"
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
"github.com/openshift/origin/pkg/image/api"
)
// REST implements the RESTStorage interface for ImageStreamImport
type REST struct {
secrets kcoreclient.SecretsGetter
}
// NewREST returns a new REST.
func NewREST(secrets kcoreclient.SecretsGetter) *REST {
return &REST{secrets: secrets}
}
func (r *REST) New() runtime.Object {
return &kapi.SecretList{}
}
func (r *REST) NewGetOptions() (runtime.Object, bool, string) {
return &metav1.ListOptions{}, false, ""
}
// Get retrieves all pull type secrets in the current namespace. Name is currently ignored and
// reserved for future use.
func (r *REST) Get(ctx apirequest.Context, _ string, options runtime.Object) (runtime.Object, error) {
listOptions, ok := options.(*metav1.ListOptions)
if !ok {
return nil, fmt.Errorf("unexpected options: %T", options)
}
var opts metav1.ListOptions
if listOptions != nil {
opts = *listOptions
}
ns, ok := apirequest.NamespaceFrom(ctx)
if !ok {
ns = metav1.NamespaceAll
}
secrets, err := r.secrets.Secrets(ns).List(opts)
if err != nil {
return nil, err
}
filtered := make([]kapi.Secret, 0, len(secrets.Items))
for i := range secrets.Items {
if secrets.Items[i].Annotations[api.ExcludeImageSecretAnnotation] == "true" {
continue
}
switch secrets.Items[i].Type {
case kapi.SecretTypeDockercfg, kapi.SecretTypeDockerConfigJson:
filtered = append(filtered, secrets.Items[i])
}
}
secrets.Items = filtered
return secrets, nil
}