Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add support for #validate=true to message refs (#2633)" #2755

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions private/buf/buffetch/buffetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const (

useProtoNamesKey = "use_proto_names"
useEnumNumbersKey = "use_enum_numbers"
validateKey = "validate"
)

var (
Expand Down Expand Up @@ -111,16 +110,10 @@ type MessageRef interface {
//
// May be used for items such as YAML unmarshaling errors.
Path() string
// UseProtoNames indicates if the message should use proto names when encoding.
//
// Only applies for MessageEncodingYAML at this time.
// UseProtoNames only applies for MessageEncodingYAML at this time.
UseProtoNames() bool
// UseEnumNumbers indicates if the message should use enum numbers when encoding.
//
// Only applies for MessageEncodingYAML at this time.
// UseEnumNumbers only applies for MessageEncodingYAML at this time.
UseEnumNumbers() bool
// Validate indicates if the message should be validated when decoding.
Validate() bool
IsNull() bool
internalSingleRef() internal.SingleRef
}
Expand Down
10 changes: 0 additions & 10 deletions private/buf/buffetch/message_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type messageRef struct {
singleRef internal.SingleRef
useProtoNames bool
useEnumNumbers bool
validate bool
messageEncoding MessageEncoding
}

Expand All @@ -41,15 +40,10 @@ func newMessageRef(
if err != nil {
return nil, err
}
validate, err := getTrueOrFalseForSingleRef(singleRef, validateKey)
if err != nil {
return nil, err
}
return &messageRef{
singleRef: singleRef,
useProtoNames: useProtoNames,
useEnumNumbers: useEnumNumbers,
validate: validate,
messageEncoding: messageEncoding,
}, nil
}
Expand All @@ -74,10 +68,6 @@ func (r *messageRef) UseEnumNumbers() bool {
return r.useEnumNumbers
}

func (r *messageRef) Validate() bool {
return r.validate
}

func (r *messageRef) IsNull() bool {
return r.singleRef.FileScheme() == internal.FileSchemeNull
}
Expand Down
33 changes: 6 additions & 27 deletions private/buf/buffetch/ref_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,18 @@ func newRefParser(logger *zap.Logger) *refParser {
fetchRefParser: internal.NewRefParser(
logger,
internal.WithRawRefProcessor(processRawRef),
internal.WithSingleFormat(
formatBin,
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(
formatBinpb,
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(formatBin),
internal.WithSingleFormat(formatBinpb),
internal.WithSingleFormat(
formatJSON,
internal.WithSingleCustomOptionKey(useProtoNamesKey),
internal.WithSingleCustomOptionKey(useEnumNumbersKey),
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(
formatTxtpb,
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(formatTxtpb),
internal.WithSingleFormat(
formatYAML,
internal.WithSingleCustomOptionKey(useProtoNamesKey),
internal.WithSingleCustomOptionKey(useEnumNumbersKey),
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(
formatBingz,
Expand Down Expand Up @@ -118,28 +107,18 @@ func newMessageRefParser(logger *zap.Logger, options ...MessageRefParserOption)
fetchRefParser: internal.NewRefParser(
logger,
internal.WithRawRefProcessor(newProcessRawRefMessage(messageRefParserOptions.defaultMessageEncoding)),
internal.WithSingleFormat(
formatBin,
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(
formatBinpb,
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(formatBin),
internal.WithSingleFormat(formatBinpb),
internal.WithSingleFormat(
formatJSON,
internal.WithSingleCustomOptionKey(useProtoNamesKey),
internal.WithSingleCustomOptionKey(useEnumNumbersKey),
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(formatTxtpb,
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(formatTxtpb),
internal.WithSingleFormat(
formatYAML,
internal.WithSingleCustomOptionKey(useProtoNamesKey),
internal.WithSingleCustomOptionKey(useEnumNumbersKey),
internal.WithSingleCustomOptionKey(validateKey),
),
internal.WithSingleFormat(
formatBingz,
Expand Down
17 changes: 0 additions & 17 deletions private/buf/bufwire/proto_encoding_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufreflect"
"github.com/bufbuild/buf/private/pkg/app"
"github.com/bufbuild/buf/private/pkg/protoencoding"
"github.com/bufbuild/protovalidate-go"
"github.com/bufbuild/protoyaml-go"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/codes"
"go.uber.org/multierr"
Expand Down Expand Up @@ -73,14 +71,6 @@ func (p *protoEncodingReader) GetMessage(
if err != nil {
return nil, err
}
var validator protoyaml.Validator
if messageRef.Validate() {
var err error
validator, err = protovalidate.New()
if err != nil {
return nil, err
}
}
var unmarshaler protoencoding.Unmarshaler
switch messageRef.MessageEncoding() {
case buffetch.MessageEncodingBinpb:
Expand All @@ -93,9 +83,7 @@ func (p *protoEncodingReader) GetMessage(
unmarshaler = protoencoding.NewYAMLUnmarshaler(
resolver,
protoencoding.YAMLUnmarshalerWithPath(messageRef.Path()),
protoencoding.YAMLUnmarshalerWithValidator(validator),
)
validator = nil // Validation errors are handled by the unmarshaler.
default:
return nil, errors.New("unknown message encoding type")
}
Expand All @@ -120,10 +108,5 @@ func (p *protoEncodingReader) GetMessage(
if err := unmarshaler.Unmarshal(data, message); err != nil {
return nil, fmt.Errorf("unable to unmarshal the message: %v", err)
}
if validator != nil {
if err := validator.Validate(message); err != nil {
return nil, err
}
}
return message, nil
}
6 changes: 4 additions & 2 deletions private/buf/cmd/buf/command/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ func run(
}
fromMessageRef, err := buffetch.NewMessageRefParser(
container.Logger(),
buffetch.MessageRefParserWithDefaultMessageEncoding(buffetch.MessageEncodingBinpb),
buffetch.MessageRefParserWithDefaultMessageEncoding(
buffetch.MessageEncodingBinpb,
),
).GetMessageRef(ctx, flags.From)
if err != nil {
return fmt.Errorf("--%s: %v", fromFlagName, err)
return fmt.Errorf("--%s: %v", outputFlagName, err)
}
storageosProvider := bufcli.NewStorageosProvider(flags.DisableSymlinks)
runner := command.NewRunner()
Expand Down
Loading