update vendor to use csi-lib-utils v0.3.0
This commit is contained in:
55
vendor/github.com/kubernetes-csi/csi-lib-utils/protosanitizer/protosanitizer.go
generated
vendored
55
vendor/github.com/kubernetes-csi/csi-lib-utils/protosanitizer/protosanitizer.go
generated
vendored
@@ -24,10 +24,10 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"github.com/golang/protobuf/descriptor"
|
||||
"github.com/golang/protobuf/proto"
|
||||
protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
||||
protobufdescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
||||
)
|
||||
|
||||
// StripSecrets returns a wrapper around the original CSI gRPC message
|
||||
@@ -36,15 +36,27 @@ import (
|
||||
// Instead of the secret value(s), the string "***stripped***" is
|
||||
// included in the result.
|
||||
//
|
||||
// StripSecrets relies on an extension in CSI 1.0 and thus can only
|
||||
// be used for messages based on that or a more recent spec!
|
||||
//
|
||||
// StripSecrets itself is fast and therefore it is cheap to pass the
|
||||
// result to logging functions which may or may not end up serializing
|
||||
// the parameter depending on the current log level.
|
||||
func StripSecrets(msg interface{}) fmt.Stringer {
|
||||
return &stripSecrets{msg}
|
||||
return &stripSecrets{msg, isCSI1Secret}
|
||||
}
|
||||
|
||||
// StripSecretsCSI03 is like StripSecrets, except that it works
|
||||
// for messages based on CSI 0.3 and older. It does not work
|
||||
// for CSI 1.0, use StripSecrets for that.
|
||||
func StripSecretsCSI03(msg interface{}) fmt.Stringer {
|
||||
return &stripSecrets{msg, isCSI03Secret}
|
||||
}
|
||||
|
||||
type stripSecrets struct {
|
||||
msg interface{}
|
||||
|
||||
isSecretField func(field *protobuf.FieldDescriptorProto) bool
|
||||
}
|
||||
|
||||
func (s *stripSecrets) String() string {
|
||||
@@ -60,7 +72,7 @@ func (s *stripSecrets) String() string {
|
||||
}
|
||||
|
||||
// Now remove secrets from the generic representation of the message.
|
||||
strip(parsed, s.msg)
|
||||
s.strip(parsed, s.msg)
|
||||
|
||||
// Re-encoded the stripped representation and return that.
|
||||
b, err = json.Marshal(parsed)
|
||||
@@ -70,7 +82,7 @@ func (s *stripSecrets) String() string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func strip(parsed interface{}, msg interface{}) {
|
||||
func (s *stripSecrets) strip(parsed interface{}, msg interface{}) {
|
||||
protobufMsg, ok := msg.(descriptor.Message)
|
||||
if !ok {
|
||||
// Not a protobuf message, so we are done.
|
||||
@@ -93,8 +105,7 @@ func strip(parsed interface{}, msg interface{}) {
|
||||
fields := md.GetField()
|
||||
if fields != nil {
|
||||
for _, field := range fields {
|
||||
ex, err := proto.GetExtension(field.Options, csi.E_CsiSecret)
|
||||
if err == nil && ex != nil && *ex.(*bool) {
|
||||
if s.isSecretField(field) {
|
||||
// Overwrite only if already set.
|
||||
if _, ok := parsedFields[field.GetName()]; ok {
|
||||
parsedFields[field.GetName()] = "***stripped***"
|
||||
@@ -126,13 +137,41 @@ func strip(parsed interface{}, msg interface{}) {
|
||||
if slice, ok := entry.([]interface{}); ok {
|
||||
// Array of values, like VolumeCapabilities in CreateVolumeRequest.
|
||||
for _, entry := range slice {
|
||||
strip(entry, i)
|
||||
s.strip(entry, i)
|
||||
}
|
||||
} else {
|
||||
// Single value.
|
||||
strip(entry, i)
|
||||
s.strip(entry, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// isCSI1Secret uses the csi.E_CsiSecret extension from CSI 1.0 to
|
||||
// determine whether a field contains secrets.
|
||||
func isCSI1Secret(field *protobuf.FieldDescriptorProto) bool {
|
||||
ex, err := proto.GetExtension(field.Options, e_CsiSecret)
|
||||
return err == nil && ex != nil && *ex.(*bool)
|
||||
}
|
||||
|
||||
// Copied from the CSI 1.0 spec (https://github.com/container-storage-interface/spec/blob/37e74064635d27c8e33537c863b37ccb1182d4f8/lib/go/csi/csi.pb.go#L4520-L4527)
|
||||
// to avoid a package dependency that would prevent usage of this package
|
||||
// in repos using an older version of the spec.
|
||||
//
|
||||
// Future revision of the CSI spec must not change this extensions, otherwise
|
||||
// they will break filtering in binaries based on the 1.0 version of the spec.
|
||||
var e_CsiSecret = &proto.ExtensionDesc{
|
||||
ExtendedType: (*protobufdescriptor.FieldOptions)(nil),
|
||||
ExtensionType: (*bool)(nil),
|
||||
Field: 1059,
|
||||
Name: "csi.v1.csi_secret",
|
||||
Tag: "varint,1059,opt,name=csi_secret,json=csiSecret",
|
||||
Filename: "github.com/container-storage-interface/spec/csi.proto",
|
||||
}
|
||||
|
||||
// isCSI03Secret relies on the naming convention in CSI <= 0.3
|
||||
// to determine whether a field contains secrets.
|
||||
func isCSI03Secret(field *protobuf.FieldDescriptorProto) bool {
|
||||
return strings.HasSuffix(field.GetName(), "_secrets")
|
||||
}
|
||||
|
Reference in New Issue
Block a user