forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
oauth.go
108 lines (98 loc) · 3.44 KB
/
oauth.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package legacy
import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
oauthv1 "github.com/openshift/api/oauth/v1"
"github.com/openshift/origin/pkg/oauth/apis/oauth"
oauthv1helpers "github.com/openshift/origin/pkg/oauth/apis/oauth/v1"
)
// InstallLegacyOAuth this looks like a lot of duplication, but the code in the individual versions is living and may
// change. The code here should never change and needs to allow the other code to move independently.
func InstallInternalLegacyOAuth(scheme *runtime.Scheme) {
InstallExternalLegacyOAuth(scheme)
schemeBuilder := runtime.NewSchemeBuilder(
addUngroupifiedInternalOAuthTypes,
addLegacyOAuthFieldSelectorKeyConversions,
oauthv1helpers.RegisterDefaults,
oauthv1helpers.RegisterConversions,
)
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
}
func InstallExternalLegacyOAuth(scheme *runtime.Scheme) {
schemeBuilder := runtime.NewSchemeBuilder(
addUngroupifiedOAuthTypes,
)
utilruntime.Must(schemeBuilder.AddToScheme(scheme))
}
func addUngroupifiedOAuthTypes(scheme *runtime.Scheme) error {
types := []runtime.Object{
&oauthv1.OAuthAccessToken{},
&oauthv1.OAuthAccessTokenList{},
&oauthv1.OAuthAuthorizeToken{},
&oauthv1.OAuthAuthorizeTokenList{},
&oauthv1.OAuthClient{},
&oauthv1.OAuthClientList{},
&oauthv1.OAuthClientAuthorization{},
&oauthv1.OAuthClientAuthorizationList{},
&oauthv1.OAuthRedirectReference{},
}
scheme.AddKnownTypes(GroupVersion, types...)
return nil
}
func addUngroupifiedInternalOAuthTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(InternalGroupVersion,
&oauth.OAuthAccessToken{},
&oauth.OAuthAccessTokenList{},
&oauth.OAuthAuthorizeToken{},
&oauth.OAuthAuthorizeTokenList{},
&oauth.OAuthClient{},
&oauth.OAuthClientList{},
&oauth.OAuthClientAuthorization{},
&oauth.OAuthClientAuthorizationList{},
&oauth.OAuthRedirectReference{},
)
return nil
}
func addLegacyOAuthFieldSelectorKeyConversions(scheme *runtime.Scheme) error {
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "OAuthAccessToken", legacyOAuthAccessTokenFieldSelectorKeyConversionFunc); err != nil {
return err
}
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "OAuthAuthorizeToken", legacyOAuthAuthorizeTokenFieldSelectorKeyConversionFunc); err != nil {
return err
}
if err := scheme.AddFieldLabelConversionFunc(GroupVersion.String(), "OAuthClientAuthorization", legacyOAuthClientAuthorizationFieldSelectorKeyConversionFunc); err != nil {
return err
}
return nil
}
func legacyOAuthAccessTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) {
switch label {
case "clientName",
"userName",
"userUID",
"authorizeToken":
return label, value, nil
default:
return runtime.DefaultMetaV1FieldSelectorConversion(label, value)
}
}
func legacyOAuthAuthorizeTokenFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) {
switch label {
case "clientName",
"userName",
"userUID":
return label, value, nil
default:
return runtime.DefaultMetaV1FieldSelectorConversion(label, value)
}
}
func legacyOAuthClientAuthorizationFieldSelectorKeyConversionFunc(label, value string) (internalLabel, internalValue string, err error) {
switch label {
case "clientName",
"userName",
"userUID":
return label, value, nil
default:
return runtime.DefaultMetaV1FieldSelectorConversion(label, value)
}
}