fix(import): import json marshal to jsonpb (#4580)

* fix(import): import json marshal to jsonpb

* fix: add unmarshaloptions discard unknown

Co-authored-by: Livio Spring <livio.a@gmail.com>

* fix(import): import json marshal to jsonpb

Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
Stefan Benz 2022-10-19 14:36:51 +01:00 committed by GitHub
parent d2eb0b0d2a
commit 2bfa51da1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,16 +3,17 @@ package admin
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"strconv"
"time"
"cloud.google.com/go/storage"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"google.golang.org/api/option"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/durationpb"
"github.com/zitadel/logging"
@ -229,9 +230,14 @@ func (s *Server) transportDataFromFile(ctx context.Context, v1Transformation boo
data = localData
}
jsonpb := &runtime.JSONPb{
UnmarshalOptions: protojson.UnmarshalOptions{
DiscardUnknown: true,
},
}
if v1Transformation {
dataImportV1 := new(v1_pb.ImportDataOrg)
if err := json.Unmarshal(data, dataImportV1); err != nil {
if err := jsonpb.Unmarshal(data, dataImportV1); err != nil {
return nil, err
}
@ -242,7 +248,7 @@ func (s *Server) transportDataFromFile(ctx context.Context, v1Transformation boo
dataOrgs = dataImport.Orgs
} else {
dataImport := new(admin_pb.ImportDataOrg)
if err := json.Unmarshal(data, dataImport); err != nil {
if err := jsonpb.Unmarshal(data, dataImport); err != nil {
return nil, err
}
dataOrgs = dataImport.Orgs