Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'osnadmin channel info' subcommand and update tests #4890 #4919

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/osnadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now we have two ways of getting the same information about a channel. Why do we need that?
Renaming the existing API is not a good idea as it might break existing tools that use the current CLI.

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)
}
Expand Down
77 changes: 64 additions & 13 deletions docs/source/commands/osnadminchannel.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ each orderer.

The `osnadmin channel` command has the following subcommands:

* join
* list
* remove
- join
- list
- info
- remove

## osnadmin channel
```
Expand Down Expand Up @@ -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).
```
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`.

Expand All @@ -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
Expand All @@ -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
}

```
Expand All @@ -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
Expand Down
42 changes: 32 additions & 10 deletions docs/wrappers/osnadmin_channel_postscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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
Expand All @@ -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
Comment on lines +61 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Using the `--channel-id` flag to get detailed information for mychannel from the orderer at `orderer.example.com:9443`.
- Using the `--channelID` 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
Priyansurout marked this conversation as resolved.
Show resolved Hide resolved

Status: 200
{
"name": "mychannel",
"url": "/participation/v1/channels/mychannel",
"consensusRelation": "consenter",
"status": "active",
"height": 3
Priyansurout marked this conversation as resolved.
Show resolved Hide resolved
}

```
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions docs/wrappers/osnadmin_channel_preamble.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ each orderer.

The `osnadmin channel` command has the following subcommands:

* join
* list
* remove
- join
- list
- info
- remove
21 changes: 21 additions & 0 deletions internal/osnadmin/info.go
Original file line number Diff line number Diff line change
@@ -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)
}
7 changes: 0 additions & 7 deletions internal/osnadmin/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion scripts/help_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Loading