Merge pull request #12639 from hashicorp/gogo-away

Remove the Rest of Gogo
This commit is contained in:
Eric Haberkorn 2022-03-29 10:14:44 -04:00 committed by GitHub
commit e5ed4fe493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 110 additions and 3916 deletions

View File

@ -235,13 +235,12 @@ jobs:
sudo chmod -R a+Xr /usr/local/include/google/
rm protoc-*.zip
- run:
name: Install gogo/protobuf
name: Install protobuf
command: |
gogo_version=$(go list -m github.com/gogo/protobuf | awk '{print $2}')
goproto_version=$(go list -m github.com/golang/protobuf | awk '{print $2}')
go install -v github.com/hashicorp/protoc-gen-go-binary@master
go install -v github.com/gogo/protobuf/protoc-gen-gofast@${gogo_version}
go install -v github.com/favadi/protoc-go-inject-tag@v1.3.0
go install -v github.com/golang/protobuf/protoc-gen-go@v1.3.5
go install -v github.com/golang/protobuf/protoc-gen-go@${goproto_version}
- run:
command: make --always-make proto

View File

@ -2,13 +2,13 @@
# https://www.consul.io/docs/install#compiling-from-source
SHELL = bash
GOGOVERSION?=$(shell grep github.com/gogo/protobuf go.mod | awk '{print $$2}')
GOPROTOVERSION?=$(shell grep github.com/golang/protobuf go.mod | awk '{print $$2}')
GOTOOLS = \
github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs@master \
github.com/hashicorp/go-bindata/go-bindata@master \
golang.org/x/tools/cmd/cover@master \
golang.org/x/tools/cmd/stringer@master \
github.com/gogo/protobuf/protoc-gen-gofast@$(GOGOVERSION) \
github.com/golang/protobuf/protoc-gen-go@$(GOPROTOVERSION) \
github.com/hashicorp/protoc-gen-go-binary@master \
github.com/vektra/mockery/cmd/mockery@master \
github.com/golangci/golangci-lint/cmd/golangci-lint@v1.40.1 \
@ -347,7 +347,7 @@ proto: $(PROTOGOFILES) $(PROTOGOBINFILES)
%.pb.go %.pb.binary.go: %.proto
@$(SHELL) $(CURDIR)/build-support/scripts/proto-gen-entry.sh --grpc --import-replace "$<"
@$(SHELL) $(CURDIR)/build-support/scripts/proto-gen.sh --grpc --import-replace "$<"
.PHONY: module-versions
# Print a list of modules which can be updated.

View File

@ -1,4 +1,4 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: agent/grpc/private/internal/testservice/simple.proto
package testservice
@ -10,9 +10,7 @@ import (
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
@ -39,26 +37,18 @@ func (*Req) ProtoMessage() {}
func (*Req) Descriptor() ([]byte, []int) {
return fileDescriptor_98af0751f806f450, []int{0}
}
func (m *Req) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
return xxx_messageInfo_Req.Unmarshal(m, b)
}
func (m *Req) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Req.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
return xxx_messageInfo_Req.Marshal(b, m, deterministic)
}
func (m *Req) XXX_Merge(src proto.Message) {
xxx_messageInfo_Req.Merge(m, src)
}
func (m *Req) XXX_Size() int {
return m.Size()
return xxx_messageInfo_Req.Size(m)
}
func (m *Req) XXX_DiscardUnknown() {
xxx_messageInfo_Req.DiscardUnknown(m)
@ -87,26 +77,18 @@ func (*Resp) ProtoMessage() {}
func (*Resp) Descriptor() ([]byte, []int) {
return fileDescriptor_98af0751f806f450, []int{1}
}
func (m *Resp) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
return xxx_messageInfo_Resp.Unmarshal(m, b)
}
func (m *Resp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Resp.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
return xxx_messageInfo_Resp.Marshal(b, m, deterministic)
}
func (m *Resp) XXX_Merge(src proto.Message) {
xxx_messageInfo_Resp.Merge(m, src)
}
func (m *Resp) XXX_Size() int {
return m.Size()
return xxx_messageInfo_Resp.Size(m)
}
func (m *Resp) XXX_DiscardUnknown() {
xxx_messageInfo_Resp.DiscardUnknown(m)
@ -138,30 +120,28 @@ func init() {
}
var fileDescriptor_98af0751f806f450 = []byte{
// 214 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x49, 0x4c, 0x4f, 0xcd,
0x2b, 0xd1, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2c, 0x4b, 0x2c, 0x49, 0xd5, 0xcf,
0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0x2f, 0x49, 0x2d, 0x2e, 0x29, 0x4e, 0x2d, 0x2a,
0xcb, 0x4c, 0x4e, 0xd5, 0x2f, 0xce, 0xcc, 0x2d, 0xc8, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9,
0x17, 0xe2, 0x46, 0x92, 0x51, 0x52, 0xe5, 0x62, 0x0e, 0x4a, 0x2d, 0x14, 0x92, 0xe3, 0xe2, 0x72,
0x49, 0x2c, 0x49, 0x4c, 0x4e, 0x05, 0xe9, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x12,
0x51, 0x72, 0xe3, 0x62, 0x09, 0x4a, 0x2d, 0x2e, 0x00, 0xa9, 0x0b, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d,
0xf2, 0x4b, 0xcc, 0x4d, 0x85, 0xa9, 0x43, 0x88, 0xa0, 0x99, 0xc3, 0x84, 0x6e, 0x8e, 0x51, 0x2e,
0x17, 0x5b, 0x30, 0xd8, 0x2d, 0x42, 0x46, 0x5c, 0x9c, 0xc1, 0xf9, 0xb9, 0xa9, 0x25, 0x19, 0x99,
0x79, 0xe9, 0x42, 0x02, 0x7a, 0x48, 0x6e, 0xd2, 0x0b, 0x4a, 0x2d, 0x94, 0x12, 0x44, 0x13, 0x29,
0x2e, 0x50, 0x62, 0x10, 0xd2, 0xe7, 0x62, 0x71, 0xcb, 0xc9, 0x2f, 0x27, 0x52, 0xb9, 0x01, 0xa3,
0x93, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe3,
0xb1, 0x1c, 0x43, 0x12, 0x1b, 0x38, 0x0c, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x76, 0xce,
0x88, 0x7d, 0x3b, 0x01, 0x00, 0x00,
// 189 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x8f, 0xcd, 0x0a, 0x82, 0x40,
0x14, 0x85, 0xb3, 0x44, 0xf0, 0xb6, 0xa9, 0x59, 0x45, 0x8b, 0x08, 0x21, 0x68, 0xe5, 0x84, 0xf5,
0x08, 0xe1, 0xb2, 0xc5, 0xf8, 0x04, 0x93, 0x5c, 0x6c, 0xc0, 0xf9, 0x71, 0xe6, 0x62, 0xaf, 0x1f,
0x0a, 0x91, 0xb8, 0x6a, 0xfb, 0xdd, 0xef, 0x1e, 0xce, 0x81, 0x9b, 0x6c, 0xd0, 0x10, 0x6f, 0xbc,
0xab, 0xb9, 0xf3, 0xaa, 0x97, 0x84, 0x5c, 0x19, 0x42, 0x6f, 0x64, 0xcb, 0x09, 0x03, 0x05, 0xf4,
0xbd, 0xaa, 0x91, 0x07, 0xa5, 0x5d, 0x8b, 0xb9, 0xf3, 0x96, 0x2c, 0x5b, 0x4f, 0x2e, 0xd9, 0x09,
0x56, 0x02, 0x3b, 0x76, 0x00, 0xb8, 0x4b, 0x92, 0x35, 0x0e, 0xdf, 0xbb, 0xe8, 0x18, 0x9d, 0x53,
0x31, 0x21, 0x59, 0x09, 0xb1, 0xc0, 0xe0, 0x06, 0xaf, 0x42, 0xdf, 0xa3, 0x7f, 0x48, 0x8d, 0x5f,
0xef, 0x47, 0x66, 0x39, 0xcb, 0x79, 0x4e, 0xa1, 0x21, 0xa9, 0xc6, 0x2e, 0xac, 0x80, 0xb4, 0xb2,
0x1a, 0xe9, 0xa5, 0x4c, 0xc3, 0x36, 0xf9, 0xa4, 0x53, 0x2e, 0xb0, 0xdb, 0x6f, 0x67, 0x24, 0xb8,
0x6c, 0xc1, 0x38, 0xc4, 0x65, 0x6b, 0xdf, 0x7f, 0xea, 0x97, 0xe8, 0x99, 0x8c, 0x8b, 0xaf, 0x9f,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x5c, 0xf5, 0xcb, 0x29, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
const _ = grpc.SupportPackageIsVersion6
// SimpleClient is the client API for Simple service.
//
@ -172,10 +152,10 @@ type SimpleClient interface {
}
type simpleClient struct {
cc *grpc.ClientConn
cc grpc.ClientConnInterface
}
func NewSimpleClient(cc *grpc.ClientConn) SimpleClient {
func NewSimpleClient(cc grpc.ClientConnInterface) SimpleClient {
return &simpleClient{cc}
}
@ -298,414 +278,3 @@ var _Simple_serviceDesc = grpc.ServiceDesc{
},
Metadata: "agent/grpc/private/internal/testservice/simple.proto",
}
func (m *Req) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Req) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Req) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Datacenter) > 0 {
i -= len(m.Datacenter)
copy(dAtA[i:], m.Datacenter)
i = encodeVarintSimple(dAtA, i, uint64(len(m.Datacenter)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *Resp) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Resp) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Resp) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Datacenter) > 0 {
i -= len(m.Datacenter)
copy(dAtA[i:], m.Datacenter)
i = encodeVarintSimple(dAtA, i, uint64(len(m.Datacenter)))
i--
dAtA[i] = 0x12
}
if len(m.ServerName) > 0 {
i -= len(m.ServerName)
copy(dAtA[i:], m.ServerName)
i = encodeVarintSimple(dAtA, i, uint64(len(m.ServerName)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintSimple(dAtA []byte, offset int, v uint64) int {
offset -= sovSimple(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *Req) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Datacenter)
if l > 0 {
n += 1 + l + sovSimple(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *Resp) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.ServerName)
if l > 0 {
n += 1 + l + sovSimple(uint64(l))
}
l = len(m.Datacenter)
if l > 0 {
n += 1 + l + sovSimple(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovSimple(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozSimple(x uint64) (n int) {
return sovSimple(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *Req) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSimple
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Req: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Req: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Datacenter", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSimple
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthSimple
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthSimple
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Datacenter = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipSimple(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthSimple
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *Resp) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSimple
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Resp: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Resp: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ServerName", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSimple
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthSimple
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthSimple
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ServerName = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Datacenter", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowSimple
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthSimple
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthSimple
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Datacenter = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipSimple(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthSimple
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipSimple(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowSimple
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowSimple
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowSimple
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthSimple
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupSimple
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthSimple
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthSimple = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowSimple = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupSimple = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -26,7 +26,6 @@ import (
grpc "github.com/hashicorp/consul/agent/grpc/private"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/proto/pbcommongogo"
"github.com/hashicorp/consul/proto/pbservice"
"github.com/hashicorp/consul/proto/pbsubscribe"
"github.com/hashicorp/consul/types"
@ -124,7 +123,7 @@ func TestServer_Subscribe_IntegrationWithBackend(t *testing.T) {
streamHandle, err := streamClient.Subscribe(ctx, &pbsubscribe.SubscribeRequest{
Topic: pbsubscribe.Topic_ServiceHealth,
Key: "redis",
Namespace: pbcommongogo.DefaultEnterpriseMeta.Namespace,
Namespace: pbcommon.DefaultEnterpriseMeta.Namespace,
})
require.NoError(t, err)
@ -489,7 +488,7 @@ func TestServer_Subscribe_IntegrationWithBackend_ForwardToDC(t *testing.T) {
Topic: pbsubscribe.Topic_ServiceHealth,
Key: "redis",
Datacenter: "dc2",
Namespace: pbcommongogo.DefaultEnterpriseMeta.Namespace,
Namespace: pbcommon.DefaultEnterpriseMeta.Namespace,
})
require.NoError(t, err)
go recvEvents(chEvents, streamHandle)
@ -746,7 +745,7 @@ node "node1" {
Topic: pbsubscribe.Topic_ServiceHealth,
Key: "foo",
Token: token,
Namespace: pbcommongogo.DefaultEnterpriseMeta.Namespace,
Namespace: pbcommon.DefaultEnterpriseMeta.Namespace,
})
require.NoError(t, err)

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/hashicorp/consul/proto/pbcommon"
"strings"
"testing"
"time"
@ -18,7 +17,7 @@ import (
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/submatview"
"github.com/hashicorp/consul/proto/pbcommongogo"
"github.com/hashicorp/consul/proto/pbcommon"
"github.com/hashicorp/consul/proto/pbservice"
"github.com/hashicorp/consul/proto/pbsubscribe"
"github.com/hashicorp/consul/types"
@ -75,7 +74,7 @@ func TestHealthView_IntegrationWithStore_WithEmptySnapshot(t *testing.T) {
t.Skip("too slow for testing.Short")
}
namespace := getNamespace(pbcommongogo.DefaultEnterpriseMeta.Namespace)
namespace := getNamespace(pbcommon.DefaultEnterpriseMeta.Namespace)
streamClient := newStreamClient(validateNamespace(namespace))
ctx, cancel := context.WithCancel(context.Background())

View File

@ -5,7 +5,6 @@ import (
)
// GetToken helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetToken() string {
if m != nil {
return m.Token
@ -14,7 +13,6 @@ func (m *QueryOptions) GetToken() string {
}
// GetMinQueryIndex helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetMinQueryIndex() uint64 {
if m != nil {
return m.MinQueryIndex
@ -23,7 +21,6 @@ func (m *QueryOptions) GetMinQueryIndex() uint64 {
}
// GetMaxQueryTime helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetMaxQueryTime() (time.Duration, error) {
if m != nil {
return m.MaxQueryTime, nil
@ -32,7 +29,6 @@ func (m *QueryOptions) GetMaxQueryTime() (time.Duration, error) {
}
// GetAllowStale helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetAllowStale() bool {
if m != nil {
return m.AllowStale
@ -41,7 +37,6 @@ func (m *QueryOptions) GetAllowStale() bool {
}
// GetRequireConsistent helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetRequireConsistent() bool {
if m != nil {
return m.RequireConsistent
@ -50,7 +45,6 @@ func (m *QueryOptions) GetRequireConsistent() bool {
}
// GetUseCache helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetUseCache() bool {
if m != nil {
return m.UseCache
@ -59,7 +53,6 @@ func (m *QueryOptions) GetUseCache() bool {
}
// GetMaxStaleDuration helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetMaxStaleDuration() (time.Duration, error) {
if m != nil {
return m.MaxStaleDuration, nil
@ -68,7 +61,6 @@ func (m *QueryOptions) GetMaxStaleDuration() (time.Duration, error) {
}
// GetMaxAge helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetMaxAge() (time.Duration, error) {
if m != nil {
return m.MaxAge, nil
@ -77,7 +69,6 @@ func (m *QueryOptions) GetMaxAge() (time.Duration, error) {
}
// GetMustRevalidate helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetMustRevalidate() bool {
if m != nil {
return m.MustRevalidate
@ -86,7 +77,6 @@ func (m *QueryOptions) GetMustRevalidate() bool {
}
// GetStaleIfError helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetStaleIfError() (time.Duration, error) {
if m != nil {
return m.StaleIfError, nil
@ -95,7 +85,6 @@ func (m *QueryOptions) GetStaleIfError() (time.Duration, error) {
}
// GetFilter helps implement the QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryOptions) GetFilter() string {
if m != nil {
return m.Filter
@ -104,67 +93,56 @@ func (m *QueryOptions) GetFilter() string {
}
// SetToken is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetToken(token string) {
q.Token = token
}
// SetMinQueryIndex is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetMinQueryIndex(minQueryIndex uint64) {
q.MinQueryIndex = minQueryIndex
}
// SetMaxQueryTime is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetMaxQueryTime(maxQueryTime time.Duration) {
q.MaxQueryTime = maxQueryTime
}
// SetAllowStale is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetAllowStale(allowStale bool) {
q.AllowStale = allowStale
}
// SetRequireConsistent is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetRequireConsistent(requireConsistent bool) {
q.RequireConsistent = requireConsistent
}
// SetUseCache is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetUseCache(useCache bool) {
q.UseCache = useCache
}
// SetMaxStaleDuration is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetMaxStaleDuration(maxStaleDuration time.Duration) {
q.MaxStaleDuration = maxStaleDuration
}
// SetMaxAge is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetMaxAge(maxAge time.Duration) {
q.MaxAge = maxAge
}
// SetMustRevalidate is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetMustRevalidate(mustRevalidate bool) {
q.MustRevalidate = mustRevalidate
}
// SetStaleIfError is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetStaleIfError(staleIfError time.Duration) {
q.StaleIfError = staleIfError
}
// SetFilter is needed to implement the structs.QueryOptionsCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryOptions) SetFilter(filter string) {
q.Filter = filter
}
@ -178,7 +156,6 @@ func (m *QueryMeta) GetIndex() uint64 {
}
// GetLastContact helps implement the QueryMetaCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryMeta) GetLastContact() (time.Duration, error) {
if m != nil {
return m.LastContact, nil
@ -187,7 +164,6 @@ func (m *QueryMeta) GetLastContact() (time.Duration, error) {
}
// GetKnownLeader helps implement the QueryMetaCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryMeta) GetKnownLeader() bool {
if m != nil {
return m.KnownLeader
@ -196,7 +172,6 @@ func (m *QueryMeta) GetKnownLeader() bool {
}
// GetConsistencyLevel helps implement the QueryMetaCompat interface
// Copied from proto/pbcommongogo/common.pb.go
func (m *QueryMeta) GetConsistencyLevel() string {
if m != nil {
return m.ConsistencyLevel
@ -205,25 +180,21 @@ func (m *QueryMeta) GetConsistencyLevel() string {
}
// SetLastContact is needed to implement the structs.QueryMetaCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryMeta) SetLastContact(lastContact time.Duration) {
q.LastContact = lastContact
}
// SetKnownLeader is needed to implement the structs.QueryMetaCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryMeta) SetKnownLeader(knownLeader bool) {
q.KnownLeader = knownLeader
}
// SetIndex is needed to implement the structs.QueryMetaCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryMeta) SetIndex(index uint64) {
q.Index = index
}
// SetConsistencyLevel is needed to implement the structs.QueryMetaCompat interface
// Copied from proto/pbcommongogo/common.go
func (q *QueryMeta) SetConsistencyLevel(consistencyLevel string) {
q.ConsistencyLevel = consistencyLevel
}

View File

@ -22,7 +22,6 @@ import (
"github.com/hashicorp/serf/coordinate"
"github.com/mitchellh/hashstructure"
gtype "github.com/gogo/protobuf/types"
ptypes "github.com/golang/protobuf/ptypes"
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/cache"
@ -2686,25 +2685,6 @@ func (m MessageType) String() string {
}
func DurationToProtoGogo(d time.Duration) gtype.Duration {
return *gtype.DurationProto(d)
}
func DurationFromProtoGogo(d gtype.Duration) time.Duration {
duration, _ := gtype.DurationFromProto(&d)
return duration
}
func TimeFromProtoGogo(s *gtype.Timestamp) time.Time {
time, _ := gtype.TimestampFromProto(s)
return time
}
func TimeToProtoGogo(s time.Time) *gtype.Timestamp {
proto, _ := gtype.TimestampProto(s)
return proto
}
func DurationToProto(d time.Duration) *duration.Duration {
return ptypes.DurationProto(d)
}

View File

@ -11,7 +11,7 @@ import (
"github.com/hashicorp/consul/agent/cache"
"github.com/hashicorp/consul/lib/ttlcache"
"github.com/hashicorp/consul/proto/pbcommongogo"
"github.com/hashicorp/consul/proto/pbcommon"
"github.com/hashicorp/consul/proto/pbservice"
"github.com/hashicorp/consul/proto/pbsubscribe"
"github.com/hashicorp/consul/sdk/testutil/retry"
@ -25,7 +25,7 @@ func TestStore_Get(t *testing.T) {
go store.Run(ctx)
req := &fakeRequest{
client: NewTestStreamingClient(pbcommongogo.DefaultEnterpriseMeta.Namespace),
client: NewTestStreamingClient(pbcommon.DefaultEnterpriseMeta.Namespace),
}
req.client.QueueEvents(
newEndOfSnapshotEvent(2),
@ -232,7 +232,7 @@ func (r *fakeRequest) NewMaterializer() (*Materializer, error) {
Token: "abcd",
Datacenter: "dc1",
Index: index,
Namespace: pbcommongogo.DefaultEnterpriseMeta.Namespace,
Namespace: pbcommon.DefaultEnterpriseMeta.Namespace,
}
return req
},
@ -292,7 +292,7 @@ func TestStore_Notify(t *testing.T) {
go store.Run(ctx)
req := &fakeRequest{
client: NewTestStreamingClient(pbcommongogo.DefaultEnterpriseMeta.Namespace),
client: NewTestStreamingClient(pbcommon.DefaultEnterpriseMeta.Namespace),
}
req.client.QueueEvents(
newEndOfSnapshotEvent(2),
@ -361,7 +361,7 @@ func TestStore_Notify_ManyRequests(t *testing.T) {
go store.Run(ctx)
req := &fakeRequest{
client: NewTestStreamingClient(pbcommongogo.DefaultEnterpriseMeta.Namespace),
client: NewTestStreamingClient(pbcommon.DefaultEnterpriseMeta.Namespace),
}
req.client.QueueEvents(newEndOfSnapshotEvent(2))
@ -473,7 +473,7 @@ func TestStore_Run_ExpiresEntries(t *testing.T) {
go store.Run(ctx)
req := &fakeRequest{
client: NewTestStreamingClient(pbcommongogo.DefaultEnterpriseMeta.Namespace),
client: NewTestStreamingClient(pbcommon.DefaultEnterpriseMeta.Namespace),
}
req.client.QueueEvents(newEndOfSnapshotEvent(2))

View File

@ -1,26 +0,0 @@
#!/usr/bin/env bash
FILENAME=$3
echo $PWD
if [[ "$FILENAME" =~ .*pbcommon/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
elif [[ "$FILENAME" =~ .*pbconnect/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
elif [[ "$FILENAME" =~ .*pbconfig/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
elif [[ "$FILENAME" =~ .*pbautoconf/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
elif [[ "$FILENAME" =~ .*pbservice/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
elif [[ "$FILENAME" =~ .*pbsubscribe/.* ]]; then
echo "$FILENAME no gogo"
./build-support/scripts/proto-gen-no-gogo.sh $1 $2 $3
else
echo "$FILENAME gogo"
./build-support/scripts/proto-gen.sh $1 $2 $3
fi

View File

@ -1,169 +0,0 @@
#!/usr/bin/env bash
SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})"
pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null
SCRIPT_DIR=$(pwd)
pushd ../.. > /dev/null
SOURCE_DIR=$(pwd)
popd > /dev/null
pushd ../functions > /dev/null
FN_DIR=$(pwd)
popd > /dev/null
popd > /dev/null
source "${SCRIPT_DIR}/functions.sh"
function usage {
cat <<-EOF
Usage: ${SCRIPT_NAME} [<options ...>] <proto filepath>
Description:
Generate the Go files from protobuf definitions. In addition to
running the protoc generator it will also fixup build tags in the
generated code.
Options:
--import-replace Replace imports of google types with those from the protobuf repo.
--grpc Enable the gRPC plugin
-h | --help Print this help text.
EOF
}
function err_usage {
err "$1"
err ""
err "$(usage)"
}
function main {
local -i grpc=0
local -i imp_replace=0
local proto_path=
while test $# -gt 0
do
case "$1" in
-h | --help )
usage
return 0
;;
--grpc )
grpc=1
shift
;;
--import-replace )
imp_replace=1
shift
;;
* )
proto_path="$1"
shift
;;
esac
done
if test -z "${proto_path}"
then
err_usage "ERROR: No proto file specified"
return 1
fi
go mod download
local golang_proto_path=$(go list -f '{{ .Dir }}' -m github.com/golang/protobuf)
local golang_proto_mod_path=$(sed -e 's,\(.*\)github.com.*,\1,' <<< "${golang_proto_path}")
local golang_proto_imp_replace="Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp"
golang_proto_imp_replace="${golang_proto_imp_replace},Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration"
local proto_go_path=${proto_path%%.proto}.pb.go
local proto_go_bin_path=${proto_path%%.proto}.pb.binary.go
local proto_go_rpcglue_path=${proto_path%%.proto}.rpcglue.pb.go
local go_proto_out="paths=source_relative"
if is_set "${grpc}"
then
go_proto_out="${go_proto_out},plugins=grpc"
fi
if is_set "${imp_replace}"
then
go_proto_out="${go_proto_out},${golang_proto_imp_replace}"
fi
if test -n "${go_proto_out}"
then
go_proto_out="${go_proto_out}:"
fi
# How we run protoc probably needs some documentation.
#
# This is the path to where
# -I="${golang_proto_path}/protobuf" \
local -i ret=0
status_stage "Generating ${proto_path} into ${proto_go_path} and ${proto_go_bin_path} (NO GOGO)"
echo "debug_run protoc \
-I=\"${golang_proto_path}\" \
-I=\"${golang_proto_mod_path}\" \
-I=\"${SOURCE_DIR}\" \
--go_out=\"${go_proto_out}${SOURCE_DIR}\" \
--go-binary_out=\"${SOURCE_DIR}\" \
\"${proto_path}\""
debug_run protoc \
-I="${golang_proto_path}" \
-I="${golang_proto_mod_path}" \
-I="${SOURCE_DIR}" \
--go_out="${go_proto_out}${SOURCE_DIR}" \
--go-binary_out="${SOURCE_DIR}" \
"${proto_path}"
if test $? -ne 0
then
err "Failed to run protoc for ${proto_path}"
return 1
fi
debug_run protoc-go-inject-tag \
-input="${proto_go_path}"
if test $? -ne 0
then
err "Failed to run protoc-go-inject-tag for ${proto_path}"
return 1
fi
echo "debug_run protoc \
-I=\"${golang_proto_path}\" \
-I=\"${golang_proto_mod_path}\" \
-I=\"${SOURCE_DIR}\" \
--go_out=\"${go_proto_out}${SOURCE_DIR}\" \
--go-binary_out=\"${SOURCE_DIR}\" \
\"${proto_path}\""
BUILD_TAGS=$(sed -e '/^[[:space:]]*$/,$d' < "${proto_path}" | grep '// +build')
if test -n "${BUILD_TAGS}"
then
echo -e "${BUILD_TAGS}\n" >> "${proto_go_path}.new"
cat "${proto_go_path}" >> "${proto_go_path}.new"
mv "${proto_go_path}.new" "${proto_go_path}"
echo -e "${BUILD_TAGS}\n" >> "${proto_go_bin_path}.new"
cat "${proto_go_bin_path}" >> "${proto_go_bin_path}.new"
mv "${proto_go_bin_path}.new" "${proto_go_bin_path}"
fi
# note: this has to run after we fix up the build tags above
rm -f "${proto_go_rpcglue_path}"
debug_run go run ./internal/tools/proto-gen-rpc-glue/main.go -path "${proto_go_path}"
if test $? -ne 0
then
err "Failed to generate consul rpc glue outputs from ${proto_path}"
return 1
fi
return 0
}
main "$@"
exit $?

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})"
pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null
SCRIPT_DIR=$(pwd)
@ -22,7 +23,7 @@ Description:
generated code.
Options:
--import-replace Replace imports of google types with those from the gogo/protobuf repo.
--import-replace Replace imports of google types with those from the protobuf repo.
--grpc Enable the gRPC plugin
-h | --help Print this help text.
EOF
@ -67,21 +68,19 @@ function main {
return 1
fi
local gogo_proto_path=$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)
local gogo_proto_mod_path=$(sed -e 's,\(.*\)github.com.*,\1,' <<< "${gogo_proto_path}")
go mod download
local gogo_proto_imp_replace="Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types"
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types"
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types"
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types"
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types"
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/api/annotations.proto=github.com/gogo/googleapis/google/api"
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/field_mask.proto=github.com/gogo/protobuf/types"
gogo_proto_imp_replace="${gogo_proto_imp_replace},Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types"
local golang_proto_path=$(go list -f '{{ .Dir }}' -m github.com/golang/protobuf)
local golang_proto_mod_path=$(sed -e 's,\(.*\)github.com.*,\1,' <<< "${golang_proto_path}")
local golang_proto_imp_replace="Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp"
golang_proto_imp_replace="${golang_proto_imp_replace},Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration"
local proto_go_path=${proto_path%%.proto}.pb.go
local proto_go_bin_path=${proto_path%%.proto}.pb.binary.go
local proto_go_rpcglue_path=${proto_path%%.proto}.rpcglue.pb.go
local go_proto_out="paths=source_relative"
if is_set "${grpc}"
then
@ -90,7 +89,7 @@ function main {
if is_set "${imp_replace}"
then
go_proto_out="${go_proto_out},${gogo_proto_imp_replace}"
go_proto_out="${go_proto_out},${golang_proto_imp_replace}"
fi
if test -n "${go_proto_out}"
@ -100,36 +99,69 @@ function main {
# How we run protoc probably needs some documentation.
#
# This is the path to where
# -I="${gogo_proto_path}/protobuf" \
# This is the path to where
# -I="${golang_proto_path}/protobuf" \
local -i ret=0
status_stage "Generating ${proto_path} into ${proto_go_path} and ${proto_go_bin_path}"
echo "debug_run protoc \
-I=\"${golang_proto_path}\" \
-I=\"${golang_proto_mod_path}\" \
-I=\"${SOURCE_DIR}\" \
--go_out=\"${go_proto_out}${SOURCE_DIR}\" \
--go-binary_out=\"${SOURCE_DIR}\" \
\"${proto_path}\""
debug_run protoc \
-I="${gogo_proto_path}/protobuf" \
-I="${gogo_proto_path}" \
-I="${gogo_proto_mod_path}" \
-I="${golang_proto_path}" \
-I="${golang_proto_mod_path}" \
-I="${SOURCE_DIR}" \
--gofast_out="${go_proto_out}${SOURCE_DIR}" \
--go_out="${go_proto_out}${SOURCE_DIR}" \
--go-binary_out="${SOURCE_DIR}" \
"${proto_path}"
if test $? -ne 0
then
err "Failed to generate outputs from ${proto_path}"
err "Failed to run protoc for ${proto_path}"
return 1
fi
debug_run protoc-go-inject-tag \
-input="${proto_go_path}"
if test $? -ne 0
then
err "Failed to run protoc-go-inject-tag for ${proto_path}"
return 1
fi
echo "debug_run protoc \
-I=\"${golang_proto_path}\" \
-I=\"${golang_proto_mod_path}\" \
-I=\"${SOURCE_DIR}\" \
--go_out=\"${go_proto_out}${SOURCE_DIR}\" \
--go-binary_out=\"${SOURCE_DIR}\" \
\"${proto_path}\""
BUILD_TAGS=$(sed -e '/^[[:space:]]*$/,$d' < "${proto_path}" | grep '// +build')
if test -n "${BUILD_TAGS}"
then
echo -e "${BUILD_TAGS}\n" >> "${proto_go_path}.new"
cat "${proto_go_path}" >> "${proto_go_path}.new"
mv "${proto_go_path}.new" "${proto_go_path}"
echo -e "${BUILD_TAGS}\n" >> "${proto_go_bin_path}.new"
cat "${proto_go_bin_path}" >> "${proto_go_bin_path}.new"
mv "${proto_go_bin_path}.new" "${proto_go_bin_path}"
fi
# note: this has to run after we fix up the build tags above
rm -f "${proto_go_rpcglue_path}"
debug_run go run ./internal/tools/proto-gen-rpc-glue/main.go -path "${proto_go_path}"
if test $? -ne 0
then
err "Failed to generate consul rpc glue outputs from ${proto_path}"
return 1
fi
return 0
}

2
go.mod
View File

@ -23,7 +23,7 @@ require (
github.com/envoyproxy/go-control-plane v0.9.5
github.com/frankban/quicktest v1.11.0 // indirect
github.com/fsnotify/fsnotify v1.5.1
github.com/gogo/protobuf v1.3.2
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.3.5
github.com/google/go-cmp v0.5.6
github.com/google/go-querystring v1.0.0 // indirect

View File

@ -1,4 +1,4 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto/pbacl/acl.proto
package pbacl
@ -6,9 +6,7 @@ package pbacl
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
@ -37,26 +35,18 @@ func (*ACLLink) ProtoMessage() {}
func (*ACLLink) Descriptor() ([]byte, []int) {
return fileDescriptor_ad2d2c73a6a0d8b5, []int{0}
}
func (m *ACLLink) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
return xxx_messageInfo_ACLLink.Unmarshal(m, b)
}
func (m *ACLLink) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ACLLink.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
return xxx_messageInfo_ACLLink.Marshal(b, m, deterministic)
}
func (m *ACLLink) XXX_Merge(src proto.Message) {
xxx_messageInfo_ACLLink.Merge(m, src)
}
func (m *ACLLink) XXX_Size() int {
return m.Size()
return xxx_messageInfo_ACLLink.Size(m)
}
func (m *ACLLink) XXX_DiscardUnknown() {
xxx_messageInfo_ACLLink.DiscardUnknown(m)
@ -82,296 +72,18 @@ func init() {
proto.RegisterType((*ACLLink)(nil), "acl.ACLLink")
}
func init() { proto.RegisterFile("proto/pbacl/acl.proto", fileDescriptor_ad2d2c73a6a0d8b5) }
func init() {
proto.RegisterFile("proto/pbacl/acl.proto", fileDescriptor_ad2d2c73a6a0d8b5)
}
var fileDescriptor_ad2d2c73a6a0d8b5 = []byte{
// 145 bytes of a gzipped FileDescriptorProto
// 128 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2d, 0x28, 0xca, 0x2f,
0xc9, 0xd7, 0x2f, 0x48, 0x4a, 0x4c, 0xce, 0xd1, 0x4f, 0x4c, 0xce, 0xd1, 0x03, 0xf3, 0x85, 0x98,
0x13, 0x93, 0x73, 0x94, 0x74, 0xb9, 0xd8, 0x1d, 0x9d, 0x7d, 0x7c, 0x32, 0xf3, 0xb2, 0x85, 0xf8,
0xb8, 0x98, 0x3c, 0x5d, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x98, 0x3c, 0x5d, 0x84, 0x84,
0xb8, 0x58, 0xfc, 0x12, 0x73, 0x53, 0x25, 0x98, 0xc0, 0x22, 0x60, 0xb6, 0x93, 0xe5, 0x89, 0x47,
0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe3, 0xb1, 0x1c, 0x43, 0x94,
0x7a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x46, 0x62, 0x71, 0x46,
0x66, 0x72, 0x7e, 0x51, 0x81, 0x7e, 0x72, 0x7e, 0x5e, 0x71, 0x69, 0x8e, 0x3e, 0x92, 0xc5, 0x49,
0x6c, 0x60, 0x8e, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x1b, 0xe6, 0xfd, 0xff, 0x8e, 0x00, 0x00,
0x00,
0xb8, 0x58, 0xfc, 0x12, 0x73, 0x53, 0x25, 0x98, 0xc0, 0x22, 0x60, 0xb6, 0x93, 0x66, 0x94, 0x7a,
0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x46, 0x62, 0x71, 0x46, 0x66,
0x72, 0x7e, 0x51, 0x81, 0x7e, 0x72, 0x7e, 0x5e, 0x71, 0x69, 0x8e, 0x3e, 0x92, 0x45, 0x49, 0x6c,
0x60, 0x8e, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xaf, 0x25, 0x54, 0x7f, 0x7e, 0x00, 0x00, 0x00,
}
func (m *ACLLink) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ACLLink) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ACLLink) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Name) > 0 {
i -= len(m.Name)
copy(dAtA[i:], m.Name)
i = encodeVarintAcl(dAtA, i, uint64(len(m.Name)))
i--
dAtA[i] = 0x12
}
if len(m.ID) > 0 {
i -= len(m.ID)
copy(dAtA[i:], m.ID)
i = encodeVarintAcl(dAtA, i, uint64(len(m.ID)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintAcl(dAtA []byte, offset int, v uint64) int {
offset -= sovAcl(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *ACLLink) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.ID)
if l > 0 {
n += 1 + l + sovAcl(uint64(l))
}
l = len(m.Name)
if l > 0 {
n += 1 + l + sovAcl(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovAcl(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozAcl(x uint64) (n int) {
return sovAcl(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *ACLLink) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAcl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ACLLink: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ACLLink: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAcl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthAcl
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthAcl
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAcl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthAcl
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthAcl
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Name = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipAcl(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthAcl
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipAcl(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowAcl
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowAcl
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowAcl
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthAcl
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupAcl
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthAcl
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthAcl = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowAcl = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupAcl = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -1,70 +0,0 @@
// Code generated by mog. DO NOT EDIT.
package pbcommongogo
import "github.com/hashicorp/consul/agent/structs"
func QueryMetaToStructs(s *QueryMeta, t *structs.QueryMeta) {
if s == nil {
return
}
t.Index = s.Index
t.LastContact = structs.DurationFromProtoGogo(s.LastContact)
t.KnownLeader = s.KnownLeader
t.ConsistencyLevel = s.ConsistencyLevel
t.ResultsFilteredByACLs = s.ResultsFilteredByACLs
}
func QueryMetaFromStructs(t *structs.QueryMeta, s *QueryMeta) {
if s == nil {
return
}
s.Index = t.Index
s.LastContact = structs.DurationToProtoGogo(t.LastContact)
s.KnownLeader = t.KnownLeader
s.ConsistencyLevel = t.ConsistencyLevel
s.ResultsFilteredByACLs = t.ResultsFilteredByACLs
}
func QueryOptionsToStructs(s *QueryOptions, t *structs.QueryOptions) {
if s == nil {
return
}
t.Token = s.Token
t.MinQueryIndex = s.MinQueryIndex
t.MaxQueryTime = structs.DurationFromProtoGogo(s.MaxQueryTime)
t.AllowStale = s.AllowStale
t.RequireConsistent = s.RequireConsistent
t.UseCache = s.UseCache
t.MaxStaleDuration = structs.DurationFromProtoGogo(s.MaxStaleDuration)
t.MaxAge = structs.DurationFromProtoGogo(s.MaxAge)
t.MustRevalidate = s.MustRevalidate
t.Filter = s.Filter
}
func QueryOptionsFromStructs(t *structs.QueryOptions, s *QueryOptions) {
if s == nil {
return
}
s.Token = t.Token
s.MinQueryIndex = t.MinQueryIndex
s.MaxQueryTime = structs.DurationToProtoGogo(t.MaxQueryTime)
s.AllowStale = t.AllowStale
s.RequireConsistent = t.RequireConsistent
s.UseCache = t.UseCache
s.MaxStaleDuration = structs.DurationToProtoGogo(t.MaxStaleDuration)
s.MaxAge = structs.DurationToProtoGogo(t.MaxAge)
s.MustRevalidate = t.MustRevalidate
s.Filter = t.Filter
}
func RaftIndexToStructs(s *RaftIndex, t *structs.RaftIndex) {
if s == nil {
return
}
t.CreateIndex = s.CreateIndex
t.ModifyIndex = s.ModifyIndex
}
func RaftIndexFromStructs(t *structs.RaftIndex, s *RaftIndex) {
if s == nil {
return
}
s.CreateIndex = t.CreateIndex
s.ModifyIndex = t.ModifyIndex
}

View File

@ -1,303 +0,0 @@
package pbcommongogo
import (
"time"
"github.com/hashicorp/consul/agent/structs"
)
// IsRead is always true for QueryOption
func (q *QueryOptions) IsRead() bool {
return true
}
// AllowStaleRead returns whether a stale read should be allowed
func (q *QueryOptions) AllowStaleRead() bool {
return q.AllowStale
}
func (q *QueryOptions) TokenSecret() string {
return q.Token
}
func (q *QueryOptions) SetTokenSecret(s string) {
q.Token = s
}
// SetToken is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetToken(token string) {
q.Token = token
}
// SetMinQueryIndex is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetMinQueryIndex(minQueryIndex uint64) {
q.MinQueryIndex = minQueryIndex
}
// SetMaxQueryTime is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetMaxQueryTime(maxQueryTime time.Duration) {
q.MaxQueryTime = structs.DurationToProtoGogo(maxQueryTime)
}
// SetAllowStale is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetAllowStale(allowStale bool) {
q.AllowStale = allowStale
}
// SetRequireConsistent is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetRequireConsistent(requireConsistent bool) {
q.RequireConsistent = requireConsistent
}
// SetUseCache is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetUseCache(useCache bool) {
q.UseCache = useCache
}
// SetMaxStaleDuration is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetMaxStaleDuration(maxStaleDuration time.Duration) {
q.MaxStaleDuration = structs.DurationToProtoGogo(maxStaleDuration)
}
// SetMaxAge is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetMaxAge(maxAge time.Duration) {
q.MaxAge = structs.DurationToProtoGogo(maxAge)
}
// SetMustRevalidate is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetMustRevalidate(mustRevalidate bool) {
q.MustRevalidate = mustRevalidate
}
// SetStaleIfError is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetStaleIfError(staleIfError time.Duration) {
q.StaleIfError = structs.DurationToProtoGogo(staleIfError)
}
func (q QueryOptions) HasTimedOut(start time.Time, rpcHoldTimeout, maxQueryTime, defaultQueryTime time.Duration) (bool, error) {
maxTime := structs.DurationFromProtoGogo(q.MaxQueryTime)
o := structs.QueryOptions{
MaxQueryTime: maxTime,
MinQueryIndex: q.MinQueryIndex,
}
return o.HasTimedOut(start, rpcHoldTimeout, maxQueryTime, defaultQueryTime)
}
// SetFilter is needed to implement the structs.QueryOptionsCompat interface
func (q *QueryOptions) SetFilter(filter string) {
q.Filter = filter
}
// GetMaxQueryTime is required to implement blockingQueryOptions
func (q *QueryOptions) GetMaxQueryTime() (time.Duration, error) {
return structs.DurationFromProtoGogo(q.MaxQueryTime), nil
}
// GetMinQueryIndex is required to implement blockingQueryOptions
func (q *QueryOptions) GetMinQueryIndex() uint64 {
if q != nil {
return q.MinQueryIndex
}
return 0
}
// GetRequireConsistent is required to implement blockingQueryOptions
func (q *QueryOptions) GetRequireConsistent() bool {
if q != nil {
return q.RequireConsistent
}
return false
}
// GetToken is required to implement blockingQueryOptions
func (q *QueryOptions) GetToken() string {
if q != nil {
return q.Token
}
return ""
}
// GetAllowStale is required to implement structs.QueryOptionsCompat
func (q *QueryOptions) GetAllowStale() bool {
if q != nil {
return q.AllowStale
}
return false
}
// GetFilter is required to implement structs.QueryOptionsCompat
func (q *QueryOptions) GetFilter() string {
if q != nil {
return q.Filter
}
return ""
}
// GetMaxAge is required to implement structs.QueryOptionsCompat
func (q *QueryOptions) GetMaxAge() (time.Duration, error) {
if q != nil {
return structs.DurationFromProtoGogo(q.MaxAge), nil
}
return 0, nil
}
// GetMaxStaleDuration is required to implement structs.QueryOptionsCompat
func (q *QueryOptions) GetMaxStaleDuration() (time.Duration, error) {
if q != nil {
return structs.DurationFromProtoGogo(q.MaxStaleDuration), nil
}
return 0, nil
}
// GetMustRevalidate is required to implement structs.QueryOptionsCompat
func (q *QueryOptions) GetMustRevalidate() bool {
if q != nil {
return q.MustRevalidate
}
return false
}
// GetStaleIfError is required to implement structs.QueryOptionsCompat
func (q *QueryOptions) GetStaleIfError() (time.Duration, error) {
if q != nil {
return structs.DurationFromProtoGogo(q.StaleIfError), nil
}
return 0, nil
}
// GetUseCache is required to implement structs.QueryOptionsCompat
func (q *QueryOptions) GetUseCache() bool {
if q != nil {
return q.UseCache
}
return false
}
// SetLastContact is needed to implement the structs.QueryMetaCompat interface
func (q *QueryMeta) SetLastContact(lastContact time.Duration) {
q.LastContact = structs.DurationToProtoGogo(lastContact)
}
// SetKnownLeader is needed to implement the structs.QueryMetaCompat interface
func (q *QueryMeta) SetKnownLeader(knownLeader bool) {
q.KnownLeader = knownLeader
}
// SetIndex is needed to implement the structs.QueryMetaCompat interface
func (q *QueryMeta) SetIndex(index uint64) {
q.Index = index
}
// SetConsistencyLevel is needed to implement the structs.QueryMetaCompat interface
func (q *QueryMeta) SetConsistencyLevel(consistencyLevel string) {
q.ConsistencyLevel = consistencyLevel
}
func (q *QueryMeta) GetBackend() structs.QueryBackend {
return structs.QueryBackend(0)
}
// SetResultsFilteredByACLs is needed to implement the structs.QueryMetaCompat interface
func (q *QueryMeta) SetResultsFilteredByACLs(v bool) {
q.ResultsFilteredByACLs = v
}
// GetIndex is required to implement blockingQueryResponseMeta
func (q *QueryMeta) GetIndex() uint64 {
if q != nil {
return q.Index
}
return 0
}
// GetConsistencyLevel is required to implement structs.QueryMetaCompat
func (q *QueryMeta) GetConsistencyLevel() string {
if q != nil {
return q.ConsistencyLevel
}
return ""
}
// GetKnownLeader is required to implement structs.QueryMetaCompat
func (q *QueryMeta) GetKnownLeader() bool {
if q != nil {
return q.KnownLeader
}
return false
}
// GetLastContact is required to implement structs.QueryMetaCompat
func (q *QueryMeta) GetLastContact() (time.Duration, error) {
if q != nil {
return structs.DurationFromProtoGogo(q.LastContact), nil
}
return 0, nil
}
// GetResultsFilteredByACLs is required to implement structs.QueryMetaCompat
func (q *QueryMeta) GetResultsFilteredByACLs() bool {
if q != nil {
return q.ResultsFilteredByACLs
}
return false
}
// WriteRequest only applies to writes, always false
//
// IsRead implements structs.RPCInfo
func (w WriteRequest) IsRead() bool {
return false
}
// SetTokenSecret implements structs.RPCInfo
func (w WriteRequest) TokenSecret() string {
return w.Token
}
// SetTokenSecret implements structs.RPCInfo
func (w *WriteRequest) SetTokenSecret(s string) {
w.Token = s
}
// AllowStaleRead returns whether a stale read should be allowed
//
// AllowStaleRead implements structs.RPCInfo
func (w WriteRequest) AllowStaleRead() bool {
return false
}
// HasTimedOut implements structs.RPCInfo
func (w WriteRequest) HasTimedOut(start time.Time, rpcHoldTimeout, _, _ time.Duration) (bool, error) {
return time.Since(start) > rpcHoldTimeout, nil
}
// IsRead implements structs.RPCInfo
func (r *ReadRequest) IsRead() bool {
return true
}
// AllowStaleRead implements structs.RPCInfo
func (r *ReadRequest) AllowStaleRead() bool {
// TODO(partitions): plumb this?
return false
}
// TokenSecret implements structs.RPCInfo
func (r *ReadRequest) TokenSecret() string {
return r.Token
}
// SetTokenSecret implements structs.RPCInfo
func (r *ReadRequest) SetTokenSecret(token string) {
r.Token = token
}
// HasTimedOut implements structs.RPCInfo
func (r *ReadRequest) HasTimedOut(start time.Time, rpcHoldTimeout, maxQueryTime, defaultQueryTime time.Duration) (bool, error) {
return time.Since(start) > rpcHoldTimeout, nil
}
// RequestDatacenter implements structs.RPCInfo
func (td TargetDatacenter) RequestDatacenter() string {
return td.Datacenter
}

View File

@ -1,78 +0,0 @@
// Code generated by protoc-gen-go-binary. DO NOT EDIT.
// source: proto/pbcommongogo/common.proto
package pbcommongogo
import (
"github.com/golang/protobuf/proto"
)
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *RaftIndex) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *RaftIndex) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *TargetDatacenter) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *TargetDatacenter) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *WriteRequest) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *WriteRequest) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *ReadRequest) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *ReadRequest) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *QueryOptions) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *QueryOptions) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *QueryMeta) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *QueryMeta) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *EnterpriseMeta) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *EnterpriseMeta) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}

File diff suppressed because it is too large Load Diff

View File

@ -1,182 +0,0 @@
syntax = "proto3";
package commongogo;
option go_package = "github.com/hashicorp/consul/proto/pbcommongogo";
import "google/protobuf/duration.proto";
// Go Modules now includes the version in the filepath for packages within GOPATH/pkg/mode
// Therefore unless we want to hardcode a version here like
// github.com/gogo/protobuf@v1.3.0/gogoproto/gogo.proto then the only other choice is to
// have a more relative import and pass the right import path to protoc. I don't like it
// but its necessary.
import "gogoproto/gogo.proto";
option (gogoproto.goproto_unkeyed_all) = false;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.goproto_sizecache_all) = false;
// RaftIndex is used to track the index used while creating
// or modifying a given struct type.
//
// mog annotation:
//
// target=github.com/hashicorp/consul/agent/structs.RaftIndex
// output=common.gen.go
// name=Structs
message RaftIndex {
uint64 CreateIndex = 1 [(gogoproto.moretags) = "bexpr:\"-\""];
uint64 ModifyIndex = 2 [(gogoproto.moretags) = "bexpr:\"-\""];
}
// TargetDatacenter is intended to be used within other messages used for RPC routing
// amongst the various Consul datacenters
message TargetDatacenter {
string Datacenter = 1;
}
message WriteRequest {
// Token is the ACL token ID. If not provided, the 'anonymous'
// token is assumed for backwards compatibility.
string Token = 1;
}
// ReadRequest is a type that may be embedded into any requests for read
// operations.
// It is a replacement for QueryOptions now that we no longer need any of those
// fields because we are moving away from using blocking queries.
// It is also similar to WriteRequest. It is a separate type so that in the
// future we can introduce fields that may only be relevant for reads.
message ReadRequest {
// Token is the ACL token ID. If not provided, the 'anonymous'
// token is assumed for backwards compatibility.
string Token = 1;
// RequireConsistent indicates that the request must be sent to the leader.
bool RequireConsistent = 2;
}
// QueryOptions is used to specify various flags for read queries
//
// mog annotation:
//
// target=github.com/hashicorp/consul/agent/structs.QueryOptions
// output=common.gen.go
// name=Structs
// ignore-fields=StaleIfError,AllowNotModifiedResponse
message QueryOptions {
// Token is the ACL token ID. If not provided, the 'anonymous'
// token is assumed for backwards compatibility.
string Token = 1;
// If set, wait until query exceeds given index. Must be provided
// with MaxQueryTime.
uint64 MinQueryIndex = 2;
// Provided with MinQueryIndex to wait for change.
// mog: func-to=structs.DurationFromProtoGogo func-from=structs.DurationToProtoGogo
google.protobuf.Duration MaxQueryTime = 3
[(gogoproto.nullable) = false];
// If set, any follower can service the request. Results
// may be arbitrarily stale.
bool AllowStale = 4;
// If set, the leader must verify leadership prior to
// servicing the request. Prevents a stale read.
bool RequireConsistent = 5;
// If set, the local agent may respond with an arbitrarily stale locally
// cached response. The semantics differ from AllowStale since the agent may
// be entirely partitioned from the servers and still considered "healthy" by
// operators. Stale responses from Servers are also arbitrarily stale, but can
// provide additional bounds on the last contact time from the leader. It's
// expected that servers that are partitioned are noticed and replaced in a
// timely way by operators while the same may not be true for client agents.
bool UseCache = 6;
// If set and AllowStale is true, will try first a stale
// read, and then will perform a consistent read if stale
// read is older than value.
// mog: func-to=structs.DurationFromProtoGogo func-from=structs.DurationToProtoGogo
google.protobuf.Duration MaxStaleDuration = 7
[(gogoproto.nullable) = false];
// MaxAge limits how old a cached value will be returned if UseCache is true.
// If there is a cached response that is older than the MaxAge, it is treated
// as a cache miss and a new fetch invoked. If the fetch fails, the error is
// returned. Clients that wish to allow for stale results on error can set
// StaleIfError to a longer duration to change this behavior. It is ignored
// if the endpoint supports background refresh caching. See
// https://www.consul.io/api/index.html#agent-caching for more details.
// mog: func-to=structs.DurationFromProtoGogo func-from=structs.DurationToProtoGogo
google.protobuf.Duration MaxAge = 8
[(gogoproto.nullable) = false];
// MustRevalidate forces the agent to fetch a fresh version of a cached
// resource or at least validate that the cached version is still fresh. It is
// implied by either max-age=0 or must-revalidate Cache-Control headers. It
// only makes sense when UseCache is true. We store it since MaxAge = 0 is the
// default unset value.
bool MustRevalidate = 9;
// StaleIfError specifies how stale the client will accept a cached response
// if the servers are unavailable to fetch a fresh one. Only makes sense when
// UseCache is true and MaxAge is set to a lower, non-zero value. It is
// ignored if the endpoint supports background refresh caching. See
// https://www.consul.io/api/index.html#agent-caching for more details.
google.protobuf.Duration StaleIfError = 10
[(gogoproto.nullable) = false];
// Filter specifies the go-bexpr filter expression to be used for
// filtering the data prior to returning a response
string Filter = 11;
}
// QueryMeta allows a query response to include potentially
// useful metadata about a query
//
// mog annotation:
//
// target=github.com/hashicorp/consul/agent/structs.QueryMeta
// output=common.gen.go
// name=Structs
// ignore-fields=NotModified,Backend
message QueryMeta {
// This is the index associated with the read
uint64 Index = 1;
// If AllowStale is used, this is time elapsed since
// last contact between the follower and leader. This
// can be used to gauge staleness.
// mog: func-to=structs.DurationFromProtoGogo func-from=structs.DurationToProtoGogo
google.protobuf.Duration LastContact = 2
[(gogoproto.nullable) = false];
// Used to indicate if there is a known leader node
bool KnownLeader = 3;
// Consistencylevel returns the consistency used to serve the query
// Having `discovery_max_stale` on the agent can affect whether
// the request was served by a leader.
string ConsistencyLevel = 4;
// Reserved for NotModified and Backend.
reserved 5, 6;
// ResultsFilteredByACLs is true when some of the query's results were
// filtered out by enforcing ACLs. It may be false because nothing was
// removed, or because the endpoint does not yet support this flag.
bool ResultsFilteredByACLs = 7;
}
// EnterpriseMeta contains metadata that is only used by the Enterprise version
// of Consul.
message EnterpriseMeta {
// Namespace in which the entity exists.
string Namespace = 1;
// Partition in which the entity exists.
string Partition = 2;
}

View File

@ -1,25 +0,0 @@
//go:build !consulent
// +build !consulent
package pbcommongogo
import (
"github.com/hashicorp/consul/agent/structs"
)
var DefaultEnterpriseMeta = EnterpriseMeta{}
func NewEnterpriseMetaFromStructs(_ structs.EnterpriseMeta) *EnterpriseMeta {
return &EnterpriseMeta{}
}
func EnterpriseMetaToStructs(s *EnterpriseMeta, t *structs.EnterpriseMeta) {
if s == nil {
return
}
}
func EnterpriseMetaFromStructs(t *structs.EnterpriseMeta, s *EnterpriseMeta) {
if s == nil {
return
}
}

View File

@ -4,7 +4,6 @@ import (
fmt "fmt"
"reflect"
//TODO(gogo-remove): remove the types alias
types "github.com/golang/protobuf/ptypes/struct"
)

View File

@ -1,23 +0,0 @@
package pbutil
import (
"time"
"github.com/gogo/protobuf/types"
)
func DurationToProto(d time.Duration) *types.Duration {
return types.DurationProto(d)
}
func DurationFromProto(d *types.Duration) (time.Duration, error) {
return types.DurationFromProto(d)
}
func TimeFromProto(s *types.Timestamp) (time.Time, error) {
return types.TimestampFromProto(s)
}
func TimeToProto(s time.Time) (*types.Timestamp, error) {
return types.TimestampProto(s)
}

View File

@ -1,68 +0,0 @@
package proto
import (
"reflect"
"time"
"github.com/gogo/protobuf/types"
)
var (
tsType = reflect.TypeOf((*types.Timestamp)(nil))
timePtrType = reflect.TypeOf((*time.Time)(nil))
timeType = timePtrType.Elem()
mapStrInf = reflect.TypeOf((map[string]interface{})(nil))
epoch1970 = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
)
// HookPBTimestampToTime is a mapstructure decode hook to translate a protobuf timestamp
// to a time.Time value
func HookPBTimestampToTime(from, to reflect.Type, data interface{}) (interface{}, error) {
if to == timeType && from == tsType {
ts := data.(*types.Timestamp)
if ts.Seconds == 0 && ts.Nanos == 0 {
return time.Time{}, nil
}
return time.Unix(ts.Seconds, int64(ts.Nanos)).UTC(), nil
}
return data, nil
}
// HookTimeToPBtimestamp is a mapstructure decode hook to translate a time.Time value to
// a protobuf Timestamp value.
func HookTimeToPBTimestamp(from, to reflect.Type, data interface{}) (interface{}, error) {
// Note that mapstructure doesn't do direct struct to struct conversion in this case. I
// still don't completely understand why converting the PB TS to time.Time does but
// I suspect it has something to do with the struct containing a concrete time.Time
// as opposed to a pointer to a time.Time. Regardless this path through mapstructure
// first will decode the concrete time.Time into a map[string]interface{} before
// eventually decoding that map[string]interface{} into the *types.Timestamp. One
// other note is that mapstructure ends up creating a new Value and sets it it to
// the time.Time value and thats what gets passed to us. That is why we end up
// seeing a *time.Time instead of a time.Time.
if from == timePtrType && to == mapStrInf {
ts := data.(*time.Time)
// protobuf only supports times from Jan 1 1970 onward but the time.Time type
// can represent values back to year 1. Basically
if ts.Before(epoch1970) {
return map[string]interface{}{}, nil
}
nanos := ts.UnixNano()
if nanos < 0 {
return map[string]interface{}{}, nil
}
seconds := nanos / 1000000000
nanos = nanos % 1000000000
return map[string]interface{}{
"Seconds": seconds,
"Nanos": int32(nanos),
}, nil
}
return data, nil
}

View File

@ -1,86 +0,0 @@
package proto
import (
"testing"
"time"
"github.com/gogo/protobuf/types"
"github.com/mitchellh/mapstructure"
"github.com/stretchr/testify/require"
)
type pbTSWrapper struct {
Timestamp *types.Timestamp
}
type timeTSWrapper struct {
Timestamp time.Time
}
func TestHookPBTimestampToTime(t *testing.T) {
in := pbTSWrapper{
Timestamp: &types.Timestamp{
Seconds: 1000,
Nanos: 42,
},
}
expected := timeTSWrapper{
Timestamp: time.Unix(1000, 42).UTC(),
}
var actual timeTSWrapper
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: HookPBTimestampToTime,
Result: &actual,
})
require.NoError(t, err)
require.NoError(t, decoder.Decode(in))
require.Equal(t, expected, actual)
}
func TestHookTimeToPBTimestamp(t *testing.T) {
in := timeTSWrapper{
Timestamp: time.Unix(999999, 123456).UTC(),
}
expected := pbTSWrapper{
Timestamp: &types.Timestamp{
Seconds: 999999,
Nanos: 123456,
},
}
var actual pbTSWrapper
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: HookTimeToPBTimestamp,
Result: &actual,
})
require.NoError(t, err)
require.NoError(t, decoder.Decode(in))
require.Equal(t, expected, actual)
}
func TestHookTimeToPBTimestamp_ZeroTime(t *testing.T) {
in := timeTSWrapper{}
expected := pbTSWrapper{
Timestamp: &types.Timestamp{
Seconds: 0,
Nanos: 0,
},
}
var actual pbTSWrapper
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: HookTimeToPBTimestamp,
Result: &actual,
})
require.NoError(t, err)
require.NoError(t, decoder.Decode(in))
require.Equal(t, expected, actual)
}