forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identitymapper.go
38 lines (33 loc) · 1.38 KB
/
identitymapper.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
package identitymapper
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
authapi "github.com/openshift/origin/pkg/auth/api"
userapi "github.com/openshift/origin/pkg/user/api"
uimap "github.com/openshift/origin/pkg/user/registry/useridentitymapping"
)
type alwaysCreateUserIdentityToUserMapper struct {
providerID string
userIdentityRegistry uimap.Registry
}
// NewAlwaysCreateUserIdentityToUserMapper always does a createOrUpdate for the passed identity
func NewAlwaysCreateUserIdentityToUserMapper(providerID string, userIdentityRegistry uimap.Registry) authapi.UserIdentityMapper {
return &alwaysCreateUserIdentityToUserMapper{providerID, userIdentityRegistry}
}
// UserFor returns info about the user for whom identity info have been provided
func (p *alwaysCreateUserIdentityToUserMapper) UserFor(identityInfo authapi.UserIdentityInfo) (user.Info, error) {
userIdentityMapping := &userapi.UserIdentityMapping{
Identity: userapi.Identity{
Provider: p.providerID, // Provider id is imposed
UserName: identityInfo.GetUserName(),
Extra: identityInfo.GetExtra(),
},
}
authoritativeMapping, _ /*created*/, err := p.userIdentityRegistry.CreateOrUpdateUserIdentityMapping(userIdentityMapping)
if err != nil {
return nil, err
}
return &user.DefaultInfo{
Name: authoritativeMapping.User.Name,
UID: string(authoritativeMapping.User.UID),
}, nil
}