diff --git a/GNUmakefile b/GNUmakefile index 81240ef59b..ad5454991c 100644 --- a/GNUmakefile +++ b/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: diff --git a/proto/pbpeering/deep-copy.sh b/proto/pbpeering/deep-copy.sh deleted file mode 100755 index 48acdd4a13..0000000000 --- a/proto/pbpeering/deep-copy.sh +++ /dev/null @@ -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 \ - ./ - diff --git a/proto/pbpeering/peering.deepcopy.go b/proto/pbpeering/peering.deepcopy.go deleted file mode 100644 index 7ba92d425c..0000000000 --- a/proto/pbpeering/peering.deepcopy.go +++ /dev/null @@ -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 -} diff --git a/proto/pbpeering/peering.go b/proto/pbpeering/peering.go index b5d36e73dd..511de42c57 100644 --- a/proto/pbpeering/peering.go +++ b/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 +}