Skip to content

Commit

Permalink
[FAB-7990] Fix debug flag
Browse files Browse the repository at this point in the history
Debug flag was not being respected for
identity and affiliation list commands

Change-Id: I0cab82cc38aaf39a4270774999c32b956df02050
Signed-off-by: Saad Karim <skarim@us.ibm.com>
  • Loading branch information
Saad Karim committed Feb 7, 2018
1 parent 4dba361 commit 9a45730
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/fabric-ca-client/affiliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func printChildren(children []api.AffiliationInfo, level int) {
for i := 0; i < level; i++ {
spaces = spaces + " "
}
fmt.Printf("%saffiliation :%s\n", spaces, child.Name)
fmt.Printf("%saffiliation: %s\n", spaces, child.Name)
printChildren(child.Affiliations, level+1)
}
}
4 changes: 4 additions & 0 deletions cmd/fabric-ca-client/clientcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type ClientCmd struct {
dynamicIdentity identityArgs
// Dynamically configuring affiliations
dynamicAffiliation affiliationArgs
// Enable debug level logging
debug bool
}

// NewCommand returns new ClientCmd ready for running
Expand Down Expand Up @@ -160,6 +162,7 @@ func (c *ClientCmd) init() {
},
})
c.registerFlags()
log.Level = log.LevelInfo
}

// registerFlags registers command flags with viper
Expand Down Expand Up @@ -190,6 +193,7 @@ func (c *ClientCmd) registerFlags() {
"Hostname to include in the certificate signing request during enrollment")
pflags.StringSliceVarP(
&c.cfgCsrNames, "csr.names", "", nil, "A list of comma-separated CSR names of the form <name>=<value> (e.g. C=CA,O=Org1)")
pflags.BoolVarP(&c.debug, "debug", "d", false, "Enable debug level logging")

c.clientCfg = &lib.ClientConfig{}
tags := map[string]string{
Expand Down
4 changes: 4 additions & 0 deletions cmd/fabric-ca-client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ bccsp:
func (c *ClientCmd) configInit() error {
var err error

if c.debug {
log.Level = log.LevelDebug
}

c.cfgFileName, c.homeDirectory, err = util.ValidateAndReturnAbsConf(c.cfgFileName, c.homeDirectory, cmdName)
if err != nil {
return err
Expand Down
30 changes: 30 additions & 0 deletions cmd/fabric-ca-client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"time"

"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/log"
"github.com/hyperledger/fabric-ca/api"
"github.com/hyperledger/fabric-ca/lib"
"github.com/hyperledger/fabric-ca/lib/attr"
Expand Down Expand Up @@ -2056,6 +2057,35 @@ func TestHomeDirectory(t *testing.T) {

}

func TestDebugSetting(t *testing.T) {
os.RemoveAll(testdataDir)
defer os.RemoveAll(testdataDir)

srv = lib.TestGetServer(serverPort, testdataDir, "", -1, t)
err := srv.Start()
util.FatalError(t, err, "Failed to start server")
defer srv.Stop()

err = RunMain([]string{cmdName, "enroll", "-u", enrollURL})
util.FatalError(t, err, "Failed to enroll user")

err = RunMain([]string{cmdName, "affiliation", "list"})
assert.NoError(t, err, "Failed to return all affiliations")
assert.Equal(t, 2, log.Level) // Default level for listing affiliations is warning (2)

err = RunMain([]string{cmdName, "affiliation", "list", "-d"})
assert.NoError(t, err, "Failed to return all affiliations")
assert.Equal(t, 0, log.Level) // With '-d' flag log level should be debug (0)

err = RunMain([]string{cmdName, "identity", "list"})
assert.NoError(t, err, "Failed to return all affiliations")
assert.Equal(t, 2, log.Level) // Default level for listing identities is warning (2)

err = RunMain([]string{cmdName, "identity", "list", "-d"})
assert.NoError(t, err, "Failed to return all affiliations")
assert.Equal(t, 0, log.Level) // With '-d' flag log level should be debug (0)
}

func TestCleanUp(t *testing.T) {
os.Remove("../../testdata/ca-cert.pem")
os.Remove("../../testdata/ca-key.pem")
Expand Down
1 change: 0 additions & 1 deletion lib/clientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

// ClientConfig is the fabric-ca client's config
type ClientConfig struct {
Debug bool `def:"false" opt:"d" help:"Enable debug level logging"`
URL string `def:"http://localhost:7054" opt:"u" help:"URL of fabric-ca-server"`
MSPDir string `def:"msp" opt:"M" help:"Membership Service Provider directory"`
TLS tls.ClientTLSConfig
Expand Down

0 comments on commit 9a45730

Please sign in to comment.