-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
50 lines (37 loc) · 984 Bytes
/
context.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
42
43
44
45
46
47
48
49
50
package auth
// ReqContext is a context associated with a request.
import (
"context"
"net"
"time"
)
type ReqContext struct {
// Auth role - set if a authorized_keys or other authz is configured
Role string
// SAN list from the certificate, or equivalent auth method.
SAN []string
// Request start time
T0 time.Time
// Public key of the first cert in the chain (similar with SSH)
Pub []byte
// VIP associated with the public key.
VIP net.IP
VAPID *JWT
}
// ID of the caller, validated based on certs.
// Currently based on VIP6 for mesh nods.
func (rc *ReqContext) ID() string {
if rc.VIP == nil {
return ""
}
return rc.VIP.String()
}
type h2Key int
var h2Info = h2Key(1)
// h2ctx := r.Context().Value(mesh.H2Info).(*mesh.ReqContext)
func AuthContext(ctx context.Context) *ReqContext {
return ctx.Value(h2Info).(*ReqContext)
}
func ContextWithAuth(ctx context.Context, h2c *ReqContext) context.Context {
return context.WithValue(ctx, h2Info, h2c)
}