From 3dd21023bc9964e41ec8eb2c649860378e725aea Mon Sep 17 00:00:00 2001 From: freddygv Date: Wed, 27 Oct 2021 14:54:27 -0600 Subject: [PATCH 1/2] Ensure partition-exports kind gets marshalled The api module has decoding functions that rely on 'kind' being present of payloads. This is so that we can decode into the appropriate api type for the config entry. This commit ensures that a static kind is marshalled in responses from Consul's api endpoints so that the api module can decode them. --- agent/structs/config_entry_exports.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/agent/structs/config_entry_exports.go b/agent/structs/config_entry_exports.go index 5ae15ca68..044f9d62a 100644 --- a/agent/structs/config_entry_exports.go +++ b/agent/structs/config_entry_exports.go @@ -1,6 +1,7 @@ package structs import ( + "encoding/json" "fmt" "github.com/hashicorp/consul/acl" @@ -158,3 +159,19 @@ func (e *PartitionExportsConfigEntry) GetEnterpriseMeta() *EnterpriseMeta { return &e.EnterpriseMeta } + +// MarshalJSON adds the Kind field so that the JSON can be decoded back into the +// correct type. +// This method is implemented on the structs type (as apposed to the api type) +// because that is what the API currently uses to return a response. +func (e *PartitionExportsConfigEntry) MarshalJSON() ([]byte, error) { + type Alias PartitionExportsConfigEntry + source := &struct { + Kind string + *Alias + }{ + Kind: PartitionExports, + Alias: (*Alias)(e), + } + return json.Marshal(source) +} From 35c5ff50115c64cbd8421fa3dd874b64ca406620 Mon Sep 17 00:00:00 2001 From: freddygv Date: Wed, 27 Oct 2021 14:58:04 -0600 Subject: [PATCH 2/2] Update filename to match entry kind - mesh --- api/{config_entry_cluster.go => config_entry_mesh.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename api/{config_entry_cluster.go => config_entry_mesh.go} (100%) diff --git a/api/config_entry_cluster.go b/api/config_entry_mesh.go similarity index 100% rename from api/config_entry_cluster.go rename to api/config_entry_mesh.go