Browse Source

proto: deep-copy PeeringTrustBundle using proto.Clone (#15004)

Fixes a `go vet` warning caused by the pragma.DoNotCopy on the protobuf
message type.

Originally I'd hoped we wouldn't need any reflection in the proxycfg hot
path, but it seems proto.Clone is the only supported way to copy a message.
kisunji/fix-golden
Dan Upton 2 years ago committed by GitHub
parent
commit
641347fe14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      GNUmakefile
  2. 11
      proto/pbpeering/deep-copy.sh
  3. 17
      proto/pbpeering/peering.deepcopy.go
  4. 12
      proto/pbpeering/peering.go

1
GNUmakefile

@ -329,7 +329,6 @@ codegen-tools:
.PHONY: deep-copy
deep-copy:
@$(SHELL) $(CURDIR)/agent/structs/deep-copy.sh
@$(SHELL) $(CURDIR)/proto/pbpeering/deep-copy.sh
@$(SHELL) $(CURDIR)/agent/proxycfg/deep-copy.sh
version:

11
proto/pbpeering/deep-copy.sh

@ -1,11 +0,0 @@
#!/usr/bin/env bash
readonly PACKAGE_DIR="$(dirname "${BASH_SOURCE[0]}")"
cd $PACKAGE_DIR
# Uses: https://github.com/globusdigital/deep-copy
deep-copy -pointer-receiver \
-type PeeringTrustBundle \
-o ./peering.deepcopy.go \
./

17
proto/pbpeering/peering.deepcopy.go

@ -1,17 +0,0 @@
// generated by deep-copy -pointer-receiver -type PeeringTrustBundle -o ./peering.deepcopy.go ./; DO NOT EDIT.
package pbpeering
// DeepCopy generates a deep copy of *PeeringTrustBundle
func (o *PeeringTrustBundle) DeepCopy() *PeeringTrustBundle {
var cp PeeringTrustBundle = *o
if o.unknownFields != nil {
cp.unknownFields = make([]byte, len(o.unknownFields))
copy(cp.unknownFields, o.unknownFields)
}
if o.RootPEMs != nil {
cp.RootPEMs = make([]string, len(o.RootPEMs))
copy(cp.RootPEMs, o.RootPEMs)
}
return &cp
}

12
proto/pbpeering/peering.go

@ -10,6 +10,7 @@ import (
"github.com/golang/protobuf/ptypes/timestamp"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/protobuf/proto"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
@ -302,3 +303,14 @@ func TimePtrToProto(s *time.Time) *timestamp.Timestamp {
}
return structs.TimeToProto(*s)
}
// DeepCopy returns a copy of the PeeringTrustBundle that can be passed around
// without worrying about the receiver unsafely modifying it. It is used by the
// generated DeepCopy methods in proxycfg.
func (o *PeeringTrustBundle) DeepCopy() *PeeringTrustBundle {
cp, ok := proto.Clone(o).(*PeeringTrustBundle)
if !ok {
panic(fmt.Sprintf("failed to clone *PeeringTrustBundle, got: %T", cp))
}
return cp
}

Loading…
Cancel
Save