From 1a491886fad318700a8bb16619bf06a53a7b0aab Mon Sep 17 00:00:00 2001 From: "R.B. Boyer" <4903+rboyer@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:27:21 -0500 Subject: [PATCH] structs: ensure exported-services PeerName field can be addressed as peer_name (#12862) --- agent/structs/config_entry_exports.go | 8 ++++---- agent/structs/config_entry_test.go | 9 +++++++++ api/config_entry_exports.go | 8 ++++---- command/config/write/config_write_test.go | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/agent/structs/config_entry_exports.go b/agent/structs/config_entry_exports.go index e7e33c54d2..c3051fc371 100644 --- a/agent/structs/config_entry_exports.go +++ b/agent/structs/config_entry_exports.go @@ -14,7 +14,7 @@ type ExportedServicesConfigEntry struct { // Services is a list of services to be exported and the list of partitions // to expose them to. - Services []ExportedService + Services []ExportedService `json:",omitempty"` Meta map[string]string `json:",omitempty"` acl.EnterpriseMeta `hcl:",squash" mapstructure:",squash"` @@ -31,7 +31,7 @@ type ExportedService struct { Namespace string `json:",omitempty"` // Consumers is a list of downstream consumers of the service to be exported. - Consumers []ServiceConsumer + Consumers []ServiceConsumer `json:",omitempty"` } // ServiceConsumer represents a downstream consumer of the service to be exported. @@ -39,10 +39,10 @@ type ExportedService struct { type ServiceConsumer struct { // Partition is the admin partition to export the service to. // Deprecated: PeerName should be used for both remote peers and local partitions. - Partition string + Partition string `json:",omitempty"` // PeerName is the name of the peer to export the service to. - PeerName string + PeerName string `json:",omitempty" alias:"peer_name"` } func (e *ExportedServicesConfigEntry) ToMap() map[string]map[string][]string { diff --git a/agent/structs/config_entry_test.go b/agent/structs/config_entry_test.go index 90931907ef..661a87ce90 100644 --- a/agent/structs/config_entry_test.go +++ b/agent/structs/config_entry_test.go @@ -1770,6 +1770,9 @@ func TestDecodeConfigEntry(t *testing.T) { }, { partition = "baz" + }, + { + peer_name = "flarm" } ] }, @@ -1801,6 +1804,9 @@ func TestDecodeConfigEntry(t *testing.T) { }, { Partition = "baz" + }, + { + PeerName = "flarm" } ] }, @@ -1832,6 +1838,9 @@ func TestDecodeConfigEntry(t *testing.T) { { Partition: "baz", }, + { + PeerName: "flarm", + }, }, }, { diff --git a/api/config_entry_exports.go b/api/config_entry_exports.go index 14a021f649..4193358ab3 100644 --- a/api/config_entry_exports.go +++ b/api/config_entry_exports.go @@ -16,7 +16,7 @@ type ExportedServicesConfigEntry struct { // Services is a list of services to be exported and the list of partitions // to expose them to. - Services []ExportedService + Services []ExportedService `json:",omitempty"` Meta map[string]string `json:",omitempty"` @@ -40,7 +40,7 @@ type ExportedService struct { Namespace string `json:",omitempty"` // Consumers is a list of downstream consumers of the service to be exported. - Consumers []ServiceConsumer + Consumers []ServiceConsumer `json:",omitempty"` } // ServiceConsumer represents a downstream consumer of the service to be exported. @@ -48,10 +48,10 @@ type ExportedService struct { type ServiceConsumer struct { // Partition is the admin partition to export the service to. // Deprecated: PeerName should be used for both remote peers and local partitions. - Partition string + Partition string `json:",omitempty"` // PeerName is the name of the peer to export the service to. - PeerName string + PeerName string `json:",omitempty" alias:"peer_name"` } func (e *ExportedServicesConfigEntry) GetKind() string { return ExportedServices } diff --git a/command/config/write/config_write_test.go b/command/config/write/config_write_test.go index a55253d488..679a3b77ec 100644 --- a/command/config/write/config_write_test.go +++ b/command/config/write/config_write_test.go @@ -2891,6 +2891,9 @@ func TestParseConfigEntry(t *testing.T) { }, { partition = "baz" + }, + { + peer_name = "flarm" } ] }, @@ -2922,6 +2925,9 @@ func TestParseConfigEntry(t *testing.T) { }, { Partition = "baz" + }, + { + PeerName = "flarm" } ] }, @@ -2954,6 +2960,9 @@ func TestParseConfigEntry(t *testing.T) { }, { "partition": "baz" + }, + { + "peer_name": "flarm" } ] }, @@ -2987,6 +2996,9 @@ func TestParseConfigEntry(t *testing.T) { }, { "Partition": "baz" + }, + { + "PeerName": "flarm" } ] }, @@ -3019,6 +3031,9 @@ func TestParseConfigEntry(t *testing.T) { { Partition: "baz", }, + { + PeerName: "flarm", + }, }, }, {