Skip to content

Commit

Permalink
protosanitizer: remove dependency on csi package
Browse files Browse the repository at this point in the history
The only thing that is needed from the spec is the extension field
definition. It's easier to understand why the code is generic and
going to support future revisions of the spec when using a copy of
that field definition instead of the entire spec package.

Another positive effect is that only a single file needs to be
vendored and compiled by users of the code and not also the more
complex spec.
  • Loading branch information
pohly committed Dec 6, 2018
1 parent 4b14959 commit 1e77671
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions protosanitizer/protosanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/golang/protobuf/descriptor"
"github.com/golang/protobuf/proto"
protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer/csi10"
protobufdescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
)

// StripSecrets returns a wrapper around the original CSI gRPC message
Expand Down Expand Up @@ -151,10 +151,25 @@ func (s *stripSecrets) strip(parsed interface{}, msg interface{}) {
// 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, csi.E_CsiSecret)
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 {
Expand Down
2 changes: 1 addition & 1 deletion protosanitizer/protosanitizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"testing"

"github.com/golang/protobuf/proto"
csi "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/csi10"
csi03 "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi03"
csi "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi10"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csitest"
"github.com/stretchr/testify/assert"
)
Expand Down
File renamed without changes.

0 comments on commit 1e77671

Please sign in to comment.