forked from spiffe/spire
-
Notifications
You must be signed in to change notification settings - Fork 4
/
masks.go
35 lines (30 loc) · 1.18 KB
/
masks.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
package protoutil
import (
"reflect"
"strings"
"github.com/accuknox/spire/proto/spire/common"
"github.com/spiffe/spire-api-sdk/proto/spire/api/types"
"google.golang.org/protobuf/proto"
)
var (
AllTrueAgentMask = MakeAllTrueMask(&types.AgentMask{}).(*types.AgentMask)
AllTrueBundleMask = MakeAllTrueMask(&types.BundleMask{}).(*types.BundleMask)
AllTrueEntryMask = MakeAllTrueMask(&types.EntryMask{}).(*types.EntryMask)
AllTrueFederationRelationshipMask = MakeAllTrueMask(&types.FederationRelationshipMask{}).(*types.FederationRelationshipMask)
AllTrueCommonBundleMask = MakeAllTrueMask(&common.BundleMask{}).(*common.BundleMask)
AllTrueCommonAgentMask = MakeAllTrueMask(&common.AttestedNodeMask{}).(*common.AttestedNodeMask)
)
func MakeAllTrueMask(m proto.Message) proto.Message {
v := reflect.ValueOf(proto.Clone(m)).Elem()
t := v.Type()
for i := 0; i < v.NumField(); i++ {
ft := t.Field(i)
fv := v.Field(i)
// Skip the protobuf internal fields or those that aren't bool's
if strings.HasPrefix(ft.Name, "XXX_") || ft.Type.Kind() != reflect.Bool {
continue
}
fv.SetBool(true)
}
return v.Addr().Interface().(proto.Message)
}