From 3d7ee88c39ed6cc460eb904dcd8978c44b369f12 Mon Sep 17 00:00:00 2001 From: bufdev Date: Fri, 20 Sep 2024 14:41:31 -0400 Subject: [PATCH 1/4] commit --- go.mod | 4 +- go.sum | 4 ++ private/bufpkg/bufcheck/annotation.go | 14 +++--- .../bufcheckserverutil/bufcheckserverutil.go | 13 ++--- .../internal/bufcheckserverutil/input_file.go | 10 ++-- private/bufpkg/bufcheck/check_client_spec.go | 5 +- private/bufpkg/bufcheck/client.go | 48 +++++++++--------- .../internal/bufcheckopt/bufcheckopt.go | 36 ++++++------- .../internal/cmd/buf-plugin-panic/main.go | 3 +- .../buf-plugin-protovalidate-ext/handlers.go | 3 +- .../cmd/buf-plugin-protovalidate-ext/util.go | 15 +++--- .../internal/cmd/buf-plugin-rpc-ext/main.go | 9 ++-- .../cmd/buf-plugin-suffix/handlers.go | 50 ++++++++++--------- private/bufpkg/bufcheck/multi_client.go | 4 +- private/bufpkg/bufcheck/options_config.go | 3 +- private/bufpkg/bufcheck/util.go | 10 ++-- 16 files changed, 121 insertions(+), 110 deletions(-) diff --git a/go.mod b/go.mod index cb79a78be8..542c0fad8d 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,11 @@ go 1.22.0 toolchain go1.23.1 require ( - buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240904181154-a0be11449112.2 + buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2 buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2 buf.build/gen/go/bufbuild/registry/connectrpc/go v1.16.2-20240821192916-45ba72cdd479.1 buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240821192916-45ba72cdd479.2 - buf.build/go/bufplugin v0.2.0 + buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9 buf.build/go/protoyaml v0.2.0 connectrpc.com/connect v1.16.2 connectrpc.com/otelconnect v0.7.1 diff --git a/go.sum b/go.sum index b97f5d2e2f..83ab33f344 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2 h1:saqQcA0XF8LL9vE7OvN1CDPQYy4M8oWU+0C1O8eh/cU= +buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2/go.mod h1:B+9TKHRYqoAUW57pLjhkLOnBCu0DQYMV+f7imQ9nXwI= buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240904181154-a0be11449112.2 h1:X9qBPcvWGOJs/CeRVLoxxLJwC/eKyWDS/G4nj+3KGMY= buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240904181154-a0be11449112.2/go.mod h1:B+9TKHRYqoAUW57pLjhkLOnBCu0DQYMV+f7imQ9nXwI= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2 h1:SZRVx928rbYZ6hEKUIN+vtGDkl7uotABRWGY4OAg5gM= @@ -10,6 +12,8 @@ buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5 buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5345c0a56177.2/go.mod h1:GjH0gjlY/ns16X8d6eaXV2W+6IFwsO5Ly9WVnzyd1E0= buf.build/go/bufplugin v0.2.0 h1:nnNvWzUgQXitRDmjWWIkuXj9klreAAE94sVCsL+0v5g= buf.build/go/bufplugin v0.2.0/go.mod h1:ZZYGt6PDcjbBSywdz/G8NdXkIuWi2rzR8CduGzbCPdk= +buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9 h1:gdVcGNHVnuXgZN4wmVBP97OTTY8pCZS5rtT8agrVIC0= +buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9/go.mod h1:KmGYXJH84/xRYOm8m8dEKlLj/Rko9yLvetVrZ+tEmj0= buf.build/go/protoyaml v0.2.0 h1:2g3OHjtLDqXBREIOjpZGHmQ+U/4mkN1YiQjxNB68Ip8= buf.build/go/protoyaml v0.2.0/go.mod h1:L/9QvTDkTWcDTzAL6HMfN+mYC6CmZRm2KnsUA054iL0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= diff --git a/private/bufpkg/bufcheck/annotation.go b/private/bufpkg/bufcheck/annotation.go index 5e5323f1ec..98ff3f59cc 100644 --- a/private/bufpkg/bufcheck/annotation.go +++ b/private/bufpkg/bufcheck/annotation.go @@ -53,8 +53,8 @@ func annotationToFileAnnotation( pathToExternalPath map[string]string, annotation *annotation, ) bufanalysis.FileAnnotation { - location := annotation.Location() - if location == nil { + fileLocation := annotation.FileLocation() + if fileLocation == nil { // We have to do this or we get a weird fileInfo != nil but it is nil thing. return bufanalysis.NewFileAnnotation( nil, @@ -67,14 +67,14 @@ func annotationToFileAnnotation( annotation.PluginName(), ) } - path := location.File().FileDescriptor().Path() + path := fileLocation.FileDescriptor().Protoreflect().Path() // While it never should, it is OK if pathToExternalPath returns "" for a given path. // We handle this in fileInfo. fileInfo := newFileInfo(path, pathToExternalPath[path]) - startLine := location.StartLine() + 1 - startColumn := location.StartColumn() + 1 - endLine := location.EndLine() + 1 - endColumn := location.EndColumn() + 1 + startLine := fileLocation.StartLine() + 1 + startColumn := fileLocation.StartColumn() + 1 + endLine := fileLocation.EndLine() + 1 + endColumn := fileLocation.EndColumn() + 1 return bufanalysis.NewFileAnnotation( fileInfo, startLine, diff --git a/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/bufcheckserverutil.go b/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/bufcheckserverutil.go index 262eb7c029..fbe84a9260 100644 --- a/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/bufcheckserverutil.go +++ b/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/bufcheckserverutil.go @@ -18,6 +18,7 @@ import ( "context" "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/descriptor" "github.com/bufbuild/buf/private/bufpkg/bufprotosource" "github.com/bufbuild/buf/private/pkg/slicesext" "google.golang.org/protobuf/reflect/protodesc" @@ -32,11 +33,11 @@ func Before( ctx context.Context, request check.Request, ) (context.Context, check.Request, error) { - protosourceFiles, err := protosourceFilesForFiles(ctx, request.Files()) + protosourceFiles, err := protosourceFilesForFileDescriptors(ctx, request.FileDescriptors()) if err != nil { return nil, nil, err } - againstProtosourceFiles, err := protosourceFilesForFiles(ctx, request.AgainstFiles()) + againstProtosourceFiles, err := protosourceFilesForFileDescriptors(ctx, request.AgainstFileDescriptors()) if err != nil { return nil, nil, err } @@ -94,17 +95,17 @@ func (h multiRuleHandler) Handle(ctx context.Context, responseWriter check.Respo return nil } -func protosourceFilesForFiles(ctx context.Context, files []check.File) ([]bufprotosource.File, error) { - if len(files) == 0 { +func protosourceFilesForFileDescriptors(ctx context.Context, fileDescriptors []descriptor.FileDescriptor) ([]bufprotosource.File, error) { + if len(fileDescriptors) == 0 { return nil, nil } resolver, err := protodesc.NewFiles( &descriptorpb.FileDescriptorSet{ - File: slicesext.Map(files, check.File.FileDescriptorProto), + File: slicesext.Map(fileDescriptors, descriptor.FileDescriptor.FileDescriptorProto), }, ) if err != nil { return nil, err } - return bufprotosource.NewFiles(ctx, slicesext.Map(files, newInputFile), resolver) + return bufprotosource.NewFiles(ctx, slicesext.Map(fileDescriptors, newInputFile), resolver) } diff --git a/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go b/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go index 13dbb2e17f..2e63c49105 100644 --- a/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go +++ b/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go @@ -15,23 +15,23 @@ package bufcheckserverutil import ( - "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/descriptor" "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/gofrs/uuid/v5" ) type inputFile struct { - check.File + descriptor.FileDescriptor } -func newInputFile(file check.File) *inputFile { +func newInputFile(fileDescriptor descriptor.FileDescriptor) *inputFile { return &inputFile{ - File: file, + FileDescriptor: fileDescriptor, } } func (i *inputFile) Path() string { - return i.File.FileDescriptorProto().GetName() + return i.FileDescriptor.FileDescriptorProto().GetName() } func (i *inputFile) ExternalPath() string { diff --git a/private/bufpkg/bufcheck/check_client_spec.go b/private/bufpkg/bufcheck/check_client_spec.go index 86021bcfbe..0004438b9f 100644 --- a/private/bufpkg/bufcheck/check_client_spec.go +++ b/private/bufpkg/bufcheck/check_client_spec.go @@ -16,6 +16,7 @@ package bufcheck import ( "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/option" ) // checkClientSpec contains a check.Client and details on what to do about @@ -25,10 +26,10 @@ import ( type checkClientSpec struct { PluginName string Client check.Client - Options check.Options + Options option.Options } -func newCheckClientSpec(pluginName string, client check.Client, options check.Options) *checkClientSpec { +func newCheckClientSpec(pluginName string, client check.Client, options option.Options) *checkClientSpec { return &checkClientSpec{ PluginName: pluginName, Client: client, diff --git a/private/bufpkg/bufcheck/client.go b/private/bufpkg/bufcheck/client.go index 17e239636b..07510b3901 100644 --- a/private/bufpkg/bufcheck/client.go +++ b/private/bufpkg/bufcheck/client.go @@ -21,6 +21,8 @@ import ( "strings" "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/descriptor" + "buf.build/go/bufplugin/option" "github.com/bufbuild/buf/private/bufpkg/bufanalysis" "github.com/bufbuild/buf/private/bufpkg/bufcheck/bufcheckserver" "github.com/bufbuild/buf/private/bufpkg/bufconfig" @@ -111,7 +113,7 @@ func (c *client) Lint( return err } logRulesConfig(c.logger, config.rulesConfig) - files, err := check.FilesForProtoFiles(imageToProtoFiles(image)) + files, err := descriptor.FileDescriptorsForProtoFileDescriptors(imageToProtoFileDescriptors(image)) if err != nil { // If a validated Image results in an error, this is a system error. return syserror.Wrap(err) @@ -176,20 +178,20 @@ func (c *client) Breaking( return err } logRulesConfig(c.logger, config.rulesConfig) - files, err := check.FilesForProtoFiles(imageToProtoFiles(image)) + fileDescriptors, err := descriptor.FileDescriptorsForProtoFileDescriptors(imageToProtoFileDescriptors(image)) if err != nil { // If a validated Image results in an error, this is a system error. return syserror.Wrap(err) } - againstFiles, err := check.FilesForProtoFiles(imageToProtoFiles(againstImage)) + againstFileDescriptors, err := descriptor.FileDescriptorsForProtoFileDescriptors(imageToProtoFileDescriptors(againstImage)) if err != nil { // If a validated Image results in an error, this is a system error. return syserror.Wrap(err) } request, err := check.NewRequest( - files, + fileDescriptors, check.WithRuleIDs(config.RuleIDs...), - check.WithAgainstFiles(againstFiles), + check.WithAgainstFileDescriptors(againstFileDescriptors), check.WithOptions(config.DefaultOptions), ) if err != nil { @@ -286,11 +288,7 @@ func (c *client) allRulesAndCategories( // Just passing through to fulfill all contracts, ie checkClientSpec has non-nil Options. // Options are not used here. // config struct really just needs refactoring. - emptyOptions, err := check.NewOptions(nil) - if err != nil { - return nil, nil, err - } - multiClient, err := c.getMultiClient(fileVersion, pluginConfigs, disableBuiltin, emptyOptions) + multiClient, err := c.getMultiClient(fileVersion, pluginConfigs, disableBuiltin, option.EmptyOptions) if err != nil { return nil, nil, err } @@ -301,7 +299,7 @@ func (c *client) getMultiClient( fileVersion bufconfig.FileVersion, pluginConfigs []bufconfig.PluginConfig, disableBuiltin bool, - defaultOptions check.Options, + defaultOptions option.Options, ) (*multiClient, error) { var checkClientSpecs []*checkClientSpec if !disableBuiltin { @@ -316,7 +314,7 @@ func (c *client) getMultiClient( ) } for _, pluginConfig := range pluginConfigs { - options, err := check.NewOptions(pluginConfig.Options()) + options, err := option.NewOptions(pluginConfig.Options()) if err != nil { return nil, fmt.Errorf("could not parse options for plugin %q: %w", pluginConfig.Name(), err) } @@ -393,8 +391,8 @@ func ignoreAnnotation( config *config, annotation *annotation, ) (bool, error) { - if location := annotation.Location(); location != nil { - ignore, err := ignoreLocation(config, annotation.RuleID(), location) + if fileLocation := annotation.FileLocation(); fileLocation != nil { + ignore, err := ignoreFileLocation(config, annotation.RuleID(), fileLocation) if err != nil { return false, err } @@ -402,24 +400,24 @@ func ignoreAnnotation( return true, nil } } - if againstLocation := annotation.AgainstLocation(); againstLocation != nil { - return ignoreLocation(config, annotation.RuleID(), againstLocation) + if againstFileLocation := annotation.AgainstFileLocation(); againstFileLocation != nil { + return ignoreFileLocation(config, annotation.RuleID(), againstFileLocation) } return false, nil } -func ignoreLocation( +func ignoreFileLocation( config *config, ruleID string, - location check.Location, + fileLocation descriptor.FileLocation, ) (bool, error) { - file := location.File() - if config.ExcludeImports && file.IsImport() { + fileDescriptor := fileLocation.FileDescriptor() + if config.ExcludeImports && fileDescriptor.IsImport() { return true, nil } - fileDescriptor := file.FileDescriptor() - path := fileDescriptor.Path() + protoreflectFileDescriptor := fileDescriptor.Protoreflect() + path := protoreflectFileDescriptor.Path() if normalpath.MapHasEqualOrContainingPath(config.IgnoreRootPaths, path, normalpath.Relative) { return true, nil } @@ -430,7 +428,7 @@ func ignoreLocation( // Not a great design, but will never be triggered by lint since this is never set. if config.IgnoreUnstablePackages { - if packageVersion, ok := protoversion.NewPackageVersionForPackage(string(fileDescriptor.Package())); ok { + if packageVersion, ok := protoversion.NewPackageVersionForPackage(string(protoreflectFileDescriptor.Package())); ok { if packageVersion.StabilityLevel() != protoversion.StabilityLevelStable { return true, nil } @@ -440,7 +438,7 @@ func ignoreLocation( // Not a great design, but will never be triggered by breaking since this is never set. // Therefore, never called for an againstLocation (since lint never has againstLocations). if config.AllowCommentIgnores && config.CommentIgnorePrefix != "" { - sourcePath := location.SourcePath() + sourcePath := fileLocation.SourcePath() if len(sourcePath) == 0 { return false, nil } @@ -448,7 +446,7 @@ func ignoreLocation( if err != nil { return false, err } - sourceLocations := fileDescriptor.SourceLocations() + sourceLocations := protoreflectFileDescriptor.SourceLocations() for _, associatedSourcePath := range associatedSourcePaths { sourceLocation := sourceLocations.ByPath(associatedSourcePath) if leadingComments := sourceLocation.LeadingComments; leadingComments != "" { diff --git a/private/bufpkg/bufcheck/internal/bufcheckopt/bufcheckopt.go b/private/bufpkg/bufcheck/internal/bufcheckopt/bufcheckopt.go index 13f0e4710f..6d0c85ce50 100644 --- a/private/bufpkg/bufcheck/internal/bufcheckopt/bufcheckopt.go +++ b/private/bufpkg/bufcheck/internal/bufcheckopt/bufcheckopt.go @@ -15,7 +15,7 @@ package bufcheckopt import ( - "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/option" ) const ( @@ -30,14 +30,14 @@ const ( defaultServiceSuffix = "Service" ) -// OptionsSpec builds check.Options for clients. +// OptionsSpec builds option.Options for clients. // // These can then be sent over the wire to servers. // // Note that we don't expose OptionsSpec for the server-side rules, instead we rely // on the static functions, as we want to move our rules to be as native to bufplugin-go // as possible. Instead of i.e. attaching an Options struct to bufcheckserverutil.Requests, -// we have individual rules go through the direct reading of check.Options using +// we have individual rules go through the direct reading of option.Options using // the static functions below. // // Only use this on the client side. @@ -65,8 +65,8 @@ type OptionsSpec struct { CommentExcludes []string } -// ToOptions builds a check.Options. -func (o *OptionsSpec) ToOptions() (check.Options, error) { +// ToOptions builds a option.Options. +func (o *OptionsSpec) ToOptions() (option.Options, error) { keyToValue := make(map[string]any, 5) if value := o.EnumZeroValueSuffix; len(value) > 0 { keyToValue[enumZeroValueSuffixKey] = value @@ -86,14 +86,14 @@ func (o *OptionsSpec) ToOptions() (check.Options, error) { if value := o.CommentExcludes; len(value) > 0 { keyToValue[commentExcludesKey] = value } - return check.NewOptions(keyToValue) + return option.NewOptions(keyToValue) } // GetEnumZeroValueSuffix gets the enum zero-value suffix. // // Returns the default suffix if the option is not set. -func GetEnumZeroValueSuffix(options check.Options) (string, error) { - value, err := check.GetStringValue(options, enumZeroValueSuffixKey) +func GetEnumZeroValueSuffix(options option.Options) (string, error) { + value, err := option.GetStringValue(options, enumZeroValueSuffixKey) if err != nil { return "", err } @@ -106,31 +106,31 @@ func GetEnumZeroValueSuffix(options check.Options) (string, error) { // GetRPCAllowSameRequestResponse returns true if the rpc_allow_same_request_response option is set to true. // // Returns error if the value was unrecognized. -func GetRPCAllowSameRequestResponse(options check.Options) (bool, error) { - return check.GetBoolValue(options, rpcAllowSameRequestResponseKey) +func GetRPCAllowSameRequestResponse(options option.Options) (bool, error) { + return option.GetBoolValue(options, rpcAllowSameRequestResponseKey) } // GetRPCAllowGoogleProtobufEmptyRequests returns true if the rpc_allow_google_protobuf_empty_requests // option is set to true. // // Returns error if the value was unrecognized. -func GetRPCAllowGoogleProtobufEmptyRequests(options check.Options) (bool, error) { - return check.GetBoolValue(options, rpcAllowGoogleProtobufEmptyRequestsKey) +func GetRPCAllowGoogleProtobufEmptyRequests(options option.Options) (bool, error) { + return option.GetBoolValue(options, rpcAllowGoogleProtobufEmptyRequestsKey) } // GetRPCAllowGoogleProtobufEmptyResponses returns true if the rpc_allow_google_protobuf_empty_responses // option is set to true. // // Returns error if the value was unrecognized. -func GetRPCAllowGoogleProtobufEmptyResponses(options check.Options) (bool, error) { - return check.GetBoolValue(options, rpcAllowGoogleProtobufEmptyResponsesKey) +func GetRPCAllowGoogleProtobufEmptyResponses(options option.Options) (bool, error) { + return option.GetBoolValue(options, rpcAllowGoogleProtobufEmptyResponsesKey) } // GetServiceSuffix gets the service suffix. // // Returns the default suffix if the option is not set. -func GetServiceSuffix(options check.Options) (string, error) { - value, err := check.GetStringValue(options, serviceSuffixKey) +func GetServiceSuffix(options option.Options) (string, error) { + value, err := option.GetStringValue(options, serviceSuffixKey) if err != nil { return "", err } @@ -145,6 +145,6 @@ func GetServiceSuffix(options check.Options) (string, error) { // If a comment line starts with one of these excludes, it is not considered an actual comment. // // The returned slice is guaranteed to have only non-empty elements. -func GetCommentExcludes(options check.Options) ([]string, error) { - return check.GetStringSliceValue(options, commentExcludesKey) +func GetCommentExcludes(options option.Options) ([]string, error) { + return option.GetStringSliceValue(options, commentExcludesKey) } diff --git a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-panic/main.go b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-panic/main.go index 2e4ea38cfc..a6d360f9ad 100644 --- a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-panic/main.go +++ b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-panic/main.go @@ -19,6 +19,7 @@ import ( "buf.build/go/bufplugin/check" "buf.build/go/bufplugin/check/checkutil" + "buf.build/go/bufplugin/descriptor" ) func main() { @@ -38,6 +39,6 @@ func main() { ) } -func checkPanic(context.Context, check.ResponseWriter, check.Request, check.File) error { +func checkPanic(context.Context, check.ResponseWriter, check.Request, descriptor.FileDescriptor) error { panic("this panic is intentional") } diff --git a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/handlers.go b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/handlers.go index ad8deb7538..374588f58e 100644 --- a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/handlers.go +++ b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/handlers.go @@ -19,6 +19,7 @@ import ( "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/option" "github.com/bufbuild/protovalidate-go/resolver" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -113,7 +114,7 @@ func checkValidateIDDashless( fieldDescriptor protoreflect.FieldDescriptor, ) error { idFieldName := defaultIDFieldName - idFieldNameOptionValue, err := check.GetStringValue(request.Options(), idFieldNameOptionKey) + idFieldNameOptionValue, err := option.GetStringValue(request.Options(), idFieldNameOptionKey) if err != nil { return err } diff --git a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go index 72cdc5679f..fca4f76901 100644 --- a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go +++ b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go @@ -18,6 +18,7 @@ import ( "context" "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/descriptor" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -37,16 +38,16 @@ func breakingRuleHandlerForFile( responseWriter check.ResponseWriter, request check.Request, ) error { - filePathToFile := make(map[string]check.File) - for _, file := range request.Files() { - filePathToFile[file.FileDescriptor().Path()] = file + fileDescriptorPathToFileDescriptor := make(map[string]descriptor.FileDescriptor) + for _, fileDescriptor := range request.FileDescriptors() { + fileDescriptorPathToFileDescriptor[fileDescriptor.Protoreflect().Path()] = fileDescriptor } - for _, againstFile := range request.AgainstFiles() { - if !checkImport && againstFile.IsImport() { + for _, againstFileDescriptor := range request.AgainstFileDescriptors() { + if !checkImport && againstFileDescriptor.IsImport() { continue } - if file, ok := filePathToFile[againstFile.FileDescriptor().Path()]; ok { - if err := f(ctx, responseWriter, request, file.FileDescriptor(), againstFile.FileDescriptor()); err != nil { + if fileDescriptor, ok := fileDescriptorPathToFileDescriptor[againstFileDescriptor.Protoreflect().Path()]; ok { + if err := f(ctx, responseWriter, request, fileDescriptor.Protoreflect(), againstFileDescriptor.Protoreflect()); err != nil { return err } } diff --git a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-rpc-ext/main.go b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-rpc-ext/main.go index 7a2487a4eb..1a64d8b95b 100644 --- a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-rpc-ext/main.go +++ b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-rpc-ext/main.go @@ -20,6 +20,7 @@ import ( "buf.build/go/bufplugin/check" "buf.build/go/bufplugin/check/checkutil" + "buf.build/go/bufplugin/option" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -71,7 +72,7 @@ func checkPageRequestHasToken( return nil } pageRPCPrefixes := defaultPageRPCPrefixes - pageRPCPrefixesOptionValue, err := check.GetStringSliceValue(request.Options(), pageRPCPrefixOptionKey) + pageRPCPrefixesOptionValue, err := option.GetStringSliceValue(request.Options(), pageRPCPrefixOptionKey) if err != nil { return err } @@ -89,7 +90,7 @@ func checkPageRequestHasToken( return nil } pageTokenFieldName := defaultPageTokenFieldName - pageTokenFieldNameOptionValue, err := check.GetStringValue(request.Options(), pageTokenFieldNameOptionKey) + pageTokenFieldNameOptionValue, err := option.GetStringValue(request.Options(), pageTokenFieldNameOptionKey) if err != nil { return err } @@ -121,7 +122,7 @@ func checkPageResponseHasToken( return nil } pageRPCPrefixes := defaultPageRPCPrefixes - pageRPCPrefixesOptionValue, err := check.GetStringSliceValue(request.Options(), pageRPCPrefixOptionKey) + pageRPCPrefixesOptionValue, err := option.GetStringSliceValue(request.Options(), pageRPCPrefixOptionKey) if err != nil { return err } @@ -139,7 +140,7 @@ func checkPageResponseHasToken( return nil } pageTokenFieldName := defaultPageTokenFieldName - pageTokenFieldNameOptionValue, err := check.GetStringValue(request.Options(), pageTokenFieldNameOptionKey) + pageTokenFieldNameOptionValue, err := option.GetStringValue(request.Options(), pageTokenFieldNameOptionKey) if err != nil { return err } diff --git a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go index 305a623ba8..3cf47fe231 100644 --- a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go +++ b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go @@ -20,6 +20,8 @@ import ( "strings" "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/descriptor" + "buf.build/go/bufplugin/option" "github.com/bufbuild/buf/private/pkg/slicesext" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -43,8 +45,8 @@ func handleLintServiceBannedSuffixes( if err != nil { return err } - for _, file := range request.Files() { - descriptor := file.FileDescriptor() + for _, fileDescriptor := range request.FileDescriptors() { + descriptor := fileDescriptor.Protoreflect() for i := 0; i < descriptor.Services().Len(); i++ { service := descriptor.Services().Get(i) checkDescriptorBannedSuffixes(responseWriter, service, bannedServiceSuffixes, "Service") @@ -62,8 +64,8 @@ func handleLintRPCBannedSuffixes( if err != nil { return err } - for _, file := range request.Files() { - descriptor := file.FileDescriptor() + for _, fileDescriptor := range request.FileDescriptors() { + descriptor := fileDescriptor.Protoreflect() for i := 0; i < descriptor.Services().Len(); i++ { methods := descriptor.Services().Get(i).Methods() for j := 0; j < methods.Len(); j++ { @@ -84,8 +86,8 @@ func handleLintFieldBannedSuffixes( if err != nil { return err } - for _, file := range request.Files() { - descriptor := file.FileDescriptor() + for _, fileDescriptor := range request.FileDescriptors() { + descriptor := fileDescriptor.Protoreflect() for i := 0; i < descriptor.Messages().Len(); i++ { message := descriptor.Messages().Get(i) checkBannedFieldSuffixesForMessage(responseWriter, message, bannedFieldSuffixes) @@ -120,8 +122,8 @@ func handleLintEnumValueBannedSuffixes( if err != nil { return err } - for _, file := range request.Files() { - descriptor := file.FileDescriptor() + for _, fileDescriptor := range request.FileDescriptors() { + descriptor := fileDescriptor.Protoreflect() for i := 0; i < descriptor.Enums().Len(); i++ { enum := descriptor.Enums().Get(i) for j := 0; j < enum.Values().Len(); j++ { @@ -189,11 +191,11 @@ func handleBreakingServiceSuffixesNoChange( return err } previousNoChangeServiceNameToServiceDescriptor := mapServiceNameToServiceDescriptorForFilesAndNoChangeSuffixes( - request.AgainstFiles(), + request.AgainstFileDescriptors(), serviceNoChangeSuffixes, ) currentNoChangeServiceNameToServiceDescriptor := mapServiceNameToServiceDescriptorForFilesAndNoChangeSuffixes( - request.Files(), + request.FileDescriptors(), nil, ) for previousServiceName, previousServiceDescriptor := range previousNoChangeServiceNameToServiceDescriptor { @@ -232,12 +234,12 @@ func handleBreakingServiceSuffixesNoChange( // service descriptors for the given check files based on the the no change suffixes. // If no suffixes are passed, then all services are returned. func mapServiceNameToServiceDescriptorForFilesAndNoChangeSuffixes( - files []check.File, + fileDescriptors []descriptor.FileDescriptor, serviceNoChangeSuffixes []string, ) map[string]protoreflect.ServiceDescriptor { result := map[string]protoreflect.ServiceDescriptor{} - for _, file := range files { - descriptor := file.FileDescriptor() + for _, fileDescriptor := range fileDescriptors { + descriptor := fileDescriptor.Protoreflect() for i := 0; i < descriptor.Services().Len(); i++ { service := descriptor.Services().Get(i) if checkDescriptorHasNoChangeSuffix(service, serviceNoChangeSuffixes) { @@ -268,11 +270,11 @@ func handleBreakingMessageSuffixesNoChange( return err } previousNoChangeMessageNameToMessageDescriptor := mapMessageNameToMessageDescriptorForFilesAndNoChangeSuffixes( - request.AgainstFiles(), + request.AgainstFileDescriptors(), messageNoChangeSuffixes, ) currentNoChangeMessageNameToMessageDescriptor := mapMessageNameToMessageDescriptorForFilesAndNoChangeSuffixes( - request.Files(), + request.FileDescriptors(), messageNoChangeSuffixes, ) for previousMessageName, previousMessageDescriptor := range previousNoChangeMessageNameToMessageDescriptor { @@ -311,12 +313,12 @@ func handleBreakingMessageSuffixesNoChange( // message descriptors for the given check files based on the the no change suffixes. // If no suffixes are passed, then all messages are returned. func mapMessageNameToMessageDescriptorForFilesAndNoChangeSuffixes( - files []check.File, + fileDescriptors []descriptor.FileDescriptor, messageNoChangeSuffixes []string, ) map[string]protoreflect.MessageDescriptor { result := map[string]protoreflect.MessageDescriptor{} - for _, file := range files { - descriptor := file.FileDescriptor() + for _, fileDescriptor := range fileDescriptors { + descriptor := fileDescriptor.Protoreflect() messages := getNestedMessageDescriptors(descriptor.Messages(), messageNoChangeSuffixes) for _, message := range messages { result[string(message.FullName())] = message @@ -361,11 +363,11 @@ func handleBreakingEnumSuffixesNoChange( return err } previousNoChangeEnumNameToEnumDescriptor := mapEnumNameToEnumDescriptorForFilesAndNoChangeSuffixes( - request.AgainstFiles(), + request.AgainstFileDescriptors(), enumNoChangeSuffixes, ) currentNoChangeEnumNameToEnumDescriptor := mapEnumNameToEnumDescriptorForFilesAndNoChangeSuffixes( - request.Files(), + request.FileDescriptors(), enumNoChangeSuffixes, ) for previousEnumName, previousEnumDescriptor := range previousNoChangeEnumNameToEnumDescriptor { @@ -401,12 +403,12 @@ func handleBreakingEnumSuffixesNoChange( } func mapEnumNameToEnumDescriptorForFilesAndNoChangeSuffixes( - files []check.File, + fileDescriptors []descriptor.FileDescriptor, enumNoChangeSuffixes []string, ) map[string]protoreflect.EnumDescriptor { result := map[string]protoreflect.EnumDescriptor{} - for _, file := range files { - descriptor := file.FileDescriptor() + for _, fileDescriptor := range fileDescriptors { + descriptor := fileDescriptor.Protoreflect() for i := 0; i < descriptor.Enums().Len(); i++ { enum := descriptor.Enums().Get(i) if checkDescriptorHasNoChangeSuffix(enum, enumNoChangeSuffixes) { @@ -469,5 +471,5 @@ func getSuffixes( request check.Request, optionKey string, ) ([]string, error) { - return check.GetStringSliceValue(request.Options(), optionKey) + return option.GetStringSliceValue(request.Options(), optionKey) } diff --git a/private/bufpkg/bufcheck/multi_client.go b/private/bufpkg/bufcheck/multi_client.go index 52ed43403b..861b55e4ce 100644 --- a/private/bufpkg/bufcheck/multi_client.go +++ b/private/bufpkg/bufcheck/multi_client.go @@ -81,8 +81,8 @@ func (c *multiClient) Check(ctx context.Context, request check.Request) ([]*anno continue } delegateRequest, err := check.NewRequest( - request.Files(), - check.WithAgainstFiles(request.AgainstFiles()), + request.FileDescriptors(), + check.WithAgainstFileDescriptors(request.AgainstFileDescriptors()), // Do not use the options from Request. We parsed the options to the config or to // the checkClientSpec. check.WithOptions(delegate.Options), diff --git a/private/bufpkg/bufcheck/options_config.go b/private/bufpkg/bufcheck/options_config.go index 8133436ba5..3698c09abc 100644 --- a/private/bufpkg/bufcheck/options_config.go +++ b/private/bufpkg/bufcheck/options_config.go @@ -16,6 +16,7 @@ package bufcheck import ( "buf.build/go/bufplugin/check" + "buf.build/go/bufplugin/option" "github.com/bufbuild/buf/private/bufpkg/bufcheck/internal/bufcheckopt" "github.com/bufbuild/buf/private/bufpkg/bufconfig" ) @@ -27,7 +28,7 @@ type optionsConfig struct { // // Do not pass these to plugin check.Clients. Use options from checkClientSpecs instead. // Will never be nil. - DefaultOptions check.Options + DefaultOptions option.Options AllowCommentIgnores bool IgnoreUnstablePackages bool CommentIgnorePrefix string diff --git a/private/bufpkg/bufcheck/util.go b/private/bufpkg/bufcheck/util.go index a75a16d8c0..c6df99e23c 100644 --- a/private/bufpkg/bufcheck/util.go +++ b/private/bufpkg/bufcheck/util.go @@ -15,20 +15,20 @@ package bufcheck import ( - checkv1 "buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go/buf/plugin/check/v1" + descriptorv1 "buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go/buf/plugin/descriptor/v1" "github.com/bufbuild/buf/private/bufpkg/bufimage" "github.com/bufbuild/buf/private/pkg/slicesext" ) -func imageToProtoFiles(image bufimage.Image) []*checkv1.File { +func imageToProtoFileDescriptors(image bufimage.Image) []*descriptorv1.FileDescriptor { if image == nil { return nil } - return slicesext.Map(image.Files(), imageFileToProtoFile) + return slicesext.Map(image.Files(), imageToProtoFileDescriptor) } -func imageFileToProtoFile(imageFile bufimage.ImageFile) *checkv1.File { - return &checkv1.File{ +func imageToProtoFileDescriptor(imageFile bufimage.ImageFile) *descriptorv1.FileDescriptor { + return &descriptorv1.FileDescriptor{ FileDescriptorProto: imageFile.FileDescriptorProto(), IsImport: imageFile.IsImport(), IsSyntaxUnspecified: imageFile.IsSyntaxUnspecified(), From 206798e91a8e063b8badf8714dfb8e2edb208c9d Mon Sep 17 00:00:00 2001 From: bufdev Date: Fri, 20 Sep 2024 14:50:21 -0400 Subject: [PATCH 2/4] commit --- go.sum | 4 ---- .../bufcheckserver/bufcheckserver_test.go | 8 ++++---- private/bufpkg/bufcheck/multi_client_test.go | 17 +++++++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/go.sum b/go.sum index 83ab33f344..3e6b7f5f96 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2 h1:saqQcA0XF8LL9vE7OvN1CDPQYy4M8oWU+0C1O8eh/cU= buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2/go.mod h1:B+9TKHRYqoAUW57pLjhkLOnBCu0DQYMV+f7imQ9nXwI= -buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240904181154-a0be11449112.2 h1:X9qBPcvWGOJs/CeRVLoxxLJwC/eKyWDS/G4nj+3KGMY= -buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240904181154-a0be11449112.2/go.mod h1:B+9TKHRYqoAUW57pLjhkLOnBCu0DQYMV+f7imQ9nXwI= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2 h1:SZRVx928rbYZ6hEKUIN+vtGDkl7uotABRWGY4OAg5gM= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2/go.mod h1:ylS4c28ACSI59oJrOdW4pHS4n0Hw4TgSPHn8rpHl4Yw= buf.build/gen/go/bufbuild/registry/connectrpc/go v1.16.2-20240821192916-45ba72cdd479.1 h1:QaJ6UkpvlGo4dBXR41vLRfPiKungbg7brjmbBC/k6Ig= @@ -10,8 +8,6 @@ buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240821192916-45b buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240821192916-45ba72cdd479.2/go.mod h1:psseUmlKRo9v5LZJtR/aTpdTLuyp9o3X7rnLT87SZEo= buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5345c0a56177.2 h1:oSi+Adw4xvIjXrW8eY8QGR3sBdfWeY5HN/RefnRt52M= buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5345c0a56177.2/go.mod h1:GjH0gjlY/ns16X8d6eaXV2W+6IFwsO5Ly9WVnzyd1E0= -buf.build/go/bufplugin v0.2.0 h1:nnNvWzUgQXitRDmjWWIkuXj9klreAAE94sVCsL+0v5g= -buf.build/go/bufplugin v0.2.0/go.mod h1:ZZYGt6PDcjbBSywdz/G8NdXkIuWi2rzR8CduGzbCPdk= buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9 h1:gdVcGNHVnuXgZN4wmVBP97OTTY8pCZS5rtT8agrVIC0= buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9/go.mod h1:KmGYXJH84/xRYOm8m8dEKlLj/Rko9yLvetVrZ+tEmj0= buf.build/go/protoyaml v0.2.0 h1:2g3OHjtLDqXBREIOjpZGHmQ+U/4mkN1YiQjxNB68Ip8= diff --git a/private/bufpkg/bufcheck/bufcheckserver/bufcheckserver_test.go b/private/bufpkg/bufcheck/bufcheckserver/bufcheckserver_test.go index 43958d1249..7c2c8e4202 100644 --- a/private/bufpkg/bufcheck/bufcheckserver/bufcheckserver_test.go +++ b/private/bufpkg/bufcheck/bufcheckserver/bufcheckserver_test.go @@ -56,7 +56,7 @@ func TestServicePascalCase(t *testing.T) { ExpectedAnnotations: []checktest.ExpectedAnnotation{ { RuleID: "SERVICE_PASCAL_CASE", - Location: &checktest.ExpectedLocation{ + FileLocation: &checktest.ExpectedFileLocation{ FileName: "a.proto", StartLine: 7, StartColumn: 8, @@ -66,7 +66,7 @@ func TestServicePascalCase(t *testing.T) { }, { RuleID: "SERVICE_PASCAL_CASE", - Location: &checktest.ExpectedLocation{ + FileLocation: &checktest.ExpectedFileLocation{ FileName: "a.proto", StartLine: 8, StartColumn: 8, @@ -76,7 +76,7 @@ func TestServicePascalCase(t *testing.T) { }, { RuleID: "SERVICE_PASCAL_CASE", - Location: &checktest.ExpectedLocation{ + FileLocation: &checktest.ExpectedFileLocation{ FileName: "a.proto", StartLine: 9, StartColumn: 8, @@ -86,7 +86,7 @@ func TestServicePascalCase(t *testing.T) { }, { RuleID: "SERVICE_PASCAL_CASE", - Location: &checktest.ExpectedLocation{ + FileLocation: &checktest.ExpectedFileLocation{ FileName: "a.proto", StartLine: 10, StartColumn: 8, diff --git a/private/bufpkg/bufcheck/multi_client_test.go b/private/bufpkg/bufcheck/multi_client_test.go index dadd64d134..e42195d25c 100644 --- a/private/bufpkg/bufcheck/multi_client_test.go +++ b/private/bufpkg/bufcheck/multi_client_test.go @@ -22,6 +22,7 @@ import ( "buf.build/go/bufplugin/check" "buf.build/go/bufplugin/check/checktest" "buf.build/go/bufplugin/check/checkutil" + "buf.build/go/bufplugin/option" "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/pkg/command" "github.com/bufbuild/buf/private/pkg/slicesext" @@ -102,7 +103,7 @@ func testMultiClientSimple(t *testing.T, cacheRules bool) { require.NoError(t, err) timestampSuffixClient, err := check.NewClientForSpec(timestampSuffixSpec, clientForSpecOptions...) require.NoError(t, err) - emptyOptions, err := check.NewOptions(nil) + emptyOptions, err := option.NewOptions(nil) require.NoError(t, err) multiClient := newMultiClient( zap.NewNop(), @@ -129,7 +130,7 @@ func testMultiClientSimple(t *testing.T, cacheRules bool) { []checktest.ExpectedAnnotation{ { RuleID: fieldLowerSnakeCaseRuleID, - Location: &checktest.ExpectedLocation{ + FileLocation: &checktest.ExpectedFileLocation{ FileName: "simple.proto", StartLine: 10, StartColumn: 2, @@ -139,7 +140,7 @@ func testMultiClientSimple(t *testing.T, cacheRules bool) { }, { RuleID: timestampSuffixRuleID, - Location: &checktest.ExpectedLocation{ + FileLocation: &checktest.ExpectedFileLocation{ FileName: "simple.proto", StartLine: 9, StartColumn: 2, @@ -162,7 +163,7 @@ func TestMultiClientCannotHaveOverlappingRules(t *testing.T) { fieldLowerSnakeCaseClient, err := check.NewClientForSpec(fieldLowerSnakeCaseSpec) require.NoError(t, err) - emptyOptions, err := check.NewOptions(nil) + emptyOptions, err := option.NewOptions(nil) require.NoError(t, err) multiClient := newMultiClient( zap.NewNop(), @@ -193,7 +194,7 @@ func TestMultiClientCannotHaveOverlappingRulesWithBuiltIn(t *testing.T) { []string{"buf-plugin-duplicate-rule"}, ) require.NoError(t, err) - emptyOptions, err := check.NewOptions(nil) + emptyOptions, err := option.NewOptions(nil) require.NoError(t, err) multiClient, err := client.getMultiClient( @@ -256,7 +257,7 @@ func TestMultiClientCannotHaveOverlappingCategories(t *testing.T) { require.NoError(t, err) client2, err := check.NewClientForSpec(client2Spec) require.NoError(t, err) - emptyOptions, err := check.NewOptions(nil) + emptyOptions, err := option.NewOptions(nil) require.NoError(t, err) multiClient := newMultiClient( zap.NewNop(), @@ -287,7 +288,7 @@ func TestMultiClientCannotHaveOverlappingCategoriesWithBuiltIn(t *testing.T) { []string{"buf-plugin-duplicate-category"}, ) require.NoError(t, err) - emptyOptions, err := check.NewOptions(nil) + emptyOptions, err := option.NewOptions(nil) require.NoError(t, err) multiClient, err := client.getMultiClient( @@ -330,7 +331,7 @@ func checkTimestampSuffix( fieldDescriptor protoreflect.FieldDescriptor, ) error { timestampSuffix := defaultTimestampSuffix - timestampSuffixOptionValue, err := check.GetStringValue(request.Options(), timestampSuffixOptionKey) + timestampSuffixOptionValue, err := option.GetStringValue(request.Options(), timestampSuffixOptionKey) if err != nil { return err } From 052198022b5e8a769015346bc996afa5af377366 Mon Sep 17 00:00:00 2001 From: bufdev Date: Fri, 20 Sep 2024 15:57:48 -0400 Subject: [PATCH 3/4] update --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 542c0fad8d..66a8d2cb31 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,11 @@ go 1.22.0 toolchain go1.23.1 require ( - buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2 + buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240920185553-cf97df2825f6.2 buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2 buf.build/gen/go/bufbuild/registry/connectrpc/go v1.16.2-20240821192916-45ba72cdd479.1 buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240821192916-45ba72cdd479.2 - buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9 + buf.build/go/bufplugin v0.3.0 buf.build/go/protoyaml v0.2.0 connectrpc.com/connect v1.16.2 connectrpc.com/otelconnect v0.7.1 diff --git a/go.sum b/go.sum index 3e6b7f5f96..86a8a9d56f 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2 h1:saqQcA0XF8LL9vE7OvN1CDPQYy4M8oWU+0C1O8eh/cU= -buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-00000000000000-9761ea6a8cee.2/go.mod h1:B+9TKHRYqoAUW57pLjhkLOnBCu0DQYMV+f7imQ9nXwI= +buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240920185553-cf97df2825f6.2 h1:dM/jKJP5298DVmmet50pEaREQY1ZleguYDrpUWwl6AA= +buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240920185553-cf97df2825f6.2/go.mod h1:B+9TKHRYqoAUW57pLjhkLOnBCu0DQYMV+f7imQ9nXwI= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2 h1:SZRVx928rbYZ6hEKUIN+vtGDkl7uotABRWGY4OAg5gM= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240717164558-a6c49f84cc0f.2/go.mod h1:ylS4c28ACSI59oJrOdW4pHS4n0Hw4TgSPHn8rpHl4Yw= buf.build/gen/go/bufbuild/registry/connectrpc/go v1.16.2-20240821192916-45ba72cdd479.1 h1:QaJ6UkpvlGo4dBXR41vLRfPiKungbg7brjmbBC/k6Ig= @@ -8,8 +8,8 @@ buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240821192916-45b buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240821192916-45ba72cdd479.2/go.mod h1:psseUmlKRo9v5LZJtR/aTpdTLuyp9o3X7rnLT87SZEo= buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5345c0a56177.2 h1:oSi+Adw4xvIjXrW8eY8QGR3sBdfWeY5HN/RefnRt52M= buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5345c0a56177.2/go.mod h1:GjH0gjlY/ns16X8d6eaXV2W+6IFwsO5Ly9WVnzyd1E0= -buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9 h1:gdVcGNHVnuXgZN4wmVBP97OTTY8pCZS5rtT8agrVIC0= -buf.build/go/bufplugin v0.2.1-0.20240920182654-d68e828cd8f9/go.mod h1:KmGYXJH84/xRYOm8m8dEKlLj/Rko9yLvetVrZ+tEmj0= +buf.build/go/bufplugin v0.3.0 h1:0kxad9/q3nCEbHVYR02crapmRyVT0zTqC/gNkzxuWSs= +buf.build/go/bufplugin v0.3.0/go.mod h1:Znx3zF4ThDWGN1eGFMsbVT9LkMcVV4MKeAC9hiGdN6g= buf.build/go/protoyaml v0.2.0 h1:2g3OHjtLDqXBREIOjpZGHmQ+U/4mkN1YiQjxNB68Ip8= buf.build/go/protoyaml v0.2.0/go.mod h1:L/9QvTDkTWcDTzAL6HMfN+mYC6CmZRm2KnsUA054iL0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= From 764d4b75eba08e01a9883db6733b2135cb52e087 Mon Sep 17 00:00:00 2001 From: bufdev Date: Fri, 20 Sep 2024 16:05:33 -0400 Subject: [PATCH 4/4] fix --- private/bufpkg/bufcheck/annotation.go | 2 +- private/bufpkg/bufcheck/client.go | 2 +- .../cmd/buf-plugin-protovalidate-ext/util.go | 6 +++--- .../internal/cmd/buf-plugin-suffix/handlers.go | 14 +++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/private/bufpkg/bufcheck/annotation.go b/private/bufpkg/bufcheck/annotation.go index 98ff3f59cc..37799f56e2 100644 --- a/private/bufpkg/bufcheck/annotation.go +++ b/private/bufpkg/bufcheck/annotation.go @@ -67,7 +67,7 @@ func annotationToFileAnnotation( annotation.PluginName(), ) } - path := fileLocation.FileDescriptor().Protoreflect().Path() + path := fileLocation.FileDescriptor().ProtoreflectFileDescriptor().Path() // While it never should, it is OK if pathToExternalPath returns "" for a given path. // We handle this in fileInfo. fileInfo := newFileInfo(path, pathToExternalPath[path]) diff --git a/private/bufpkg/bufcheck/client.go b/private/bufpkg/bufcheck/client.go index 07510b3901..edb0d5fd4b 100644 --- a/private/bufpkg/bufcheck/client.go +++ b/private/bufpkg/bufcheck/client.go @@ -416,7 +416,7 @@ func ignoreFileLocation( return true, nil } - protoreflectFileDescriptor := fileDescriptor.Protoreflect() + protoreflectFileDescriptor := fileDescriptor.ProtoreflectFileDescriptor() path := protoreflectFileDescriptor.Path() if normalpath.MapHasEqualOrContainingPath(config.IgnoreRootPaths, path, normalpath.Relative) { return true, nil diff --git a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go index fca4f76901..e417d33d81 100644 --- a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go +++ b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext/util.go @@ -40,14 +40,14 @@ func breakingRuleHandlerForFile( ) error { fileDescriptorPathToFileDescriptor := make(map[string]descriptor.FileDescriptor) for _, fileDescriptor := range request.FileDescriptors() { - fileDescriptorPathToFileDescriptor[fileDescriptor.Protoreflect().Path()] = fileDescriptor + fileDescriptorPathToFileDescriptor[fileDescriptor.ProtoreflectFileDescriptor().Path()] = fileDescriptor } for _, againstFileDescriptor := range request.AgainstFileDescriptors() { if !checkImport && againstFileDescriptor.IsImport() { continue } - if fileDescriptor, ok := fileDescriptorPathToFileDescriptor[againstFileDescriptor.Protoreflect().Path()]; ok { - if err := f(ctx, responseWriter, request, fileDescriptor.Protoreflect(), againstFileDescriptor.Protoreflect()); err != nil { + if fileDescriptor, ok := fileDescriptorPathToFileDescriptor[againstFileDescriptor.ProtoreflectFileDescriptor().Path()]; ok { + if err := f(ctx, responseWriter, request, fileDescriptor.ProtoreflectFileDescriptor(), againstFileDescriptor.ProtoreflectFileDescriptor()); err != nil { return err } } diff --git a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go index 3cf47fe231..2fc8e709cf 100644 --- a/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go +++ b/private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go @@ -46,7 +46,7 @@ func handleLintServiceBannedSuffixes( return err } for _, fileDescriptor := range request.FileDescriptors() { - descriptor := fileDescriptor.Protoreflect() + descriptor := fileDescriptor.ProtoreflectFileDescriptor() for i := 0; i < descriptor.Services().Len(); i++ { service := descriptor.Services().Get(i) checkDescriptorBannedSuffixes(responseWriter, service, bannedServiceSuffixes, "Service") @@ -65,7 +65,7 @@ func handleLintRPCBannedSuffixes( return err } for _, fileDescriptor := range request.FileDescriptors() { - descriptor := fileDescriptor.Protoreflect() + descriptor := fileDescriptor.ProtoreflectFileDescriptor() for i := 0; i < descriptor.Services().Len(); i++ { methods := descriptor.Services().Get(i).Methods() for j := 0; j < methods.Len(); j++ { @@ -87,7 +87,7 @@ func handleLintFieldBannedSuffixes( return err } for _, fileDescriptor := range request.FileDescriptors() { - descriptor := fileDescriptor.Protoreflect() + descriptor := fileDescriptor.ProtoreflectFileDescriptor() for i := 0; i < descriptor.Messages().Len(); i++ { message := descriptor.Messages().Get(i) checkBannedFieldSuffixesForMessage(responseWriter, message, bannedFieldSuffixes) @@ -123,7 +123,7 @@ func handleLintEnumValueBannedSuffixes( return err } for _, fileDescriptor := range request.FileDescriptors() { - descriptor := fileDescriptor.Protoreflect() + descriptor := fileDescriptor.ProtoreflectFileDescriptor() for i := 0; i < descriptor.Enums().Len(); i++ { enum := descriptor.Enums().Get(i) for j := 0; j < enum.Values().Len(); j++ { @@ -239,7 +239,7 @@ func mapServiceNameToServiceDescriptorForFilesAndNoChangeSuffixes( ) map[string]protoreflect.ServiceDescriptor { result := map[string]protoreflect.ServiceDescriptor{} for _, fileDescriptor := range fileDescriptors { - descriptor := fileDescriptor.Protoreflect() + descriptor := fileDescriptor.ProtoreflectFileDescriptor() for i := 0; i < descriptor.Services().Len(); i++ { service := descriptor.Services().Get(i) if checkDescriptorHasNoChangeSuffix(service, serviceNoChangeSuffixes) { @@ -318,7 +318,7 @@ func mapMessageNameToMessageDescriptorForFilesAndNoChangeSuffixes( ) map[string]protoreflect.MessageDescriptor { result := map[string]protoreflect.MessageDescriptor{} for _, fileDescriptor := range fileDescriptors { - descriptor := fileDescriptor.Protoreflect() + descriptor := fileDescriptor.ProtoreflectFileDescriptor() messages := getNestedMessageDescriptors(descriptor.Messages(), messageNoChangeSuffixes) for _, message := range messages { result[string(message.FullName())] = message @@ -408,7 +408,7 @@ func mapEnumNameToEnumDescriptorForFilesAndNoChangeSuffixes( ) map[string]protoreflect.EnumDescriptor { result := map[string]protoreflect.EnumDescriptor{} for _, fileDescriptor := range fileDescriptors { - descriptor := fileDescriptor.Protoreflect() + descriptor := fileDescriptor.ProtoreflectFileDescriptor() for i := 0; i < descriptor.Enums().Len(); i++ { enum := descriptor.Enums().Get(i) if checkDescriptorHasNoChangeSuffix(enum, enumNoChangeSuffixes) {