Skip to content

Commit e1602b6

Browse files
committed
added to OSN new handler for update config of channel
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent e06da3c commit e1602b6

File tree

11 files changed

+616
-30
lines changed

11 files changed

+616
-30
lines changed

cmd/osnadmin/main.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func executeForArgs(args []string) (output string, exit int, err error) {
5858
remove := channel.Command("remove", "Remove a channel from an Ordering Service Node (OSN).")
5959
removeChannelID := remove.Flag("channelID", "Channel ID").Short('c').Required().String()
6060

61+
update := channel.Command("update", "Update an Ordering Service Node (OSN) to a channel.")
62+
updateChannelID := update.Flag("channelID", "Channel ID").Short('c').Required().String()
63+
configUpdateEnvelopePath := update.Flag("config-update-envelope", "Path to the file containing an up-to-date config update envelope for the channel").Short('e').Required().String()
64+
6165
command, err := app.Parse(args)
6266
if err != nil {
6367
return "", 1, err
@@ -105,6 +109,19 @@ func executeForArgs(args []string) (output string, exit int, err error) {
105109
}
106110
}
107111

112+
var marshaledConfigEnvelope []byte
113+
if *configUpdateEnvelopePath != "" {
114+
marshaledConfigEnvelope, err = os.ReadFile(*configUpdateEnvelopePath)
115+
if err != nil {
116+
return "", 1, fmt.Errorf("reading config updte envelope: %s", err)
117+
}
118+
119+
err = validateEnvelopeChannelID(marshaledConfigEnvelope, *updateChannelID)
120+
if err != nil {
121+
return "", 1, err
122+
}
123+
}
124+
108125
//
109126
// call the underlying implementations
110127
//
@@ -121,6 +138,8 @@ func executeForArgs(args []string) (output string, exit int, err error) {
121138
resp, err = osnadmin.ListAllChannels(osnURL, caCertPool, tlsClientCert)
122139
case remove.FullCommand():
123140
resp, err = osnadmin.Remove(osnURL, *removeChannelID, caCertPool, tlsClientCert)
141+
case update.FullCommand():
142+
resp, err = osnadmin.Update(osnURL, marshaledConfigEnvelope, caCertPool, tlsClientCert)
124143
}
125144
if err != nil {
126145
return errorOutput(err), 1, nil
@@ -186,3 +205,24 @@ func validateBlockChannelID(blockBytes []byte, channelID string) error {
186205

187206
return nil
188207
}
208+
209+
func validateEnvelopeChannelID(envelopeBytes []byte, channelID string) error {
210+
envelope := &common.Envelope{}
211+
err := proto.Unmarshal(envelopeBytes, envelope)
212+
if err != nil {
213+
return fmt.Errorf("unmarshalling envelope: %s", err)
214+
}
215+
216+
envelopeChannelID, err := protoutil.GetChannelIDFromEnvelope(envelope)
217+
if err != nil {
218+
return err
219+
}
220+
221+
// quick sanity check that the orderer admin is joining
222+
// the channel they think they're joining.
223+
if channelID != envelopeChannelID {
224+
return fmt.Errorf("specified --channelID %s does not match channel ID %s in config update envelope", channelID, envelopeChannelID)
225+
}
226+
227+
return nil
228+
}

cmd/osnadmin/mocks/channel_management.go

Lines changed: 97 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/osnadmin/osnadmin_suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type channelManagement interface {
2121
ChannelList() types.ChannelList
2222
ChannelInfo(channelID string) (types.ChannelInfo, error)
2323
JoinChannel(channelID string, configBlock *cb.Block) (types.ChannelInfo, error)
24+
UpdateChannel(channelID string, configUpdateEnvelope *cb.Envelope) (types.ChannelInfo, error)
2425
RemoveChannel(channelID string) error
2526
}
2627

docs/source/commands/osnadminchannel.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Subcommands:
5353
5454
channel remove --channelID=CHANNELID
5555
Remove a channel from an Ordering Service Node (OSN).
56+
57+
channel update --channelID=CHANNELID --config-update-envelope=CONFIG-UPDATE-ENVELOPE
58+
Update an Ordering Service Node (OSN) to a channel.
5659
```
5760

5861

@@ -135,6 +138,33 @@ Flags:
135138
-c, --channelID=CHANNELID Channel ID
136139
```
137140

141+
## osnadmin channel update
142+
```
143+
usage: osnadmin channel update --channelID=CHANNELID --config-update-envelope=CONFIG-UPDATE-ENVELOPE
144+
145+
Update an Ordering Service Node (OSN) to a channel.
146+
147+
Flags:
148+
--help Show context-sensitive help (also try
149+
--help-long and --help-man).
150+
-o, --orderer-address=ORDERER-ADDRESS
151+
Admin endpoint of the OSN
152+
--ca-file=CA-FILE Path to file containing PEM-encoded TLS CA
153+
certificate(s) for the OSN
154+
--client-cert=CLIENT-CERT Path to file containing PEM-encoded X509 public
155+
key to use for mutual TLS communication with
156+
the OSN
157+
--client-key=CLIENT-KEY Path to file containing PEM-encoded private key
158+
to use for mutual TLS communication with the
159+
OSN
160+
--no-status Remove the HTTP status message from the command
161+
output
162+
-c, --channelID=CHANNELID Channel ID
163+
-b, --config-block=CONFIG-BLOCK
164+
Path to the file containing an up-to-date
165+
config block for the channel
166+
```
167+
138168
## Example Usage
139169

140170
### osnadmin channel join examples
@@ -220,4 +250,30 @@ Here's an example of the `osnadmin channel remove` command.
220250

221251
Status 204 is returned upon successful removal of a channel.
222252

253+
### osnadmin channel update examples
254+
255+
Here's an example of the `osnadmin channel update` command.
256+
257+
* Update the example of the `my channel` channel defined by the modified config
258+
contained in the `my channel-config-envelope.pb` file.
259+
Use the endpoint of the order administrator
260+
at `order.example.com:9443`.
261+
262+
```
263+
osnadmin channel update -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channelID mychannel --config-update-envelope mychannel-genesis-block.pb
264+
265+
Status: 201
266+
{
267+
"name": "mychannel",
268+
"url": "/participation/v1/channels/mychannel",
269+
"consensusRelation": "consenter",
270+
"status": "active",
271+
"height": 1
272+
}
273+
274+
```
275+
276+
Status 201 and the channel details are returned indicating that the channel has been
277+
successfully updated.
278+
223279
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.

integration/channelparticipation/channel_participation.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,45 @@ func GenerateJoinRequest(url, channel string, blockBytes []byte) *http.Request {
6565
return req
6666
}
6767

68+
func Update(n *nwo.Network, o *nwo.Orderer, channel string, envelope *common.Envelope, expectedChannelInfo ChannelInfo) {
69+
envelopeBytes, err := proto.Marshal(envelope)
70+
Expect(err).NotTo(HaveOccurred())
71+
72+
protocol := "http"
73+
if n.TLSEnabled {
74+
protocol = "https"
75+
}
76+
url := fmt.Sprintf("%s://127.0.0.1:%d/participation/v1/channels", protocol, n.OrdererPort(o, nwo.AdminPort))
77+
req := GenerateUpdateRequest(url, channel, envelopeBytes)
78+
authClient, unauthClient := nwo.OrdererOperationalClients(n, o)
79+
80+
client := unauthClient
81+
if n.TLSEnabled {
82+
client = authClient
83+
}
84+
body := doBody(client, req)
85+
c := &ChannelInfo{}
86+
err = json.Unmarshal(body, c)
87+
Expect(err).NotTo(HaveOccurred())
88+
Expect(*c).To(Equal(expectedChannelInfo))
89+
}
90+
91+
func GenerateUpdateRequest(url, channel string, envelopeBytes []byte) *http.Request {
92+
updateBody := new(bytes.Buffer)
93+
writer := multipart.NewWriter(updateBody)
94+
part, err := writer.CreateFormFile("config-update-envelope", fmt.Sprintf("%s-update.envelope", channel))
95+
Expect(err).NotTo(HaveOccurred())
96+
part.Write(envelopeBytes)
97+
err = writer.Close()
98+
Expect(err).NotTo(HaveOccurred())
99+
100+
req, err := http.NewRequest(http.MethodPost, url, updateBody)
101+
Expect(err).NotTo(HaveOccurred())
102+
req.Header.Set("Content-Type", writer.FormDataContentType())
103+
104+
return req
105+
}
106+
68107
func doBody(client *http.Client, req *http.Request) []byte {
69108
resp, err := client.Do(req)
70109
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)