Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Oct 11, 2023
1 parent 52213ae commit 928a0f5
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions cmd/notation/cert/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func listCerts(ctx context.Context, opts *certListOpts) error {
storeType := opts.storeType
configFS := dir.ConfigFS()

var certPaths []string
// List all certificates under truststore/x509, display empty if there's
// no certificate yet
if namedStore == "" && storeType == "" {
var certPaths []string
for _, t := range notationgoTruststore.Types {
path, err := configFS.SysPath(dir.TrustStoreDir, "x509", string(t))
if err := truststore.CheckNonErrNotExistError(err); err != nil {
Expand Down Expand Up @@ -121,27 +121,28 @@ func listCerts(ctx context.Context, opts *certListOpts) error {
if err := truststore.CheckNonErrNotExistError(err); err != nil {
return err
}
certPaths, err = truststore.ListCerts(path, 1)
certPaths, err := truststore.ListCerts(path, 1)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
logger.Debugln("Failed to complete list at path:", path)
return fmt.Errorf("failed to list all certificates stored of type %s, with error: %s", storeType, err.Error())
}
} else {
// List all certificates under named store namedStore, display empty if
// there's no certificate yet
for _, t := range notationgoTruststore.Types {
path, err := configFS.SysPath(dir.TrustStoreDir, "x509", string(t), namedStore)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
return err
}
certs, err := truststore.ListCerts(path, 0)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
logger.Debugln("Failed to complete list at path:", path)
return fmt.Errorf("failed to list all certificates stored in the named store %s, with error: %s", namedStore, err.Error())
}
certPaths = append(certPaths, certs...)
}
return ioutil.PrintCertMap(os.Stdout, certPaths)
}

// List all certificates under named store namedStore, display empty if
// there's no certificate yet
var certPaths []string
for _, t := range notationgoTruststore.Types {
path, err := configFS.SysPath(dir.TrustStoreDir, "x509", string(t), namedStore)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
return err
}
certs, err := truststore.ListCerts(path, 0)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
logger.Debugln("Failed to complete list at path:", path)
return fmt.Errorf("failed to list all certificates stored in the named store %s, with error: %s", namedStore, err.Error())
}
certPaths = append(certPaths, certs...)
}
return ioutil.PrintCertMap(os.Stdout, certPaths)
}

0 comments on commit 928a0f5

Please sign in to comment.