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

update: updated plugin list command #461

Merged
merged 33 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b910a8a
updated dependency
Two-Hearts Oct 12, 2022
28b0438
resolved conflicts
Two-Hearts Oct 12, 2022
4f4e2a4
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 12, 2022
eea8003
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 13, 2022
216cea2
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 17, 2022
1267c02
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 18, 2022
1c3dfbb
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 18, 2022
98e5946
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 18, 2022
55563d3
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 19, 2022
c68d602
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 19, 2022
d165a7b
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 20, 2022
7166877
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 25, 2022
94f174d
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 28, 2022
e1d8437
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 29, 2022
a873c67
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 31, 2022
cd877de
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 31, 2022
53b847d
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 31, 2022
1e29bb4
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 31, 2022
5121684
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 31, 2022
679e01d
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 31, 2022
394b59a
Merge branch 'notaryproject:main' into main
Two-Hearts Oct 31, 2022
c6e8dd1
Merge branch 'notaryproject:main' into main
Two-Hearts Nov 7, 2022
b54b712
Merge branch 'notaryproject:main' into main
Two-Hearts Nov 12, 2022
b121548
Merge branch 'notaryproject:main' into main
Two-Hearts Nov 28, 2022
7ea6b0b
Merge branch 'notaryproject:main' into main
Two-Hearts Nov 30, 2022
351f18b
updated plugin printout
Two-Hearts Dec 1, 2022
b6ca9f1
updated per code review
Two-Hearts Dec 1, 2022
2be6421
updated per code review
Two-Hearts Dec 1, 2022
9a3aae4
update
Two-Hearts Dec 1, 2022
ca5bde2
update
Two-Hearts Dec 1, 2022
5422370
updated per code review
Two-Hearts Dec 2, 2022
9fb2e7f
updated per code review
Two-Hearts Dec 2, 2022
85bf890
update
Two-Hearts Dec 2, 2022
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: 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
28 changes: 21 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 All @@ -30,17 +32,29 @@ func pluginListCommand() *cobra.Command {
}

func listPlugins(command *cobra.Command) error {
var err error
mgr := plugin.NewCLIManager(dir.PluginFS())
pluginNames, err := mgr.List(command.Context())
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()
}
4 changes: 2 additions & 2 deletions cmd/notation/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func runVerify(command *cobra.Command, opts *verifyOpts) error {
return err
}
authClient, plainHTTP, _ := getAuthClient(&opts.SecureFlagOpts, ref)
remote_repo := remote.Repository{
remoteRepo := remote.Repository{
Client: authClient,
Reference: ref,
PlainHTTP: plainHTTP,
}
repo := notationregistry.NewRepository(&remote_repo)
repo := notationregistry.NewRepository(&remoteRepo)

// set up verification plugin config.
configs, err := cmd.ParseFlagPluginConfig(opts.pluginConfig)
Expand Down
22 changes: 0 additions & 22 deletions internal/ioutil/print.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
package ioutil

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

"github.com/notaryproject/notation-go"
"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