forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.go
39 lines (31 loc) · 1.06 KB
/
lookup.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
package identitymapper
import (
kapi "k8s.io/kubernetes/pkg/api"
kuser "k8s.io/kubernetes/pkg/auth/user"
authapi "github.com/openshift/origin/pkg/auth/api"
"github.com/openshift/origin/pkg/user/registry/user"
"github.com/openshift/origin/pkg/user/registry/useridentitymapping"
)
var _ = authapi.UserIdentityMapper(&lookupIdentityMapper{})
// lookupIdentityMapper does not provision a new identity or user, it only allows identities already associated with users
type lookupIdentityMapper struct {
mappings useridentitymapping.Registry
users user.Registry
}
// UserFor returns info about the user for whom identity info has been provided
func (p *lookupIdentityMapper) UserFor(info authapi.UserIdentityInfo) (kuser.Info, error) {
ctx := kapi.NewContext()
mapping, err := p.mappings.GetUserIdentityMapping(ctx, info.GetIdentityName())
if err != nil {
return nil, err
}
u, err := p.users.GetUser(ctx, mapping.User.Name)
if err != nil {
return nil, err
}
return &kuser.DefaultInfo{
Name: u.Name,
UID: string(u.UID),
Groups: u.Groups,
}, nil
}