Commit 50986a7b authored by Alberto Bertogli's avatar Alberto Bertogli

Update protobuf library to v2

There is a new protobuf library (and corresponding code generator) for
Go: google.golang.org/protobuf.

It is fairly compatible with the previous v1 API
(github.com/golang/protobuf), but there are some changes.

This patch adjusts the code and generated files to the new API.

The on-wire/on-disk format remains unchanged so this should be
transparent to the users.
parent 5ec567b2
Pipeline #146657604 passed with stages
in 8 minutes and 44 seconds
......@@ -20,9 +20,9 @@ import (
"blitiri.com.ar/go/chasquid/internal/envelope"
"blitiri.com.ar/go/chasquid/internal/normalize"
"blitiri.com.ar/go/chasquid/internal/userdb"
"google.golang.org/protobuf/encoding/prototext"
"github.com/docopt/docopt-go"
"github.com/golang/protobuf/proto"
"golang.org/x/crypto/ssh/terminal"
)
......@@ -253,7 +253,7 @@ func printConfig() {
Fatalf("Error reading config")
}
fmt.Println(proto.MarshalTextString(conf))
fmt.Println(prototext.Format(conf))
}
// chasquid-util domaininfo-remove <domain>
......
......@@ -74,7 +74,7 @@ if [ "$A" != "(email) [email protected]" ]; then
fi
C=$(r print-config | grep hostname)
if [ "$C" != "hostname: \"$HOSTNAME\"" ]; then
if ! ( echo "$C" | grep -E -q "hostname:.*\"$HOSTNAME\"" ); then
echo print-config failed
echo output: "$C"
exit 1
......
......@@ -7,9 +7,10 @@ require (
blitiri.com.ar/go/spf v0.0.0-20191018194539-a683815bdae8
blitiri.com.ar/go/systemd v0.0.0-20171003041308-cdc4fd023aa4
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/golang/protobuf v1.3.5
github.com/golang/protobuf v1.4.0
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/text v0.3.2
google.golang.org/protobuf v1.23.0
gopkg.in/yaml.v2 v2.2.4 // indirect
)
......@@ -6,8 +6,16 @@ blitiri.com.ar/go/systemd v0.0.0-20171003041308-cdc4fd023aa4 h1:ceTBe2TiHNkhA7q/
blitiri.com.ar/go/systemd v0.0.0-20171003041308-cdc4fd023aa4/go.mod h1:FmDkVlYnOzDHOhtSwtLHh6z9WVVx+aPjrHkPtfA3qhI=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
......@@ -24,6 +32,15 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
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=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
......
......@@ -2,7 +2,7 @@
package config
// Generate the config protobuf.
//go:generate protoc --go_out=. config.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative config.proto
import (
"io/ioutil"
......@@ -10,7 +10,7 @@ import (
"blitiri.com.ar/go/log"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/encoding/prototext"
)
// Load the config from the given file.
......@@ -24,7 +24,7 @@ func Load(path string) (*Config, error) {
return nil, err
}
err = proto.UnmarshalText(string(buf), c)
err = prototext.Unmarshal(buf, c)
if err != nil {
log.Errorf("Error parsing config: %v", err)
return nil, err
......
This diff is collapsed.
syntax = "proto3";
option go_package = "blitiri.com.ar/go/chasquid/internal/config";
message Config {
// Default hostname to use when saying hello.
......
......@@ -11,7 +11,7 @@ import (
)
// Command to generate domaininfo.pb.go.
//go:generate protoc --go_out=. domaininfo.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative domaininfo.proto
// DB represents the persistent domain information database.
type DB struct {
......
This diff is collapsed.
......@@ -2,6 +2,7 @@
syntax = "proto3";
package domaininfo;
option go_package = "blitiri.com.ar/go/chasquid/internal/domaininfo";
enum SecLevel {
// Does not do TLS.
......
package testpb
//go:generate protoc --go_out=. testpb.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative testpb.proto
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.23.0
// protoc v3.11.4
// source: testpb.proto
package testpb
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type M struct {
Content string `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
func (m *M) Reset() { *m = M{} }
func (m *M) String() string { return proto.CompactTextString(m) }
func (*M) ProtoMessage() {}
func (*M) Descriptor() ([]byte, []int) {
return fileDescriptor_1b98c0ed33edeb52, []int{0}
Content string `protobuf:"bytes,1,opt,name=content,proto3" json:"content,omitempty"`
}
func (m *M) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_M.Unmarshal(m, b)
}
func (m *M) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_M.Marshal(b, m, deterministic)
}
func (m *M) XXX_Merge(src proto.Message) {
xxx_messageInfo_M.Merge(m, src)
func (x *M) Reset() {
*x = M{}
if protoimpl.UnsafeEnabled {
mi := &file_testpb_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (m *M) XXX_Size() int {
return xxx_messageInfo_M.Size(m)
func (x *M) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (m *M) XXX_DiscardUnknown() {
xxx_messageInfo_M.DiscardUnknown(m)
func (*M) ProtoMessage() {}
func (x *M) ProtoReflect() protoreflect.Message {
mi := &file_testpb_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
var xxx_messageInfo_M proto.InternalMessageInfo
// Deprecated: Use M.ProtoReflect.Descriptor instead.
func (*M) Descriptor() ([]byte, []int) {
return file_testpb_proto_rawDescGZIP(), []int{0}
}
func (m *M) GetContent() string {
if m != nil {
return m.Content
func (x *M) GetContent() string {
if x != nil {
return x.Content
}
return ""
}
func init() {
proto.RegisterType((*M)(nil), "testpb.M")
var File_testpb_proto protoreflect.FileDescriptor
var file_testpb_proto_rawDesc = []byte{
0x0a, 0x0c, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06,
0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x22, 0x1d, 0x0a, 0x01, 0x4d, 0x12, 0x18, 0x0a, 0x07, 0x63,
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f,
0x6e, 0x74, 0x65, 0x6e, 0x74, 0x42, 0x34, 0x5a, 0x32, 0x62, 0x6c, 0x69, 0x74, 0x69, 0x72, 0x69,
0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x2f, 0x67, 0x6f, 0x2f, 0x63, 0x68, 0x61, 0x73, 0x71,
0x75, 0x69, 0x64, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x69, 0x6f, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
}
var (
file_testpb_proto_rawDescOnce sync.Once
file_testpb_proto_rawDescData = file_testpb_proto_rawDesc
)
func file_testpb_proto_rawDescGZIP() []byte {
file_testpb_proto_rawDescOnce.Do(func() {
file_testpb_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_proto_rawDescData)
})
return file_testpb_proto_rawDescData
}
func init() { proto.RegisterFile("testpb.proto", fileDescriptor_1b98c0ed33edeb52) }
var file_testpb_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_testpb_proto_goTypes = []interface{}{
(*M)(nil), // 0: testpb.M
}
var file_testpb_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
var fileDescriptor_1b98c0ed33edeb52 = []byte{
// 72 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x49, 0x2d, 0x2e,
0x29, 0x48, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x64, 0xb9, 0x18,
0x7d, 0x85, 0x24, 0xb8, 0xd8, 0x93, 0xf3, 0xf3, 0x4a, 0x52, 0xf3, 0x4a, 0x24, 0x18, 0x15, 0x18,
0x35, 0x38, 0x83, 0x60, 0xdc, 0x24, 0x36, 0xb0, 0x6a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff,
0xcb, 0x37, 0x9b, 0x8f, 0x3d, 0x00, 0x00, 0x00,
func init() { file_testpb_proto_init() }
func file_testpb_proto_init() {
if File_testpb_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_testpb_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*M); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_testpb_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_testpb_proto_goTypes,
DependencyIndexes: file_testpb_proto_depIdxs,
MessageInfos: file_testpb_proto_msgTypes,
}.Build()
File_testpb_proto = out.File
file_testpb_proto_rawDesc = nil
file_testpb_proto_goTypes = nil
file_testpb_proto_depIdxs = nil
}
......@@ -2,6 +2,7 @@
syntax = "proto3";
package testpb;
option go_package = "blitiri.com.ar/go/chasquid/internal/protoio/testpb";
message M {
string content = 1;
......
......@@ -3,7 +3,7 @@
package queue
// Command to generate queue.pb.go from queue.proto.
//go:generate protoc --go_out=. -I=${GOPATH}/src -I. queue.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative -I=${GOPATH}/src -I. queue.proto
import (
"context"
......@@ -29,8 +29,8 @@ import (
"blitiri.com.ar/go/chasquid/internal/trace"
"blitiri.com.ar/go/log"
"github.com/golang/protobuf/ptypes"
"golang.org/x/net/idna"
"google.golang.org/protobuf/types/known/timestamppb"
)
const (
......@@ -276,8 +276,8 @@ func ItemFromFile(fname string) (*Item, error) {
return nil, err
}
item.CreatedAt, err = ptypes.Timestamp(item.CreatedAtTs)
return item, err
item.CreatedAt = timeFromProto(item.CreatedAtTs)
return item, nil
}
// WriteTo saves an item to the given directory.
......@@ -286,11 +286,7 @@ func (item *Item) WriteTo(dir string) error {
defer item.Unlock()
itemsWritten.Add(1)
var err error
item.CreatedAtTs, err = ptypes.TimestampProto(item.CreatedAt)
if err != nil {
return err
}
item.CreatedAtTs = timeToProto(item.CreatedAt)
path := fmt.Sprintf("%s/%s%s", dir, itemFilePrefix, item.ID)
......@@ -490,3 +486,14 @@ func mustIDNAToASCII(s string) string {
}
return s
}
func timeFromProto(ts *timestamppb.Timestamp) time.Time {
return time.Unix(ts.Seconds, int64(ts.Nanos)).UTC()
}
func timeToProto(t time.Time) *timestamppb.Timestamp {
return &timestamppb.Timestamp{
Seconds: t.Unix(),
Nanos: int32(t.Nanosecond()),
}
}
This diff is collapsed.
......@@ -2,6 +2,7 @@
syntax = "proto3";
package queue;
option go_package = "blitiri.com.ar/go/chasquid/internal/queue";
import "github.com/golang/protobuf/ptypes/timestamp/timestamp.proto";
......
......@@ -30,7 +30,7 @@
//
package userdb
//go:generate protoc --go_out=. userdb.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative userdb.proto
import (
"crypto/rand"
......
This diff is collapsed.
......@@ -2,6 +2,7 @@
syntax = "proto3";
package userdb;
option go_package = "blitiri.com.ar/go/chasquid/internal/userdb";
message ProtoDB {
map<string, Password> users = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment