-
Notifications
You must be signed in to change notification settings - Fork 0
/
configtxgen.go
100 lines (89 loc) · 2.3 KB
/
configtxgen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package runner
import (
"fmt"
"os/exec"
"path/filepath"
. "github.com/onsi/gomega"
"github.com/tedsuo/ifrit/ginkgomon"
)
// Configtxgen creates runners that call cryptogen functions.
type Configtxgen struct {
// The location of the configtxgen executable
Path string
// The channel ID
ChannelID string
// The profile used for the channel
Profile string
// The organization for this config channel
AsOrg string
// The fabric config directory
ConfigDir string
// The fabric config directory set in the env variable
EnvConfigDir string
// The directory to write the block file
Output string
}
func (c *Configtxgen) setupCommandEnv(cmd *exec.Cmd) {
if c.EnvConfigDir != "" {
configDir, err := filepath.Abs(c.EnvConfigDir)
Expect(err).NotTo(HaveOccurred())
cmd.Env = append(cmd.Env, fmt.Sprintf("FABRIC_CFG_PATH=%s", configDir))
}
}
// OutputBlock uses configtxgen to generate genesis block for fabric.
func (c *Configtxgen) OutputBlock(extraArgs ...string) *ginkgomon.Runner {
cmd := exec.Command(
c.Path,
append([]string{
"-outputBlock", c.Output,
"-profile", c.Profile,
"-channelID", c.ChannelID,
"-configPath", c.ConfigDir,
}, extraArgs...)...,
)
c.setupCommandEnv(cmd)
return ginkgomon.New(ginkgomon.Config{
Name: "config output block",
AnsiColorCode: "32m",
Command: cmd,
})
}
func (c *Configtxgen) OutputCreateChannelTx(extraArgs ...string) *ginkgomon.Runner {
cmd := exec.Command(
c.Path,
append([]string{
"-channelID", c.ChannelID,
"-outputCreateChannelTx", c.Output,
"-profile", c.Profile,
"-configPath", c.ConfigDir,
}, extraArgs...)...,
)
c.setupCommandEnv(cmd)
return ginkgomon.New(ginkgomon.Config{
Name: "config create channel",
AnsiColorCode: "33m",
Command: cmd,
})
}
func (c *Configtxgen) OutputAnchorPeersUpdate(extraArgs ...string) *ginkgomon.Runner {
cmd := exec.Command(
c.Path,
append([]string{
"-channelID", c.ChannelID,
"-outputAnchorPeersUpdate", c.Output,
"-profile", c.Profile,
"-asOrg", c.AsOrg,
"-configPath", c.ConfigDir,
}, extraArgs...)...,
)
c.setupCommandEnv(cmd)
return ginkgomon.New(ginkgomon.Config{
Name: "config update peer",
AnsiColorCode: "34m",
Command: cmd,
})
}