forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_adder.go
30 lines (25 loc) · 808 Bytes
/
group_adder.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
package group
import (
"net/http"
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
"github.com/openshift/origin/pkg/auth/authenticator"
)
// GroupAdder wraps a request authenticator, and adds the specified groups to the returned user when authentication succeeds
type GroupAdder struct {
Authenticator authenticator.Request
Groups []string
}
func (g *GroupAdder) AuthenticateRequest(req *http.Request) (user.Info, bool, error) {
u, ok, err := g.Authenticator.AuthenticateRequest(req)
if err != nil || !ok {
return nil, ok, err
}
return &user.DefaultInfo{
Name: u.GetName(),
UID: u.GetUID(),
Groups: append(u.GetGroups(), g.Groups...),
}, true, nil
}
func NewGroupAdder(auth authenticator.Request, groups []string) *GroupAdder {
return &GroupAdder{auth, groups}
}