/
caveat.go
38 lines (34 loc) · 1.17 KB
/
caveat.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
// 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 access
import (
"v.io/v23/context"
"v.io/v23/security"
"v.io/v23/vdl"
)
func init() {
security.RegisterCaveatValidator(AccessTagCaveat, func(ctx *context.T, call security.Call, params []Tag) error {
wantT := TypicalTagType()
methodTags := call.MethodTags()
for _, mt := range methodTags {
if mt.Type() == wantT {
for _, ct := range params {
if mt.RawString() == vdl.ValueOf(ct).RawString() {
return nil
}
}
}
}
strs := make([]string, len(methodTags))
for i, mt := range methodTags {
strs[i] = mt.RawString()
}
return ErrorfAccessTagCaveatValidation(ctx, "access tags on method (%v) do not include any of the ones in the caveat (%v), or the method is using a different tag type", strs, params)
})
}
// NewAccessTagCaveat returns a Caveat that will validate iff the intersection
// of the tags on the method being invoked and those in 'tags' is non-empty.
func NewAccessTagCaveat(tags ...Tag) (security.Caveat, error) {
return security.NewCaveat(AccessTagCaveat, tags)
}