/
identitymapper.go
31 lines (24 loc) · 956 Bytes
/
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
package identitymapper
import (
"fmt"
"k8s.io/klog"
"k8s.io/apiserver/pkg/authentication/authenticator"
"github.com/openshift/origin/pkg/oauthserver/api"
)
// ResponseFor bridges the UserIdentityMapper interface with the authenticator.{Password|Request} interfaces
func ResponseFor(mapper api.UserIdentityMapper, identity api.UserIdentityInfo) (*authenticator.Response, bool, error) {
user, err := mapper.UserFor(identity)
if err != nil {
logf("error creating or updating mapping for: %#v due to %v", identity, err)
return nil, false, err
}
logf("got userIdentityMapping: %#v", user)
// only set User field as IDPs have no concept of Audiences
return &authenticator.Response{User: user}, true, nil
}
// logf(...) is the same as klog.V(4).Infof(...) except it reports the caller as the line number
func logf(format string, args ...interface{}) {
if klog.V(4) {
klog.InfoDepth(2, fmt.Sprintf("identitymapper: "+format, args...))
}
}