/
call.go
79 lines (69 loc) · 3.21 KB
/
call.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package security
import (
"fmt"
"time"
"v.io/v23/naming"
"v.io/v23/vdl"
)
// NewCall creates a Call.
func NewCall(params *CallParams) Call {
ctx := &ctxImpl{*params}
if params.Timestamp.IsZero() {
ctx.params.Timestamp = time.Now()
}
return ctx
}
// CallParams is used to create Call objects using the NewCall
// function.
type CallParams struct {
Timestamp time.Time // Time at which the authorization is to be checked.
Method string // Method being invoked.
MethodTags []*vdl.Value // Method tags, typically specified in VDL.
Suffix string // Object suffix on which the method is being invoked.
LocalPrincipal Principal // Principal at the local end of a request.
LocalBlessings Blessings // Blessings presented to the remote end.
LocalEndpoint naming.Endpoint // Endpoint of local end of communication.
RemoteBlessings Blessings // Blessings presented by the remote end.
RemoteDischarges []Discharge // Map of third-party caveat identifiers to corresponding discharges shared by the remote end.
LocalDischarges []Discharge // Map of third-party caveat identifiers to corresponding discharges shared by the local end.
RemoteEndpoint naming.Endpoint // Endpoint of the remote end of communication (as seen by the local end)
}
// Copy fills in p with a copy of the values in c.
func (p *CallParams) Copy(c Call) {
p.Timestamp = c.Timestamp()
p.Method = c.Method()
if tagslen := len(c.MethodTags()); tagslen == 0 {
p.MethodTags = nil
} else {
p.MethodTags = make([]*vdl.Value, tagslen)
for ix, tag := range c.MethodTags() {
p.MethodTags[ix] = vdl.CopyValue(tag)
}
}
p.Suffix = c.Suffix()
p.LocalPrincipal = c.LocalPrincipal()
p.LocalBlessings = c.LocalBlessings()
p.LocalEndpoint = c.LocalEndpoint()
p.RemoteBlessings = c.RemoteBlessings()
// TODO(ataly, suharshs): Is the copying of discharge maps
// really needed?
p.LocalDischarges = c.LocalDischarges().Copy()
p.RemoteDischarges = c.RemoteDischarges().Copy()
p.RemoteEndpoint = c.RemoteEndpoint()
}
type ctxImpl struct{ params CallParams }
func (c *ctxImpl) Timestamp() time.Time { return c.params.Timestamp }
func (c *ctxImpl) Method() string { return c.params.Method }
func (c *ctxImpl) MethodTags() []*vdl.Value { return c.params.MethodTags }
func (c *ctxImpl) Suffix() string { return c.params.Suffix }
func (c *ctxImpl) LocalPrincipal() Principal { return c.params.LocalPrincipal }
func (c *ctxImpl) LocalBlessings() Blessings { return c.params.LocalBlessings }
func (c *ctxImpl) RemoteBlessings() Blessings { return c.params.RemoteBlessings }
func (c *ctxImpl) LocalEndpoint() naming.Endpoint { return c.params.LocalEndpoint }
func (c *ctxImpl) RemoteEndpoint() naming.Endpoint { return c.params.RemoteEndpoint }
func (c *ctxImpl) LocalDischarges() Discharges { return c.params.LocalDischarges }
func (c *ctxImpl) RemoteDischarges() Discharges { return c.params.RemoteDischarges }
func (c *ctxImpl) String() string { return fmt.Sprintf("%+v", c.params) }