Skip to content

Commit 16a1c59

Browse files
authored
2.5 fix error parsing addressoverrides (#5400)
Signed-off-by: Fedor Partanskiy <fredprtnsk@gmail.com>
1 parent 5363ac7 commit 16a1c59

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

core/deliverservice/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"io/ioutil"
1212
"time"
1313

14+
"github.com/hyperledger/fabric/common/viperutil"
1415
"github.com/hyperledger/fabric/core/config"
1516
"github.com/hyperledger/fabric/internal/pkg/comm"
1617
"github.com/hyperledger/fabric/internal/pkg/peer/orderers"
17-
1818
"github.com/pkg/errors"
1919
"github.com/spf13/viper"
2020
)
@@ -63,7 +63,7 @@ func GlobalConfig() *DeliverServiceConfig {
6363

6464
func LoadOverridesMap() (map[string]*orderers.Endpoint, error) {
6565
var overrides []AddressOverride
66-
err := viper.UnmarshalKey("peer.deliveryclient.addressOverrides", &overrides)
66+
err := viper.UnmarshalKey("peer.deliveryclient.addressOverrides", &overrides, viper.DecodeHook(viperutil.YamlStringToStructHook(overrides)))
6767
if err != nil {
6868
return nil, errors.WithMessage(err, "could not unmarshal peer.deliveryclient.addressOverrides")
6969
}

core/deliverservice/config_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import (
1111
"io/ioutil"
1212
"os"
1313
"path/filepath"
14+
"strings"
1415
"testing"
1516
"time"
1617

17-
"github.com/stretchr/testify/require"
18-
1918
"github.com/hyperledger/fabric/core/deliverservice"
19+
"github.com/hyperledger/fabric/internal/peer/common"
2020
"github.com/hyperledger/fabric/internal/pkg/comm"
2121
"github.com/spf13/viper"
22+
"github.com/stretchr/testify/require"
2223
)
2324

2425
func TestSecureOptsConfig(t *testing.T) {
@@ -161,6 +162,37 @@ func TestLoadOverridesMap(t *testing.T) {
161162
require.Equal(t, "addressTo2", ep2.Address)
162163
})
163164

165+
t.Run("GreenPath With Env", func(t *testing.T) {
166+
t.Setenv("CORE_PEER_DELIVERYCLIENT_ADDRESSOVERRIDES", "[{from: addressFrom1, to: addressTo1, caCertsFile: testdata/cert.pem}"+
167+
", {from: addressFrom2, to: addressTo2, caCertsFile: testdata/cert.pem}]")
168+
config := `
169+
peer:
170+
deliveryclient:
171+
addressOverrides:
172+
`
173+
174+
viper.Reset()
175+
176+
viper.SetEnvPrefix(common.CmdRoot)
177+
viper.AllowEmptyEnv(true)
178+
viper.AutomaticEnv()
179+
replacer := strings.NewReplacer(".", "_")
180+
viper.SetEnvKeyReplacer(replacer)
181+
182+
viper.SetConfigType("yaml")
183+
err := viper.ReadConfig(bytes.NewBuffer([]byte(config)))
184+
require.NoError(t, err)
185+
res, err := deliverservice.LoadOverridesMap()
186+
require.NoError(t, err)
187+
require.Len(t, res, 2)
188+
ep1, ok := res["addressFrom1"]
189+
require.True(t, ok)
190+
require.Equal(t, "addressTo1", ep1.Address)
191+
ep2, ok := res["addressFrom2"]
192+
require.True(t, ok)
193+
require.Equal(t, "addressTo2", ep2.Address)
194+
})
195+
164196
t.Run("MissingCAFiles", func(t *testing.T) {
165197
config := `
166198
peer:

0 commit comments

Comments
 (0)