From 4144b2cf9f9153be9451f64848793ea2320621cb Mon Sep 17 00:00:00 2001 From: Priyansu Rout Date: Thu, 4 Jul 2024 23:39:36 +0530 Subject: [PATCH 1/3] Implement 'osnadmin channel info' subcommand and update tests #4892 --- cmd/osnadmin/main.go | 7 +- docs/source/commands/osnadminchannel.md | 77 ++++++++++++++++---- docs/wrappers/osnadmin_channel_postscript.md | 42 ++++++++--- docs/wrappers/osnadmin_channel_preamble.md | 7 +- internal/osnadmin/info.go | 21 ++++++ internal/osnadmin/list.go | 7 -- scripts/help_docs.sh | 2 +- 7 files changed, 128 insertions(+), 35 deletions(-) create mode 100644 internal/osnadmin/info.go diff --git a/cmd/osnadmin/main.go b/cmd/osnadmin/main.go index 464293ae515..aef9fe59094 100644 --- a/cmd/osnadmin/main.go +++ b/cmd/osnadmin/main.go @@ -54,6 +54,9 @@ func executeForArgs(args []string) (output string, exit int, err error) { list := channel.Command("list", "List channel information for an Ordering Service Node (OSN). If the channelID flag is set, more detailed information will be provided for that channel.") listChannelID := list.Flag("channelID", "Channel ID").Short('c').String() + info := channel.Command("info", "Get detailed information about a specific channel.") + infoChannelID := info.Flag("channelID", "Channel ID").Short('c').Required().String() + remove := channel.Command("remove", "Remove a channel from an Ordering Service Node (OSN).") removeChannelID := remove.Flag("channelID", "Channel ID").Short('c').Required().String() @@ -114,10 +117,12 @@ func executeForArgs(args []string) (output string, exit int, err error) { resp, err = osnadmin.Join(osnURL, marshaledConfigBlock, caCertPool, tlsClientCert) case list.FullCommand(): if *listChannelID != "" { - resp, err = osnadmin.ListSingleChannel(osnURL, *listChannelID, caCertPool, tlsClientCert) + resp, err = osnadmin.Info(osnURL, *listChannelID, caCertPool, tlsClientCert) break } resp, err = osnadmin.ListAllChannels(osnURL, caCertPool, tlsClientCert) + case info.FullCommand(): + resp, err = osnadmin.Info(osnURL, *infoChannelID, caCertPool, tlsClientCert) case remove.FullCommand(): resp, err = osnadmin.Remove(osnURL, *removeChannelID, caCertPool, tlsClientCert) } diff --git a/docs/source/commands/osnadminchannel.md b/docs/source/commands/osnadminchannel.md index 69bdd35c556..81dd5436045 100644 --- a/docs/source/commands/osnadminchannel.md +++ b/docs/source/commands/osnadminchannel.md @@ -15,9 +15,10 @@ each orderer. The `osnadmin channel` command has the following subcommands: - * join - * list - * remove +- join +- list +- info +- remove ## osnadmin channel ``` @@ -51,6 +52,9 @@ Subcommands: channelID flag is set, more detailed information will be provided for that channel. + channel info --channelID=CHANNELID + Get detailed information about a specific channel. + channel remove --channelID=CHANNELID Remove a channel from an Ordering Service Node (OSN). ``` @@ -111,6 +115,31 @@ Flags: ``` +## osnadmin channel info +``` +usage: osnadmin channel info --channelID=CHANNELID + +Get detailed information about a specific channel. + +Flags: + --help Show context-sensitive help (also try + --help-long and --help-man). + -o, --orderer-address=ORDERER-ADDRESS + Admin endpoint of the OSN + --ca-file=CA-FILE Path to file containing PEM-encoded TLS CA + certificate(s) for the OSN + --client-cert=CLIENT-CERT Path to file containing PEM-encoded X509 public + key to use for mutual TLS communication with + the OSN + --client-key=CLIENT-KEY Path to file containing PEM-encoded private key + to use for mutual TLS communication with the + OSN + --no-status Remove the HTTP status message from the command + output + -c, --channelID=CHANNELID Channel ID +``` + + ## osnadmin channel remove ``` usage: osnadmin channel remove --channelID=CHANNELID @@ -141,7 +170,7 @@ Flags: Here's an example of the `osnadmin channel join` command. -* Create and join a sample channel `mychannel` defined by the application channel genesis +- Create and join a sample channel `mychannel` defined by the application channel genesis block contained in file `mychannel-genesis-block.pb`. Use the orderer admin endpoint at `orderer.example.com:9443`. @@ -167,8 +196,8 @@ Here's an example of the `osnadmin channel join` command. Here are some examples of the `osnadmin channel list` command. -* Listing all the channels that the orderer has joined. -Note that the system channel will always be NULL because it is no longer supported from release v3.0 onwards. +- Listing all the channels that the orderer has joined. + Note that the system channel will always be NULL because it is no longer supported from release v3.0 onwards. ``` osnadmin channel list -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY @@ -188,18 +217,40 @@ Note that the system channel will always be NULL because it is no longer support Status 200 and the list of channels are returned. -* Using the `--channelID` flag to list more details for `mychannel`. +- Using the `--channelID` flag to list more details for `mychannel`. ``` osnadmin channel list -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channelID mychannel Status: 200 { - "name": "mychannel", - "url": "/participation/v1/channels/mychannel", - "consensusRelation": "consenter", - "status": "active", - "height": 3 + "name": "mychannel", + "url": "/participation/v1/channels/mychannel", + "consensusRelation": "consenter", + "status": "active", + "height": 3 + } + + ``` + + Status 200 and the details of the channels are returned. + +### osnadmin channel info example + +Here are some examples of the `osnadmin channel info` command. + +- Using the `--channel-id` flag to get detailed information for mychannel from the orderer at `orderer.example.com:9443`. + + ``` + osnadmin channel info -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channel-id mychannel + + Status: 200 + { + "name": "mychannel", + "url": "/participation/v1/channels/mychannel", + "consensusRelation": "consenter", + "status": "active", + "height": 3 } ``` @@ -210,7 +261,7 @@ Note that the system channel will always be NULL because it is no longer support Here's an example of the `osnadmin channel remove` command. -* Removing channel `mychannel` from the orderer at `orderer.example.com:9443`. +- Removing channel `mychannel` from the orderer at `orderer.example.com:9443`. ``` osnadmin channel remove -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channelID mychannel diff --git a/docs/wrappers/osnadmin_channel_postscript.md b/docs/wrappers/osnadmin_channel_postscript.md index 56c9f57a803..7fbc4d6ba5d 100644 --- a/docs/wrappers/osnadmin_channel_postscript.md +++ b/docs/wrappers/osnadmin_channel_postscript.md @@ -4,7 +4,7 @@ Here's an example of the `osnadmin channel join` command. -* Create and join a sample channel `mychannel` defined by the application channel genesis +- Create and join a sample channel `mychannel` defined by the application channel genesis block contained in file `mychannel-genesis-block.pb`. Use the orderer admin endpoint at `orderer.example.com:9443`. @@ -30,8 +30,8 @@ Here's an example of the `osnadmin channel join` command. Here are some examples of the `osnadmin channel list` command. -* Listing all the channels that the orderer has joined. -Note that the system channel will always be NULL because it is no longer supported from release v3.0 onwards. +- Listing all the channels that the orderer has joined. + Note that the system channel will always be NULL because it is no longer supported from release v3.0 onwards. ``` osnadmin channel list -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY @@ -51,18 +51,40 @@ Note that the system channel will always be NULL because it is no longer support Status 200 and the list of channels are returned. -* Using the `--channelID` flag to list more details for `mychannel`. +- Using the `--channelID` flag to list more details for `mychannel`. ``` osnadmin channel list -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channelID mychannel Status: 200 { - "name": "mychannel", - "url": "/participation/v1/channels/mychannel", - "consensusRelation": "consenter", - "status": "active", - "height": 3 + "name": "mychannel", + "url": "/participation/v1/channels/mychannel", + "consensusRelation": "consenter", + "status": "active", + "height": 3 + } + + ``` + + Status 200 and the details of the channels are returned. + +### osnadmin channel info example + +Here are some examples of the `osnadmin channel info` command. + +- Using the `--channel-id` flag to get detailed information for mychannel from the orderer at `orderer.example.com:9443`. + + ``` + osnadmin channel info -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channel-id mychannel + + Status: 200 + { + "name": "mychannel", + "url": "/participation/v1/channels/mychannel", + "consensusRelation": "consenter", + "status": "active", + "height": 3 } ``` @@ -73,7 +95,7 @@ Note that the system channel will always be NULL because it is no longer support Here's an example of the `osnadmin channel remove` command. -* Removing channel `mychannel` from the orderer at `orderer.example.com:9443`. +- Removing channel `mychannel` from the orderer at `orderer.example.com:9443`. ``` osnadmin channel remove -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channelID mychannel diff --git a/docs/wrappers/osnadmin_channel_preamble.md b/docs/wrappers/osnadmin_channel_preamble.md index 02b975506de..5688ca0542b 100644 --- a/docs/wrappers/osnadmin_channel_preamble.md +++ b/docs/wrappers/osnadmin_channel_preamble.md @@ -10,6 +10,7 @@ each orderer. The `osnadmin channel` command has the following subcommands: - * join - * list - * remove +- join +- list +- info +- remove diff --git a/internal/osnadmin/info.go b/internal/osnadmin/info.go new file mode 100644 index 00000000000..1e633bc7710 --- /dev/null +++ b/internal/osnadmin/info.go @@ -0,0 +1,21 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package osnadmin + +import ( + "crypto/tls" + "crypto/x509" + "fmt" + "net/http" +) + +// Lists a single channel an OSN is a member of. +func Info(osnURL, channelID string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate) (*http.Response, error) { + url := fmt.Sprintf("%s/participation/v1/channels/%s", osnURL, channelID) + + return httpGet(url, caCertPool, tlsClientCert) +} diff --git a/internal/osnadmin/list.go b/internal/osnadmin/list.go index c997fb7005c..d72611d1d38 100644 --- a/internal/osnadmin/list.go +++ b/internal/osnadmin/list.go @@ -19,10 +19,3 @@ func ListAllChannels(osnURL string, caCertPool *x509.CertPool, tlsClientCert tls return httpGet(url, caCertPool, tlsClientCert) } - -// Lists a single channel an OSN is a member of. -func ListSingleChannel(osnURL, channelID string, caCertPool *x509.CertPool, tlsClientCert tls.Certificate) (*http.Response, error) { - url := fmt.Sprintf("%s/participation/v1/channels/%s", osnURL, channelID) - - return httpGet(url, caCertPool, tlsClientCert) -} diff --git a/scripts/help_docs.sh b/scripts/help_docs.sh index f2108c38cb5..5eeadae0375 100755 --- a/scripts/help_docs.sh +++ b/scripts/help_docs.sh @@ -134,7 +134,7 @@ generateOrCheck \ docs/wrappers/configtxlator_postscript.md \ "${commands[@]}" -commands=("osnadmin channel" "osnadmin channel join" "osnadmin channel list" "osnadmin channel remove") +commands=("osnadmin channel" "osnadmin channel join" "osnadmin channel list" "osnadmin channel info" "osnadmin channel remove") generateOrCheck \ docs/source/commands/osnadminchannel.md \ docs/wrappers/osnadmin_channel_preamble.md \ From 09205c3c74bdbd6b4ec50a1228d5a51e0799dc12 Mon Sep 17 00:00:00 2001 From: Priyansu rout <65958054+Priyansurout@users.noreply.github.com> Date: Mon, 8 Jul 2024 07:43:24 +0530 Subject: [PATCH 2/3] Update docs/wrappers/osnadmin_channel_postscript.md Co-authored-by: Tatsuya Sato Signed-off-by: Priyansu rout <65958054+Priyansurout@users.noreply.github.com> --- docs/wrappers/osnadmin_channel_postscript.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/wrappers/osnadmin_channel_postscript.md b/docs/wrappers/osnadmin_channel_postscript.md index 7fbc4d6ba5d..d31669de7fe 100644 --- a/docs/wrappers/osnadmin_channel_postscript.md +++ b/docs/wrappers/osnadmin_channel_postscript.md @@ -76,7 +76,7 @@ Here are some examples of the `osnadmin channel info` command. - Using the `--channel-id` flag to get detailed information for mychannel from the orderer at `orderer.example.com:9443`. ``` - osnadmin channel info -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channel-id mychannel + osnadmin channel info -o orderer.example.com:9443 --ca-file $CA_FILE --client-cert $CLIENT_CERT --client-key $CLIENT_KEY --channelID mychannel Status: 200 { From ef7c7c24f706a173526cafe659b47bbbda639965 Mon Sep 17 00:00:00 2001 From: Priyansu rout <65958054+Priyansurout@users.noreply.github.com> Date: Mon, 8 Jul 2024 07:43:40 +0530 Subject: [PATCH 3/3] Update docs/wrappers/osnadmin_channel_postscript.md Co-authored-by: Tatsuya Sato Signed-off-by: Priyansu rout <65958054+Priyansurout@users.noreply.github.com> --- docs/wrappers/osnadmin_channel_postscript.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/wrappers/osnadmin_channel_postscript.md b/docs/wrappers/osnadmin_channel_postscript.md index d31669de7fe..d656dca10cd 100644 --- a/docs/wrappers/osnadmin_channel_postscript.md +++ b/docs/wrappers/osnadmin_channel_postscript.md @@ -80,11 +80,11 @@ Here are some examples of the `osnadmin channel info` command. Status: 200 { - "name": "mychannel", - "url": "/participation/v1/channels/mychannel", - "consensusRelation": "consenter", - "status": "active", - "height": 3 + "name": "mychannel", + "url": "/participation/v1/channels/mychannel", + "consensusRelation": "consenter", + "status": "active", + "height": 3 } ```