Skip to content

Commit 08750ef

Browse files
committed
added to OSN new handler for update config of channel
Signed-off-by: Fedor Partanskiy <fredprtnsk@gmail.com>
1 parent e06da3c commit 08750ef

File tree

16 files changed

+955
-33
lines changed

16 files changed

+955
-33
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: 57 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,34 @@ Flags:
135138
-c, --channelID=CHANNELID Channel ID
136139
```
137140

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

140171
### osnadmin channel join examples
@@ -220,4 +251,30 @@ Here's an example of the `osnadmin channel remove` command.
220251

221252
Status 204 is returned upon successful removal of a channel.
222253

254+
### osnadmin channel update examples
255+
256+
Here's an example of the `osnadmin channel update` command.
257+
258+
* Update the example of the `my channel` channel defined by the modified config
259+
contained in the `my channel-config-envelope.pb` file.
260+
Use the endpoint of the order administrator
261+
at `order.example.com:9443`.
262+
263+
```
264+
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
265+
266+
Status: 201
267+
{
268+
"name": "mychannel",
269+
"url": "/participation/v1/channels/mychannel",
270+
"consensusRelation": "consenter",
271+
"status": "active",
272+
"height": 1
273+
}
274+
275+
```
276+
277+
Status 201 and the channel details are returned indicating that the channel has been
278+
successfully updated.
279+
223280
<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>.

docs/wrappers/osnadmin_channel_postscript.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,30 @@ Here's an example of the `osnadmin channel remove` command.
8383

8484
Status 204 is returned upon successful removal of a channel.
8585

86+
### osnadmin channel update examples
87+
88+
Here's an example of the `osnadmin channel update` command.
89+
90+
* Update the example of the `my channel` channel defined by the modified config
91+
contained in the `my channel-config-envelope.pb` file.
92+
Use the endpoint of the order administrator
93+
at `order.example.com:9443`.
94+
95+
```
96+
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
97+
98+
Status: 201
99+
{
100+
"name": "mychannel",
101+
"url": "/participation/v1/channels/mychannel",
102+
"consensusRelation": "consenter",
103+
"status": "active",
104+
"height": 1
105+
}
106+
107+
```
108+
109+
Status 201 and the channel details are returned indicating that the channel has been
110+
successfully updated.
111+
86112
<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>.

0 commit comments

Comments
 (0)