Skip to content

Commit

Permalink
Migrate protobuf from v1 to v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
pphaneuf committed Apr 12, 2021
1 parent c5ea3ab commit 76058cc
Show file tree
Hide file tree
Showing 68 changed files with 19,118 additions and 19,080 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 172,8 @@ the original files; if you do, you'll need to install the prerequisites:
```
cd $(go list -f '{{ .Dir }}' github.com/google/trillian); \
go install github.com/golang/mock/mockgen; \
go install github.com/golang/protobuf/proto; \
go install github.com/golang/protobuf/protoc-gen-go; \
go install google.golang.org/protobuf/proto; \
go install google.golang.org/protobuf/protoc-gen-go; \
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc; \
go install golang.org/x/tools/cmd/stringer
```
Expand Down
2 changes: 1 addition & 1 deletion client/log_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 21,11 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian"
rfc6962 "github.com/google/trillian/merkle/rfc6962/hasher"
"github.com/google/trillian/testonly/integration"
"github.com/google/trillian/types"
"google.golang.org/protobuf/proto"

"github.com/google/trillian/storage/testdb"
stestonly "github.com/google/trillian/storage/testonly"
Expand Down
7 changes: 3 additions & 4 deletions cmd/createtree/keys/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 18,7 @@ import (
"fmt"
"strings"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/golang/protobuf/ptypes/any"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

Expand All @@ -41,7 40,7 @@ func RegisterType(protoType string, builder ProtoBuilder) {
// New returns a protobuf message of the specified type that describes a private
// key. A ProtoBuilder must have been registered for this type using
// RegisterType() first.
func New(protoType string) (*any.Any, error) {
func New(protoType string) (*anypb.Any, error) {
buildProto, ok := protoBuilders[protoType]
if !ok {
return nil, fmt.Errorf("key protobuf type must be one of: %s", strings.Join(RegisteredTypes(), ", "))
Expand All @@ -52,7 51,7 @@ func New(protoType string) (*any.Any, error) {
return nil, err
}

return anypb.New(proto.MessageV2(pb))
return anypb.New(pb)
}

// RegisteredTypes returns a list of protobuf message types that have been
Expand Down
11 changes: 5 additions & 6 deletions cmd/createtree/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 21,16 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/golang/protobuf/ptypes/any"
"github.com/golang/protobuf/ptypes/empty"
"github.com/google/trillian"
"github.com/google/trillian/crypto/sigpb"
"github.com/google/trillian/testonly"
"github.com/google/trillian/testonly/flagsaver"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/emptypb"
)

// defaultTree reflects all flag defaults with the addition of a valid private key.
Expand All @@ -41,7 40,7 @@ var defaultTree = &trillian.Tree{
HashStrategy: trillian.HashStrategy_RFC6962_SHA256,
HashAlgorithm: sigpb.DigitallySigned_SHA256,
SignatureAlgorithm: sigpb.DigitallySigned_ECDSA,
PrivateKey: mustMarshalAny(&empty.Empty{}),
PrivateKey: mustMarshalAny(&emptypb.Empty{}),
MaxRootDuration: durationpb.New(0 * time.Millisecond),
}

Expand All @@ -55,8 54,8 @@ type testCase struct {
wantTree *trillian.Tree
}

func mustMarshalAny(p proto.Message) *any.Any {
anyKey, err := anypb.New(proto.MessageV2(p))
func mustMarshalAny(p proto.Message) *anypb.Any {
anyKey, err := anypb.New(p)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/createtree/pem.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 19,11 @@ import (
"flag"
"fmt"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/cmd/createtree/keys"
"github.com/google/trillian/crypto/keys/der"
"github.com/google/trillian/crypto/keys/pem"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/createtree/pem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 18,11 @@ import (
"errors"
"testing"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian"
"github.com/google/trillian/crypto/keys/der"
"github.com/google/trillian/crypto/keys/pem"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"
)

func TestWithPEMKeyFile(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/createtree/pkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 23,9 @@ import (
"fmt"
"io/ioutil"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/cmd/createtree/keys"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"

pkcs11key "github.com/letsencrypt/pkcs11key/v4"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/trillian_log_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 27,6 @@ import (
"time"

"github.com/golang/glog"
"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian"
"github.com/google/trillian/cmd"
"github.com/google/trillian/cmd/internal/serverutil"
Expand All @@ -46,6 45,7 @@ import (
"github.com/google/trillian/util/clock"
clientv3 "go.etcd.io/etcd/client/v3"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

// Register key ProtoHandlers
_ "github.com/google/trillian/crypto/keys/der/proto"
Expand Down
4 changes: 2 additions & 2 deletions cmd/updatetree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 29,13 @@ import (
"time"

"github.com/golang/glog"
"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian"
"github.com/google/trillian/client/rpcflags"
"google.golang.org/genproto/protobuf/field_mask"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
Expand Down Expand Up @@ -133,7 133,7 @@ func main() {
}

if *printTree {
fmt.Println(proto.MarshalTextString(tree))
fmt.Println(prototext.Format(tree))
} else {
// DO NOT change the default output format, some scripts depend on it. If
// you really want to change it, hide the new format behind a flag.
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/der/proto/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 21,10 @@ import (
"crypto"
"fmt"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/crypto/keys"
"github.com/google/trillian/crypto/keys/der"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/der/proto/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 19,10 @@ import (
"encoding/base64"
"testing"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/crypto/keys"
"github.com/google/trillian/crypto/keys/testonly"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"
)

func TestProtoHandler(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 23,9 @@ import (
"crypto/rsa"
"fmt"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/crypto/keyspb"
"golang.org/x/crypto/ed25519"
"google.golang.org/protobuf/proto"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions crypto/keys/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@ import (
"sync"

"github.com/golang/glog"
"github.com/golang/protobuf/proto" //nolint:staticcheck
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
)

Expand All @@ -44,7 44,7 @@ var (
func RegisterHandler(keyProto proto.Message, handler ProtoHandler) {
handlersMu.Lock()
defer handlersMu.Unlock()
keyProtoType := proto.MessageReflect(keyProto).Descriptor().FullName()
keyProtoType := keyProto.ProtoReflect().Descriptor().FullName()

if _, alreadyExists := handlers[keyProtoType]; alreadyExists {
glog.Warningf("Overridding ProtoHandler for protobuf %q", keyProtoType)
Expand All @@ -58,7 58,7 @@ func RegisterHandler(keyProto proto.Message, handler ProtoHandler) {
func UnregisterHandler(keyProto proto.Message) {
handlersMu.Lock()
defer handlersMu.Unlock()
delete(handlers, proto.MessageReflect(keyProto).Descriptor().FullName())
delete(handlers, keyProto.ProtoReflect().Descriptor().FullName())
}

// NewSigner uses a registered ProtoHandler (see RegisterHandler()) to convert a
Expand All @@ -71,7 71,7 @@ func NewSigner(ctx context.Context, keyProto proto.Message) (crypto.Signer, erro
if keyProto == nil {
return nil, fmt.Errorf("nil keyProto")
}
keyProtoType := proto.MessageReflect(keyProto).Descriptor().FullName()
keyProtoType := keyProto.ProtoReflect().Descriptor().FullName()

if handler, ok := handlers[keyProtoType]; ok {
return handler(ctx, keyProto)
Expand Down
10 changes: 5 additions & 5 deletions crypto/keys/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 20,11 @@ import (
"errors"
"testing"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/golang/protobuf/ptypes/empty"
. "github.com/google/trillian/crypto/keys"
"github.com/google/trillian/crypto/keys/pem"
"github.com/google/trillian/testonly"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"
)

func fakeHandler(signer crypto.Signer, err error) ProtoHandler {
Expand All @@ -49,18 49,18 @@ func TestNewSigner(t *testing.T) {
}{
{
desc: "KeyProto with handler",
keyProto: &empty.Empty{},
keyProto: &emptypb.Empty{},
handler: fakeHandler(wantSigner, nil),
},
{
desc: "Invalid KeyProto with handler",
keyProto: &empty.Empty{},
keyProto: &emptypb.Empty{},
handler: fakeHandler(nil, errors.New("invalid KeyProto")),
wantErr: true,
},
{
desc: "KeyProto with no handler",
keyProto: &empty.Empty{},
keyProto: &emptypb.Empty{},
wantErr: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/pem/proto/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 21,10 @@ import (
"crypto"
"fmt"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/crypto/keys"
"github.com/google/trillian/crypto/keys/pem"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/pem/proto/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 18,10 @@ import (
"context"
"testing"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/crypto/keys"
"github.com/google/trillian/crypto/keys/testonly"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"
)

func TestProtoHandler(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/pkcs11/proto/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 22,10 @@ import (
"flag"
"fmt"

"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/trillian/crypto/keys"
"github.com/google/trillian/crypto/keys/pkcs11"
"github.com/google/trillian/crypto/keyspb"
"google.golang.org/protobuf/proto"
)

var modulePath = flag.String("pkcs11_module_path", "", "Path to the PKCS#11 module to use for keys that use the PKCS#11 interface")
Expand Down
2 changes: 1 addition & 1 deletion gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@

package trillian

//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/googleapis/googleapis --go_out=plugins=grpc,paths=source_relative:. trillian_log_api.proto trillian_admin_api.proto trillian.proto --doc_out=markdown,api.md:./docs/
//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/googleapis/googleapis --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. --go-grpc_opt=require_unimplemented_servers=false trillian_log_api.proto trillian_admin_api.proto trillian.proto --doc_out=markdown,api.md:./docs/
//go:generate protoc -I=. --go_out=paths=source_relative:. crypto/sigpb/sigpb.proto
//go:generate protoc -I=. --go_out=paths=source_relative:. crypto/keyspb/keyspb.proto

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 44,6 @@ require (
google.golang.org/api v0.43.0
google.golang.org/genproto v0.0.0-20210331142528-b7513248f0ba
google.golang.org/grpc v1.36.1
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
google.golang.org/protobuf v1.26.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 1126,8 @@ google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe dy9BAG
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe dy9BAGRRjU=
google.golang.org/grpc v1.36.1 h1:cmUfbeGKnz9 2DD/UYsMQXeqbHZqZDs4eQwW0sFOpBY=
google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe dy9BAGRRjU=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6 Kah6886xMZcty6N08ah7 eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
2 changes: 1 addition & 1 deletion integration/admin/admin_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,6 @@ import (
"time"

"github.com/golang/glog"
"github.com/golang/protobuf/proto" //nolint:staticcheck
"github.com/google/go-cmp/cmp"
"github.com/google/trillian"
"github.com/google/trillian/server/interceptor"
Expand All @@ -34,6 33,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

sa "github.com/google/trillian/server/admin"
Expand Down
5 changes: 3 additions & 2 deletions integration/cloudbuild/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 18,9 @@ git clone --depth=1 https://github.com/googleapis/googleapis.git "$GOPATH/src/gi
# commit the generated files in an up-to-date state.
go install \
github.com/golang/mock/mockgen \
github.com/golang/protobuf/proto \
github.com/golang/protobuf/protoc-gen-go \
google.golang.org/protobuf/proto \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc \
golang.org/x/tools/cmd/goimports \
golang.org/x/tools/cmd/stringer
Loading

0 comments on commit 76058cc

Please sign in to comment.