Skip to content

Commit

Permalink
[FAB-8847] Add ChannelConfigPath opt for SaveChannel
Browse files Browse the repository at this point in the history
This change adds a convenience method for using a named
file rather than supplying a Reader.

Change-Id: I535fe993c746d7bc8e46fca3f4c19de8743e6281
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Mar 13, 2018
1 parent 1b231db commit d84447e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
11 changes: 11 additions & 0 deletions pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"io/ioutil"
"math/rand"
"os"
"time"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
Expand Down Expand Up @@ -86,6 +87,7 @@ type requestOptions struct {
type SaveChannelRequest struct {
ChannelID string
ChannelConfig io.Reader // ChannelConfig data source
ChannelConfigPath string // Convenience option to use the named file as ChannelConfig reader
SigningIdentities []msp.Identity // Users that sign channel configuration
// TODO: support pre-signed signature blocks
}
Expand Down Expand Up @@ -596,6 +598,15 @@ func (rc *Client) SaveChannel(req SaveChannelRequest, options ...RequestOption)
return err
}

if req.ChannelConfigPath != "" {
configReader, err := os.Open(req.ChannelConfigPath)
if err != nil {
return errors.Wrapf(err, "opening channel config file failed")
}
defer configReader.Close()
req.ChannelConfig = configReader
}

if req.ChannelID == "" || req.ChannelConfig == nil {
return errors.New("must provide channel ID and channel config")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,11 @@ func TestSaveChannelSuccess(t *testing.T) {
t.Fatal(err)
}

// Test valid Save Channel request (success / filename)
err = cc.SaveChannel(SaveChannelRequest{ChannelID: "mychannel", ChannelConfigPath: channelConfig}, WithOrdererURL("example.com"))
if err != nil {
t.Fatal(err)
}
}

func TestSaveChannelFailure(t *testing.T) {
Expand Down
9 changes: 1 addition & 8 deletions test/integration/e2e/end_to_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package e2e

import (
"os"
"path"
"strconv"
"testing"
Expand Down Expand Up @@ -68,14 +67,8 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
t.Fatal(err)
}

ccReader, err := os.Open(path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"))
if err != nil {
t.Fatal(err)
}
defer ccReader.Close()

req := resmgmt.SaveChannelRequest{ChannelID: channelID,
ChannelConfig: ccReader,
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
SigningIdentities: []msp.Identity{adminIdentity}}
if err = resMgmtClient.SaveChannel(req); err != nil {
t.Fatal(err)
Expand Down
9 changes: 1 addition & 8 deletions test/integration/fab/channel_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package fab

import (
"os"
"path"
"strconv"
"testing"
Expand Down Expand Up @@ -51,13 +50,7 @@ func initializeLedgerTests(t *testing.T) (*fabsdk.FabricSDK, []string) {
t.Fatalf("creating peers failed: %v", err)
}

ccReader, err := os.Open(path.Join("../../../", metadata.ChannelConfigPath, channelConfigFile))
if err != nil {
t.Fatal(err)
}
defer ccReader.Close()

req := resmgmt.SaveChannelRequest{ChannelID: channelID, ChannelConfig: ccReader, SigningIdentities: []msp.Identity{adminIdentity}}
req := resmgmt.SaveChannelRequest{ChannelID: channelID, ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, channelConfigFile), SigningIdentities: []msp.Identity{adminIdentity}}
err = integration.InitializeChannel(sdk, orgName, req, targets)
if err != nil {
t.Fatalf("failed to ensure channel has been initialized: %s", err)
Expand Down
10 changes: 1 addition & 9 deletions test/integration/orgs/multiple_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package orgs

import (
"math"
"os"
"path"
"strconv"
"strings"
Expand Down Expand Up @@ -96,15 +95,8 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
t.Fatalf("failed to get org2AdminUser, err : %v", err)
}

// Create channel (or update if it already exists)
ccReader, err := os.Open(path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"))
if err != nil {
t.Fatal(err)
}
defer ccReader.Close()

req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
ChannelConfig: ccReader,
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.Identity{org1AdminUser, org2AdminUser}}
if err = chMgmtClient.SaveChannel(req); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit d84447e

Please sign in to comment.