diff options
Diffstat (limited to 'weed/filer/s3iam_conf.go')
| -rw-r--r-- | weed/filer/s3iam_conf.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/weed/filer/s3iam_conf.go b/weed/filer/s3iam_conf.go index 6240058a4..24ed46be5 100644 --- a/weed/filer/s3iam_conf.go +++ b/weed/filer/s3iam_conf.go @@ -1,17 +1,16 @@ package filer import ( - "bytes" "fmt" "io" "github.com/seaweedfs/seaweedfs/weed/pb/iam_pb" - "google.golang.org/protobuf/jsonpb" + jsonpb "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" ) func ParseS3ConfigurationFromBytes[T proto.Message](content []byte, config T) error { - if err := jsonpb.Unmarshal(bytes.NewBuffer(content), config); err != nil { + if err := jsonpb.Unmarshal(content, config); err != nil { return err } return nil @@ -19,12 +18,22 @@ func ParseS3ConfigurationFromBytes[T proto.Message](content []byte, config T) er func ProtoToText(writer io.Writer, config proto.Message) error { - m := jsonpb.Marshaler{ - EmitDefaults: false, - Indent: " ", + m := jsonpb.MarshalOptions{ + EmitUnpopulated: true, + Indent: " ", } - return m.Marshal(writer, config) + text, marshalErr := m.Marshal(config) + if marshalErr != nil { + return fmt.Errorf("marshal proto message: %v", marshalErr) + } + + _, writeErr := writer.Write(text) + if writeErr != nil { + return fmt.Errorf("fail to write proto message: %v", writeErr) + } + + return writeErr } // CheckDuplicateAccessKey returns an error message when s3cfg has duplicate access keys |
