Skip to content

Commit 21ddabc

Browse files
committed
Dedupe constants
Signed-off-by: Simo Sorce <[email protected]>
1 parent c2aed8d commit 21ddabc

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

pkg/oauthserver/api/types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const (
1414
// If present, this extra value is used as the preferred username
1515
IdentityPreferredUsernameKey = "preferred_username"
1616

17-
ImpersonateUserHeader = "Impersonate-User"
18-
ImpersonateGroupHeader = "Impersonate-Group"
1917
ImpersonateUserScopeHeader = "Impersonate-User-Scope"
2018
)
2119

pkg/oauthserver/client/impersonate.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
import (
44
"net/http"
55

6+
authenticationv1 "k8s.io/api/authentication/v1"
67
"k8s.io/apimachinery/pkg/runtime/schema"
78
"k8s.io/apimachinery/pkg/types"
89
utilnet "k8s.io/apimachinery/pkg/util/net"
@@ -27,13 +28,13 @@ func newImpersonatingRoundTripper(user user.Info, delegate http.RoundTripper) ht
2728

2829
func (rt *impersonatingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
2930
req = utilnet.CloneRequest(req)
30-
req.Header.Del(authenticationapi.ImpersonateUserHeader)
31-
req.Header.Del(authenticationapi.ImpersonateGroupHeader)
31+
req.Header.Del(authenticationv1.ImpersonateUserHeader)
32+
req.Header.Del(authenticationv1.ImpersonateGroupHeader)
3233
req.Header.Del(authenticationapi.ImpersonateUserScopeHeader)
3334

34-
req.Header.Set(authenticationapi.ImpersonateUserHeader, rt.user.GetName())
35+
req.Header.Set(authenticationv1.ImpersonateUserHeader, rt.user.GetName())
3536
for _, group := range rt.user.GetGroups() {
36-
req.Header.Add(authenticationapi.ImpersonateGroupHeader, group)
37+
req.Header.Add(authenticationv1.ImpersonateGroupHeader, group)
3738
}
3839
for _, scope := range rt.user.GetExtra()[authorizationapi.ScopesKey] {
3940
req.Header.Add(authenticationapi.ImpersonateUserScopeHeader, scope)
@@ -68,8 +69,8 @@ func NewImpersonatingRESTClient(user user.Info, client restclient.Interface) res
6869

6970
// Verb does the impersonation per request by setting the proper headers
7071
func (c impersonatingRESTClient) impersonate(req *restclient.Request) *restclient.Request {
71-
req.SetHeader(authenticationapi.ImpersonateUserHeader, c.user.GetName())
72-
req.SetHeader(authenticationapi.ImpersonateGroupHeader, c.user.GetGroups()...)
72+
req.SetHeader(authenticationv1.ImpersonateUserHeader, c.user.GetName())
73+
req.SetHeader(authenticationv1.ImpersonateGroupHeader, c.user.GetGroups()...)
7374
req.SetHeader(authenticationapi.ImpersonateUserScopeHeader, c.user.GetExtra()[authorizationapi.ScopesKey]...)
7475
return req
7576
}

test/integration/scopes_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package integration
33
import (
44
"testing"
55

6+
authenticationv1 "k8s.io/api/authentication/v1"
67
kapierrors "k8s.io/apimachinery/pkg/api/errors"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
apiserverserviceaccount "k8s.io/apiserver/pkg/authentication/serviceaccount"
@@ -105,7 +106,7 @@ func TestScopedImpersonation(t *testing.T) {
105106
}
106107

107108
err = clusterAdminBuildClient.Build().RESTClient().Get().
108-
SetHeader(authenticationapi.ImpersonateUserHeader, "harold").
109+
SetHeader(authenticationv1.ImpersonateUserHeader, "harold").
109110
SetHeader(authenticationapi.ImpersonateUserScopeHeader, "user:info").
110111
Namespace(projectName).Resource("builds").Name("name").Do().Into(&buildapi.Build{})
111112
if !kapierrors.IsForbidden(err) {
@@ -114,7 +115,7 @@ func TestScopedImpersonation(t *testing.T) {
114115

115116
user := &userapi.User{}
116117
err = userclient.NewForConfigOrDie(clusterAdminClientConfig).RESTClient().Get().
117-
SetHeader(authenticationapi.ImpersonateUserHeader, "harold").
118+
SetHeader(authenticationv1.ImpersonateUserHeader, "harold").
118119
SetHeader(authenticationapi.ImpersonateUserScopeHeader, "user:info").
119120
Resource("users").Name("~").Do().Into(user)
120121
if err != nil {

0 commit comments

Comments
 (0)