Skip to content

Commit

Permalink
[FAB-9887] Generate docs for client commands
Browse files Browse the repository at this point in the history
Expands the document generation script to add the CLI
for identity, affiliation, and certificate client commands
to the docs.

Change-Id: Ia85c7045558286883b7234b2c5be07320de8e37d
Signed-off-by: Saad Karim <[email protected]>
  • Loading branch information
Saad Karim committed May 16, 2018
1 parent b053b4f commit e1d4490
Show file tree
Hide file tree
Showing 3 changed files with 303 additions and 27 deletions.
172 changes: 171 additions & 1 deletion docs/source/clientcli.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
=======================
Fabric-CA Client's CLI
======================
=======================

::

Expand Down Expand Up @@ -50,3 +51,172 @@ Fabric-CA Client's CLI
-u, --url string URL of fabric-ca-server (default "http://localhost:7054")
Use "fabric-ca-client [command] --help" for more information about a command.

Identity Command
==================

::

Manage identities
Usage:
fabric-ca-client identity [command]
Available Commands:
add Add identity
list List identities
modify Modify identity
remove Remove identity
-----------------------------
Add an identity
Usage:
fabric-ca-client identity add <id> [flags]
Examples:
fabric-ca-client identity add user1 --type peer
Flags:
--affiliation string The identity's affiliation
--attrs stringSlice A list of comma-separated attributes of the form <name>=<value> (e.g. foo=foo1,bar=bar1)
--json string JSON string for adding a new identity
--maxenrollments int The maximum number of times the secret can be reused to enroll (default CA's Max Enrollment)
--secret string The enrollment secret for the identity being added
--type string Type of identity being registered (e.g. 'peer, app, user') (default "user")
-----------------------------
List identities visible to caller
Usage:
fabric-ca-client identity list [flags]
Flags:
--id string Get identity information from the fabric-ca server
-----------------------------
Modify an existing identity
Usage:
fabric-ca-client identity modify <id> [flags]
Examples:
fabric-ca-client identity modify user1 --type peer
Flags:
--affiliation string The identity's affiliation
--attrs stringSlice A list of comma-separated attributes of the form <name>=<value> (e.g. foo=foo1,bar=bar1)
--json string JSON string for modifying an existing identity
--maxenrollments int The maximum number of times the secret can be reused to enroll
--secret string The enrollment secret for the identity
--type string Type of identity being registered (e.g. 'peer, app, user')
-----------------------------
Remove an identity
Usage:
fabric-ca-client identity remove <id> [flags]
Examples:
fabric-ca-client identity remove user1
Flags:
--force Forces removing your own identity

Affiliation Command
=====================

::

Manage affiliations
Usage:
fabric-ca-client affiliation [command]
Available Commands:
add Add affiliation
list List affiliations
modify Modify affiliation
remove Remove affiliation
-----------------------------
Add affiliation
Usage:
fabric-ca-client affiliation add <affiliation> [flags]
Flags:
--force Creates parent affiliations if they do not exist
-----------------------------
List affiliations visible to caller
Usage:
fabric-ca-client affiliation list [flags]
Flags:
--affiliation string Get affiliation information from the fabric-ca server
-----------------------------
Modify existing affiliation
Usage:
fabric-ca-client affiliation modify <affiliation> [flags]
Flags:
--force Forces identities using old affiliation to use new affiliation
--name string Rename the affiliation
-----------------------------
Remove affiliation
Usage:
fabric-ca-client affiliation remove <affiliation> [flags]
Flags:
--force Forces removal of any child affiliations and any identities associated with removed affiliations

Certificate Command
=====================

::

Manage certificates
Usage:
fabric-ca-client certificate [command]
Available Commands:
list List certificates
-----------------------------
List all certificates which are visible to the caller and match the flags
Usage:
fabric-ca-client certificate list [flags]
Examples:
fabric-ca-client certificate list --id admin --expiration 2018-01-01::2018-01-30
fabric-ca-client certificate list --id admin --expiration 2018-01-01T01:30:00z::2018-01-30T11:30:00z
fabric-ca-client certificate list --id admin --expiration -30d::-15d
Flags:
--aki string Get certificates for this AKI
--expiration string Get certificates which expire between the UTC timestamp (RFC3339 format) or duration specified (e.g. <begin_time>::<end_time>)
--id string Get certificates for this enrollment ID
--notexpired Don't return expired certificates
--notrevoked Don't return revoked certificates
--revocation string Get certificates that were revoked between the UTC timestamp (RFC3339 format) or duration specified (e.g. <begin_time>::<end_time>)
--serial string Get certificates for this serial number
1 change: 1 addition & 0 deletions docs/source/servercli.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
=======================
Fabric-CA Server's CLI
=======================

Expand Down
157 changes: 131 additions & 26 deletions scripts/regenDocs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

######################################################################
#
Expand All @@ -17,39 +22,139 @@ echo "Making docs..."
# Command Line Flag Generation
######################################################################

function generateGlobalCLI {
echo "Generating Global CLI..."

# RST specific syntax to indicate a code a block
echo -e "=======================" >> servercli.rst
echo -e "Fabric-CA Server's CLI" >> servercli.rst
echo -e "=======================\n" >> servercli.rst
echo -e "::\n" >> servercli.rst

echo -e "=======================" > clientcli.rst
echo -e "Fabric-CA Client's CLI" >> clientcli.rst
echo -e "=======================\n" >> clientcli.rst
echo -e "::\n" >> clientcli.rst

# Direct the CLI help message to a temp file
fabric-ca-server > servercli_temp.rst
fabric-ca-client > clientcli_temp.rst

# Sanitize the CLI file to remove any machine specific information and provide a generic CLI
sed -i -e 's/home directory (default.*/home directory (default "$HOME\/.fabric-ca-client")/' clientcli_temp.rst
sed -i -e 's/enrollment (default.*/enrollment (default "$HOSTNAME")/' clientcli_temp.rst
sed -i -e 's/home directory (default.*/home directory (default "\/etc\/hyperledger\/fabric-ca")/' servercli_temp.rst

# Insert a few spaces in front of all the lines in temp files created above (RST formatting purposes)
sed -i -e 's/^/ /' servercli_temp.rst
sed -i -e 's/^/ /' clientcli_temp.rst

# Append temp files to ones created earlier
cat servercli_temp.rst >> servercli.rst
cat clientcli_temp.rst >> clientcli.rst
}

function generateIdentityCLI {
echo "Generating Identity Command CLI..."

echo -e "\nIdentity Command" >> clientcli.rst
echo -e "==================\n" >> clientcli.rst
echo -e "::\n" >> clientcli.rst

fabric-ca-client identity -h >> identity_cmd.rst
sed -i -e '/Global Flags:/,$d' identity_cmd.rst
printf '%s\n\n' '-----------------------------' >> identity_cmd.rst

fabric-ca-client identity add -h > identity_add_cmd.rst
sed -i -e '/Global Flags:/,$d' identity_add_cmd.rst
cat identity_add_cmd.rst >> identity_cmd.rst
printf '%s\n\n' '-----------------------------' >> identity_cmd.rst

fabric-ca-client identity list -h > identity_list_cmd.rst
sed -i -e '/Global Flags:/,$d' identity_list_cmd.rst
cat identity_list_cmd.rst >> identity_cmd.rst
printf '%s\n\n' '-----------------------------' >> identity_cmd.rst

fabric-ca-client identity modify -h > identity_modify_cmd.rst
sed -i -e '/Global Flags:/,$d' identity_modify_cmd.rst
cat identity_modify_cmd.rst >> identity_cmd.rst
printf '%s\n\n' '-----------------------------' >> identity_cmd.rst

fabric-ca-client identity remove -h > identity_remove_cmd.rst
sed -i -e '/Global Flags:/,$d' identity_remove_cmd.rst
cat identity_remove_cmd.rst >> identity_cmd.rst

sed -i -e 's/^/ /' identity_cmd.rst
cat identity_cmd.rst >> clientcli.rst
}

function generateAffiliationCLI {
echo "Generating Affiliation Command CLI..."

echo -e "\nAffiliation Command" >> clientcli.rst
echo -e "=====================\n" >> clientcli.rst
echo -e "::\n" >> clientcli.rst

fabric-ca-client affiliation -h >> affiliation_cmd.rst
sed -i -e '/Global Flags:/,$d' affiliation_cmd.rst
printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst

fabric-ca-client affiliation add -h > affiliation_add_cmd.rst
sed -i -e '/Global Flags:/,$d' affiliation_add_cmd.rst
cat affiliation_add_cmd.rst >> affiliation_cmd.rst
printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst

fabric-ca-client affiliation list -h > affiliation_list_cmd.rst
sed -i -e '/Global Flags:/,$d' affiliation_list_cmd.rst
cat affiliation_list_cmd.rst >> affiliation_cmd.rst
printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst

fabric-ca-client affiliation modify -h > affiliation_modify_cmd.rst
sed -i -e '/Global Flags:/,$d' affiliation_modify_cmd.rst
cat affiliation_modify_cmd.rst >> affiliation_cmd.rst
printf '%s\n\n' '-----------------------------' >> affiliation_cmd.rst

fabric-ca-client affiliation remove -h > affiliation_remove_cmd.rst
sed -i -e '/Global Flags:/,$d' affiliation_remove_cmd.rst
cat affiliation_remove_cmd.rst >> affiliation_cmd.rst

sed -i -e 's/^/ /' affiliation_cmd.rst
cat affiliation_cmd.rst >> clientcli.rst
}

function generateCertificateCLI {
echo "Generating Certificate Command CLI..."

echo -e "\nCertificate Command" >> clientcli.rst
echo -e "=====================\n" >> clientcli.rst
echo -e "::\n" >> clientcli.rst

fabric-ca-client certificate -h >> certificate_cmd.rst
sed -i -e '/Global Flags:/,$d' certificate_cmd.rst
printf '%s\n\n' '-----------------------------' >> certificate_cmd.rst

fabric-ca-client certificate list -h > certificate_list_cmd.rst
sed -i -e '/Global Flags:/,$d' certificate_list_cmd.rst
cat certificate_list_cmd.rst >> certificate_cmd.rst

sed -i -e 's/^/ /' certificate_cmd.rst
cat certificate_cmd.rst >> clientcli.rst
}


fabric_ca=$GOPATH/src/github.com/hyperledger/fabric-ca
docsdir=$fabric_ca/docs/source
export PATH=$PATH:$fabric_ca/bin

temp=$docsdir/temp
rm -rf $temp
mkdir -p $temp
cd $temp

# RST specific syntax to indicate a code a block
echo -e "Fabric-CA Server's CLI" > servercli.rst
echo -e "=======================\n" >> servercli.rst
echo -e "::\n" >> servercli.rst

echo -e "Fabric-CA Client's CLI" > clientcli.rst
echo -e "======================\n" >> clientcli.rst
echo -e "::\n" >> clientcli.rst

# Direct the CLI help message to a temp file
fabric-ca-server > servercli_temp.rst
fabric-ca-client > clientcli_temp.rst

# Sanitize the CLI file to remove any machine specific information and provide a generic CLI
sed -i -e 's/home directory (default.*/home directory (default "$HOME\/.fabric-ca-client")/' clientcli_temp.rst
sed -i -e 's/enrollment (default.*/enrollment (default "$HOSTNAME")/' clientcli_temp.rst
sed -i -e 's/home directory (default.*/home directory (default "\/etc\/hyperledger\/fabric-ca")/' servercli_temp.rst

# Insert a few spaces in front of all the lines in temp files created above (RST formatting purposes)
sed -i -e 's/^/ /' servercli_temp.rst
sed -i -e 's/^/ /' clientcli_temp.rst

# Append temp files to ones created earlier
cat servercli_temp.rst >> servercli.rst
cat clientcli_temp.rst >> clientcli.rst
generateGlobalCLI
generateIdentityCLI
generateAffiliationCLI
generateCertificateCLI

mv servercli.rst $docsdir/servercli.rst
mv clientcli.rst $docsdir/clientcli.rst
Expand Down Expand Up @@ -107,4 +212,4 @@ cd $docsdir
if [[ $(git status . --porcelain --untracked-file=no) ]]; then
echo "ERROR: New readme files generated, commit changes before doing push"
exit 1
fi
fi

0 comments on commit e1d4490

Please sign in to comment.