Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>
  • Loading branch information
Two-Hearts committed Dec 2, 2022
2 parents d4a00ef + a6dbab8 commit 04a877f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
7 changes: 4 additions & 3 deletions cmd/notation/cert/generateTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ func generateTestCert(opts *certGenerateTestOpts) error {

// write private key
relativeKeyPath, relativeCertPath := dir.LocalKeyPath(name)
keyPath, err := dir.ConfigFS().SysPath(relativeKeyPath)
configFS := dir.ConfigFS()
keyPath, err := configFS.SysPath(relativeKeyPath)
if err != nil {
return err
}
certPath, err := dir.ConfigFS().SysPath(relativeCertPath)
certPath, err := configFS.SysPath(relativeCertPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -164,7 +165,7 @@ func generateSelfSignedCert(privateKey *rsa.PrivateKey, name string) (testhelper

func addKeyToSigningKeys(signingKeys *config.SigningKeys, key config.KeySuite, markDefault bool) error {
if slices.Contains(signingKeys.Keys, key.Name) {
return errors.New(key.Name + ": already exists")
return fmt.Errorf("signing key with name %q already exists", key.Name)
}
signingKeys.Keys = append(signingKeys.Keys, key)
if markDefault {
Expand Down
9 changes: 5 additions & 4 deletions cmd/notation/cert/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ func certListCommand(opts *certListOpts) *cobra.Command {
func listCerts(opts *certListOpts) error {
namedStore := opts.namedStore
storeType := opts.storeType
configFS := dir.ConfigFS()

// List all certificates under truststore/x509, display empty if there's
// no certificate yet
if namedStore == "" && storeType == "" {
path, err := dir.ConfigFS().SysPath(dir.TrustStoreDir, "x509")
path, err := configFS.SysPath(dir.TrustStoreDir, "x509")
if err := truststore.CheckNonErrNotExistError(err); err != nil {
return err
}
Expand All @@ -52,7 +53,7 @@ func listCerts(opts *certListOpts) error {
// List all certificates under truststore/x509/storeType/namedStore,
// display empty if there's no such certificate
if namedStore != "" && storeType != "" {
path, err := dir.ConfigFS().SysPath(dir.TrustStoreDir, "x509", storeType, namedStore)
path, err := configFS.SysPath(dir.TrustStoreDir, "x509", storeType, namedStore)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
return err
}
Expand All @@ -66,7 +67,7 @@ func listCerts(opts *certListOpts) error {
// List all certificates under x509/storeType, display empty if
// there's no certificate yet
if storeType != "" {
path, err := dir.ConfigFS().SysPath(dir.TrustStoreDir, "x509", storeType)
path, err := configFS.SysPath(dir.TrustStoreDir, "x509", storeType)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
return err
}
Expand All @@ -77,7 +78,7 @@ func listCerts(opts *certListOpts) error {
// List all certificates under named store namedStore, display empty if
// there's no such certificate
for _, t := range notationgoTruststore.Types {
path, err := dir.ConfigFS().SysPath(dir.TrustStoreDir, "x509", string(t), namedStore)
path, err := configFS.SysPath(dir.TrustStoreDir, "x509", string(t), namedStore)
if err := truststore.CheckNonErrNotExistError(err); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/notation/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func addExternalKey(ctx context.Context, opts *keyAddOpts, pluginName, keyName s

func addKeyCore(signingKeys *config.SigningKeys, key config.KeySuite, markDefault bool) error {
if slices.Contains(signingKeys.Keys, key.Name) {
return errors.New(key.Name + ": already exists")
return fmt.Errorf("signing key with name %q already exists", key.Name)
}
signingKeys.Keys = append(signingKeys.Keys, key)
if markDefault {
Expand Down
27 changes: 20 additions & 7 deletions cmd/notation/plugin.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"fmt"
"os"
"text/tabwriter"

"github.com/notaryproject/notation-go/dir"
"github.com/notaryproject/notation-go/plugin"
"github.com/notaryproject/notation/internal/ioutil"
"github.com/notaryproject/notation-go/plugin/proto"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -35,12 +37,23 @@ func listPlugins(command *cobra.Command) error {
if err != nil {
return err
}
var plugins []plugin.Plugin
var errors []error

tw := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
fmt.Fprintln(tw, "NAME\tDESCRIPTION\tVERSION\tCAPABILITIES\tERROR\t")

var pl plugin.Plugin
var resp *proto.GetMetadataResponse
for _, n := range pluginNames {
pl, err := mgr.Get(command.Context(), n)
errors = append(errors, err)
plugins = append(plugins, pl)
pl, err = mgr.Get(command.Context(), n)
metaData := &proto.GetMetadataResponse{}
if err == nil {
resp, err = pl.GetMetadata(command.Context(), &proto.GetMetadataRequest{})
if err == nil {
metaData = resp
}
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%v\t%v\t\n",
n, metaData.Description, metaData.Version, metaData.Capabilities, err)
}
return ioutil.PrintPlugins(command.Context(), os.Stdout, plugins, errors)
return tw.Flush()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/distribution/distribution/v3 v3.0.0-20220729163034-26163d82560f
github.com/docker/docker-credential-helpers v0.7.0
github.com/notaryproject/notation-core-go v0.2.0-beta.1.0.20221123104522-9b5de089a023
github.com/notaryproject/notation-go v0.12.0-beta.1.0.20221129043056-7ae1f5fd0730
github.com/notaryproject/notation-go v0.12.0-beta.1.0.20221202021827-35d90607a666
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc2
github.com/spf13/cobra v1.6.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/notaryproject/notation-core-go v0.2.0-beta.1.0.20221123104522-9b5de089a023 h1:Z/2hxPJOjWfmgOPTNkGBDp/LVIEtizd9uJNQvjFE0Dc=
github.com/notaryproject/notation-core-go v0.2.0-beta.1.0.20221123104522-9b5de089a023/go.mod h1:n8Gbvl9sKa00KptkKEL5XKUyMTIALe74QipKauE2rj4=
github.com/notaryproject/notation-go v0.12.0-beta.1.0.20221129043056-7ae1f5fd0730 h1:WPzkdjn/fruM07tl4ZsrUNBx9FT2a/hCJwj2Djuamv0=
github.com/notaryproject/notation-go v0.12.0-beta.1.0.20221129043056-7ae1f5fd0730/go.mod h1:2Xy40C9rJip3h9XPC6ei2HEEdUoZJ5KDC6mlX/FD0oQ=
github.com/notaryproject/notation-go v0.12.0-beta.1.0.20221202021827-35d90607a666 h1:KvxQCvgpJmejv5/tUXnYSUyWyH/B7UGUdIG5eqKLOHM=
github.com/notaryproject/notation-go v0.12.0-beta.1.0.20221202021827-35d90607a666/go.mod h1:2Xy40C9rJip3h9XPC6ei2HEEdUoZJ5KDC6mlX/FD0oQ=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc2 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034=
Expand Down
22 changes: 0 additions & 22 deletions internal/ioutil/print.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
package ioutil

import (
"context"
"fmt"
"io"
"text/tabwriter"

"github.com/notaryproject/notation-go/config"
"github.com/notaryproject/notation-go/plugin"
"github.com/notaryproject/notation-go/plugin/proto"
)

func newTabWriter(w io.Writer) *tabwriter.Writer {
return tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
}

func PrintPlugins(ctx context.Context, w io.Writer, v []plugin.Plugin, errors []error) error {
tw := newTabWriter(w)
fmt.Fprintln(tw, "NAME\tDESCRIPTION\tVERSION\tCAPABILITIES\tERROR\t")
for ind, p := range v {
metaData := proto.GetMetadataResponse{}
if p != nil {
req := &proto.GetMetadataRequest{}
metadata, err := p.GetMetadata(ctx, req)
if err == nil {
metaData = *metadata
}
errors[ind] = err
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%v\t%v\t\n",
metaData.Name, metaData.Description, metaData.Version, metaData.Capabilities, errors[ind])
}
return tw.Flush()
}

func PrintKeyMap(w io.Writer, target string, v []config.KeySuite) error {
tw := newTabWriter(w)
fmt.Fprintln(tw, "NAME\tKEY PATH\tCERTIFICATE PATH\tID\tPLUGIN NAME\t")
Expand Down

0 comments on commit 04a877f

Please sign in to comment.