Skip to content

Commit

Permalink
Backport FAB-18482 into 2.2. Ability to specify chaincode's external …
Browse files Browse the repository at this point in the history
…builders via env var. Added example on how to override the list of system chaincodes using env var due to bugs in viper.

Signed-off-by: Vladyslav Kopaihorodskyi <vlad.kopaygorodsky@gmail.com>
  • Loading branch information
kopaygorodsky authored and denyeart committed Jul 26, 2022
1 parent fb9551d commit 52247b3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions core/chaincode/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var _ = Describe("Config", func() {
viper.Set("chaincode.logging.format", "test-chaincode-logging-format")
viper.Set("chaincode.logging.level", "warning")
viper.Set("chaincode.logging.shim", "warning")
viper.Set("chaincode.system", `{"lscc": "true", "escc": "true", "vscc": "true", "cscc": "true", "somecc": "enabled"}`)

config := chaincode.GlobalConfig()
Expect(config.TLSEnabled).To(BeTrue())
Expand All @@ -46,6 +47,13 @@ var _ = Describe("Config", func() {
Expect(config.LogFormat).To(Equal("test-chaincode-logging-format"))
Expect(config.LogLevel).To(Equal("warn"))
Expect(config.ShimLogLevel).To(Equal("warn"))
Expect(config.SCCAllowlist).To(Equal(map[string]bool{
"somecc": true,
"lscc": true,
"escc": true,
"vscc": true,
"cscc": true,
}))
})

Context("when an invalid keepalive is configured", func() {
Expand Down
8 changes: 5 additions & 3 deletions core/peer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package peer
import (
"crypto/tls"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"net"
"path/filepath"
Expand Down Expand Up @@ -276,10 +277,11 @@ func (c *Config) load() error {

c.ChaincodePull = viper.GetBool("chaincode.pull")
var externalBuilders []ExternalBuilder
err = viper.UnmarshalKey("chaincode.externalBuilders", &externalBuilders)
if err != nil {
return err

if err := yaml.UnmarshalStrict([]byte(viper.GetString("chaincode.externalBuilders")), &externalBuilders); err != nil {
return errors.Wrap(err, "unmarshalling 'chaincode.externalBuilders' into yaml")
}

c.ExternalBuilders = externalBuilders
for builderIndex, builder := range c.ExternalBuilders {
if builder.Path == "" {
Expand Down
20 changes: 20 additions & 0 deletions core/peer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,26 @@ func TestPropagateEnvironment(t *testing.T) {
assert.Equal(t, expectedConfig, coreConfig)
}

func TestExternalBuilderConfigAsEnvVar(t *testing.T) {
defer viper.Reset()
viper.Set("peer.address", "localhost:8080")
viper.Set("chaincode.externalBuilders", "[{name: relative, path: relative/plugin_dir, propagateEnvironment: [ENVVAR_NAME_TO_PROPAGATE_FROM_PEER, GOPROXY]}, {name: absolute, path: /absolute/plugin_dir}]")
coreConfig, err := GlobalConfig()
require.NoError(t, err)

require.Equal(t, []ExternalBuilder{
{
Path: "relative/plugin_dir",
Name: "relative",
PropagateEnvironment: []string{"ENVVAR_NAME_TO_PROPAGATE_FROM_PEER", "GOPROXY"},
},
{
Path: "/absolute/plugin_dir",
Name: "absolute",
},
}, coreConfig.ExternalBuilders)
}

func TestMissingExternalBuilderPath(t *testing.T) {
defer viper.Reset()
viper.Set("peer.address", "localhost:8080")
Expand Down
1 change: 1 addition & 0 deletions sampleconfig/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ chaincode:
keepalive: 0

# enabled system chaincodes
# To override this property via env variable use CORE_CHAINCODE_SYSTEM: {"xxx:": "enable"}
system:
_lifecycle: enable
cscc: enable
Expand Down

0 comments on commit 52247b3

Please sign in to comment.