Skip to content

Commit 1e77671

Browse files
committed
protosanitizer: remove dependency on csi package
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.
1 parent 4b14959 commit 1e77671

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

protosanitizer/protosanitizer.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/golang/protobuf/descriptor"
2828
"github.com/golang/protobuf/proto"
2929
protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
30-
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer/csi10"
30+
protobufdescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
3131
)
3232

3333
// StripSecrets returns a wrapper around the original CSI gRPC message
@@ -151,10 +151,25 @@ func (s *stripSecrets) strip(parsed interface{}, msg interface{}) {
151151
// isCSI1Secret uses the csi.E_CsiSecret extension from CSI 1.0 to
152152
// determine whether a field contains secrets.
153153
func isCSI1Secret(field *protobuf.FieldDescriptorProto) bool {
154-
ex, err := proto.GetExtension(field.Options, csi.E_CsiSecret)
154+
ex, err := proto.GetExtension(field.Options, e_CsiSecret)
155155
return err == nil && ex != nil && *ex.(*bool)
156156
}
157157

158+
// Copied from the CSI 1.0 spec (https://github.com/container-storage-interface/spec/blob/37e74064635d27c8e33537c863b37ccb1182d4f8/lib/go/csi/csi.pb.go#L4520-L4527)
159+
// to avoid a package dependency that would prevent usage of this package
160+
// in repos using an older version of the spec.
161+
//
162+
// Future revision of the CSI spec must not change this extensions, otherwise
163+
// they will break filtering in binaries based on the 1.0 version of the spec.
164+
var e_CsiSecret = &proto.ExtensionDesc{
165+
ExtendedType: (*protobufdescriptor.FieldOptions)(nil),
166+
ExtensionType: (*bool)(nil),
167+
Field: 1059,
168+
Name: "csi.v1.csi_secret",
169+
Tag: "varint,1059,opt,name=csi_secret,json=csiSecret",
170+
Filename: "github.com/container-storage-interface/spec/csi.proto",
171+
}
172+
158173
// isCSI03Secret relies on the naming convention in CSI <= 0.3
159174
// to determine whether a field contains secrets.
160175
func isCSI03Secret(field *protobuf.FieldDescriptorProto) bool {

protosanitizer/protosanitizer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"testing"
2222

2323
"github.com/golang/protobuf/proto"
24-
csi "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/csi10"
2524
csi03 "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi03"
25+
csi "github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csi10"
2626
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer/test/csitest"
2727
"github.com/stretchr/testify/assert"
2828
)

0 commit comments

Comments
 (0)