forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
patch_oauthserver.go
63 lines (52 loc) · 2.53 KB
/
patch_oauthserver.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
package openshiftkubeapiserver
import (
"net/http"
"github.com/openshift/origin/pkg/oauthserver/oauthserver"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/client-go/kubernetes"
routeclient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
)
// TODO this is taking a very large config for a small piece of it. The information must be broken up at some point so that
// we can run this in a pod. This is an indication of leaky abstraction because it spent too much time in openshift start
func NewOAuthServerConfigFromMasterConfig(genericConfig *genericapiserver.Config, oauthConfig *configapi.OAuthConfig) (*oauthserver.OAuthServerConfig, error) {
oauthServerConfig, err := oauthserver.NewOAuthServerConfig(*oauthConfig, genericConfig.LoopbackClientConfig)
if err != nil {
return nil, err
}
oauthServerConfig.GenericConfig.CorsAllowedOriginList = genericConfig.CorsAllowedOriginList
oauthServerConfig.GenericConfig.SecureServing = genericConfig.SecureServing
oauthServerConfig.GenericConfig.AuditBackend = genericConfig.AuditBackend
oauthServerConfig.GenericConfig.AuditPolicyChecker = genericConfig.AuditPolicyChecker
routeClient, err := routeclient.NewForConfig(genericConfig.LoopbackClientConfig)
if err != nil {
return nil, err
}
kubeClient, err := kubernetes.NewForConfig(genericConfig.LoopbackClientConfig)
if err != nil {
return nil, err
}
oauthServerConfig.ExtraOAuthConfig.RouteClient = routeClient
oauthServerConfig.ExtraOAuthConfig.KubeClient = kubeClient
// Build the list of valid redirect_uri prefixes for a login using the openshift-web-console client to redirect to
oauthServerConfig.ExtraOAuthConfig.AssetPublicAddresses = []string{oauthConfig.AssetPublicURL}
return oauthServerConfig, nil
}
func NewOAuthServerHandler(genericConfig *genericapiserver.Config, oauthConfig *configapi.OAuthConfig) (http.Handler, map[string]genericapiserver.PostStartHookFunc, error) {
if oauthConfig == nil {
return http.NotFoundHandler(), nil, nil
}
config, err := NewOAuthServerConfigFromMasterConfig(genericConfig, oauthConfig)
if err != nil {
return nil, nil, err
}
oauthServer, err := config.Complete().New(genericapiserver.NewEmptyDelegate())
if err != nil {
return nil, nil, err
}
return oauthServer.GenericAPIServer.PrepareRun().GenericAPIServer.Handler.FullHandlerChain,
map[string]genericapiserver.PostStartHookFunc{
"oauth.openshift.io-startoauthclientsbootstrapping": config.StartOAuthClientsBootstrapping,
},
nil
}