forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
servicebroker.go
57 lines (48 loc) · 2.14 KB
/
servicebroker.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 servicebroker
import (
"k8s.io/kubernetes/pkg/auth/user"
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
"k8s.io/kubernetes/pkg/client/restclient"
authclient "github.com/openshift/origin/pkg/auth/client"
"github.com/openshift/origin/pkg/client"
"github.com/openshift/origin/pkg/client/cache"
"github.com/openshift/origin/pkg/controller/shared"
templateclientset "github.com/openshift/origin/pkg/template/clientset/internalclientset"
internalversiontemplate "github.com/openshift/origin/pkg/template/clientset/internalclientset/typed/template/internalversion"
)
type Broker struct {
secretsGetter internalversion.SecretsGetter
localSAR client.LocalSubjectAccessReviewsNamespacer
templateclient internalversiontemplate.TemplateInterface
restconfig restclient.Config
lister cache.StoreToTemplateLister
templateNamespace string
}
func NewBroker(restconfig restclient.Config, localSAR client.LocalSubjectAccessReviewsNamespacer, secretsGetter internalversion.SecretsGetter, informers shared.InformerFactory, templateNamespace string) *Broker {
return &Broker{
secretsGetter: secretsGetter,
localSAR: localSAR,
templateclient: templateclientset.NewForConfigOrDie(&restconfig).Template(),
restconfig: restconfig,
lister: informers.Templates().Lister(),
templateNamespace: templateNamespace,
}
}
func (b *Broker) getClientsForUsername(username string) (kclientset.Interface, client.Interface, templateclientset.Interface, error) {
u := &user.DefaultInfo{Name: username}
oc, err := authclient.NewImpersonatingOpenShiftClient(u, b.restconfig)
if err != nil {
return nil, nil, nil, err
}
kc, err := authclient.NewImpersonatingKubernetesClientset(u, b.restconfig)
if err != nil {
return nil, nil, nil, err
}
impersonatingConfig := authclient.NewImpersonatingConfig(u, b.restconfig)
templateclient, err := templateclientset.NewForConfig(&impersonatingConfig)
if err != nil {
return nil, nil, nil, err
}
return kc, oc, templateclient, nil
}