...
1
16
17 package authentication
18
19 import (
20 authenticationv1 "k8s.io/api/authentication/v1"
21 )
22
23
24
25 func Authenticated(reason string, user authenticationv1.UserInfo) Response {
26 return ReviewResponse(true, user, reason)
27 }
28
29
30
31 func Unauthenticated(reason string, user authenticationv1.UserInfo) Response {
32 return ReviewResponse(false, authenticationv1.UserInfo{}, reason)
33 }
34
35
36 func Errored(err error) Response {
37 return Response{
38 TokenReview: authenticationv1.TokenReview{
39 Spec: authenticationv1.TokenReviewSpec{},
40 Status: authenticationv1.TokenReviewStatus{
41 Authenticated: false,
42 Error: err.Error(),
43 },
44 },
45 }
46 }
47
48
49 func ReviewResponse(authenticated bool, user authenticationv1.UserInfo, err string, audiences ...string) Response {
50 resp := Response{
51 TokenReview: authenticationv1.TokenReview{
52 Status: authenticationv1.TokenReviewStatus{
53 Authenticated: authenticated,
54 User: user,
55 Audiences: audiences,
56 },
57 },
58 }
59 if len(err) > 0 {
60 resp.TokenReview.Status.Error = err
61 }
62 return resp
63 }
64
View as plain text