forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.go
41 lines (33 loc) · 1.18 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
40
41
package identitymapper
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kuser "github.com/GoogleCloudPlatform/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"
)
type lookupIdentityMapper struct {
mappings useridentitymapping.Registry
users user.Registry
}
// NewLookupIdentityMapper returns a mapper that will look up existing mappings for identities
func NewLookupIdentityMapper(mappings useridentitymapping.Registry, users user.Registry) authapi.UserIdentityMapper {
return &lookupIdentityMapper{mappings, users}
}
// 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
}