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

feat: notation plugin uninstall command #832

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fb763d9
added zip suport
Two-Hearts Oct 19, 2023
dd75b5d
Merge branch 'notaryproject:main' into plugin-1.1.0
Two-Hearts Oct 19, 2023
c326db2
added tar.gz support
Two-Hearts Oct 20, 2023
d19ec82
updated
Two-Hearts Oct 23, 2023
bf3d6e9
added uninstall
Two-Hearts Oct 23, 2023
a6379c1
added install from URL
Two-Hearts Oct 23, 2023
4b5989c
updated
Two-Hearts Oct 24, 2023
1550236
fix
Two-Hearts Oct 24, 2023
ea75514
updated
Two-Hearts Oct 24, 2023
ce9439f
Merge branch 'notaryproject:main' into plugin-1.1.0
Two-Hearts Oct 31, 2023
f7c80b8
notation pluing uninstall
Two-Hearts Oct 31, 2023
d6d16f4
notation plugin uninstall
Two-Hearts Oct 31, 2023
ab59eec
test
Two-Hearts Oct 31, 2023
1e173a4
update
Two-Hearts Oct 31, 2023
695fbb3
Merge branch 'notaryproject:main' into plugin-uninstall
Two-Hearts Nov 20, 2023
5ca1d44
updated based on spec
Two-Hearts Nov 20, 2023
eae5b25
fixing e2e
Two-Hearts Nov 20, 2023
8a37514
fixing e2e
Two-Hearts Nov 20, 2023
68fd585
added license headers
Two-Hearts Nov 20, 2023
49bedec
Merge branch 'notaryproject:main' into plugin-uninstall
Two-Hearts Nov 20, 2023
e540d16
Merge branch 'notaryproject:main' into plugin-uninstall
Two-Hearts Nov 21, 2023
b8083ad
updated per code review
Two-Hearts Nov 21, 2023
57d1b9b
Merge branch 'plugin-uninstall' of https://github.com/Two-Hearts/nota…
Two-Hearts Nov 21, 2023
72c4a42
updated per code review
Two-Hearts Nov 21, 2023
d1b32b5
updated dependency
Two-Hearts Nov 21, 2023
6f6d9c8
updated dependency
Two-Hearts Nov 23, 2023
d35f513
updated per code review
Two-Hearts Nov 23, 2023
4d9639b
Merge branch 'notaryproject:main' into plugin-uninstall
Two-Hearts Nov 24, 2023
51caed0
updated
Two-Hearts Nov 24, 2023
8a17628
update
Two-Hearts Nov 27, 2023
b6a233e
Merge branch 'notaryproject:main' into plugin-uninstall
Two-Hearts Nov 28, 2023
039e139
updated per code review
Two-Hearts Nov 28, 2023
0329eae
Merge branch 'plugin-uninstall' of https://github.com/Two-Hearts/nota…
Two-Hearts Nov 28, 2023
5a50e9f
updated per code review
Two-Hearts Nov 28, 2023
d452f13
Merge branch 'main' into plugin-uninstall
Two-Hearts Nov 28, 2023
2741c85
Merge branch 'plugin-uninstall' of https://github.com/Two-Hearts/nota…
Two-Hearts Nov 28, 2023
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
13 changes: 0 additions & 13 deletions cmd/notation/internal/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,3 @@ type ErrorExceedMaxSignatures struct {
func (e ErrorExceedMaxSignatures) Error() string {
return fmt.Sprintf("exceeded configured limit of max signatures %d to examine", e.MaxSignatures)
}

// ErrorInvalidPluginName is used when a plugin executable file name does not
// follow the spec.
type ErrorInvalidPluginName struct {
Msg string
}

func (e ErrorInvalidPluginName) Error() string {
if e.Msg != "" {
return e.Msg
}
return "invalid plugin file name"
}
4 changes: 2 additions & 2 deletions cmd/notation/plugin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func Cmd() *cobra.Command {
}

command.AddCommand(
pluginListCommand(),
pluginUninstallCommand(nil),
listCommand(),
uninstallCommand(nil),
)

return command
Expand Down
2 changes: 1 addition & 1 deletion cmd/notation/plugin/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/spf13/cobra"
)

func pluginListCommand() *cobra.Command {
func listCommand() *cobra.Command {
return &cobra.Command{
Use: "list [flags]",
Aliases: []string{"ls"},
Expand Down
22 changes: 12 additions & 10 deletions cmd/notation/plugin/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"os"

"github.com/notaryproject/notation-go/dir"
"github.com/notaryproject/notation-go/log"
"github.com/notaryproject/notation-go/plugin"
"github.com/notaryproject/notation/cmd/notation/internal/cmdutil"
notationplugin "github.com/notaryproject/notation/cmd/notation/internal/plugin"
"github.com/notaryproject/notation/internal/cmd"
Expand All @@ -31,7 +33,7 @@ type pluginUninstallOpts struct {
confirmed bool
}

func pluginUninstallCommand(opts *pluginUninstallOpts) *cobra.Command {
func uninstallCommand(opts *pluginUninstallOpts) *cobra.Command {
if opts == nil {
opts = &pluginUninstallOpts{}
}
Expand All @@ -49,7 +51,7 @@ Example - Uninstall plugin:
return errors.New("plugin name is required")
}
if len(args) > 1 {
return errors.New("can only remove one plugin at a time")
return errors.New("only one plugin can be removed at a time")
}
opts.pluginName = args[0]
return nil
Expand All @@ -65,30 +67,30 @@ Example - Uninstall plugin:
}

func unInstallPlugin(command *cobra.Command, opts *pluginUninstallOpts) error {
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
// set log level
// set logger
ctx := opts.LoggingFlagOpts.InitializeLogger(command.Context())
logger := log.GetLogger(ctx)

pluginName := opts.pluginName
_, err := notationplugin.GetPluginMetadataIfExist(ctx, pluginName)
if err != nil {
if errors.Is(err, os.ErrNotExist) { // plugin does not exist
return fmt.Errorf("unable to find plugin %s.\nTo view a list of installed plugins, use `notation plugin list`", pluginName)
}
return fmt.Errorf("failed to uninstall %s: %w", pluginName, err)
// plugin exists, but the binary is corrupted
logger.Infof("Uninstalling...Found plugin %s binary file is corrupted: %v", pluginName, err)
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
}
// core process
pluginPath, err := dir.PluginFS().SysPath(pluginName)
if err != nil {
return fmt.Errorf("failed to uninstall %s: %v", pluginName, err)
}
prompt := fmt.Sprintf("Are you sure you want to uninstall plugin %q?", pluginName)
confirmed, err := cmdutil.AskForConfirmation(os.Stdin, prompt, opts.confirmed)
if err != nil {
return fmt.Errorf("failed to uninstall %s: %v", pluginName, err)
return fmt.Errorf("failed when asking for confirmation: %v", err)
}
if !confirmed {
return nil
}
if err := os.RemoveAll(pluginPath); err != nil {
mgr := plugin.NewCLIManager(dir.PluginFS())
if err := mgr.Uninstall(ctx, pluginName); err != nil {
return fmt.Errorf("failed to uninstall %s: %v", pluginName, err)
}
fmt.Printf("Successfully uninstalled plugin %s\n", pluginName)
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.21

require (
github.com/notaryproject/notation-core-go v1.0.1
github.com/notaryproject/notation-go v1.0.1
github.com/notaryproject/notation-go v1.0.2-0.20231123031546-5de0d58b21c1
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/oras-project/oras-credentials-go v0.3.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
golang.org/x/term v0.13.0
golang.org/x/term v0.14.0
oras.land/oras-go/v2 v2.3.1
)

Expand All @@ -25,8 +25,8 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/veraison/go-cose v1.1.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/notaryproject/notation-core-go v1.0.1 h1:01doxjDERbd0vocLQrlJdusKrRLNNn50OJzp0c5I4Cw=
github.com/notaryproject/notation-core-go v1.0.1/go.mod h1:rayl8WlKgS4YxOZgDO0iGGB4Ef515ZFZUFaZDmsPXgE=
github.com/notaryproject/notation-go v1.0.1 h1:D3fqG3eaBKVESRySV/Tg//MyTg2Q1nTKPh/t2q9LpSw=
github.com/notaryproject/notation-go v1.0.1/go.mod h1:VonyZsbocRQQNIDq/VPV5jKJOQwDH3gvfK4cXNpUA0U=
github.com/notaryproject/notation-go v1.0.2-0.20231123031546-5de0d58b21c1 h1:TuSZ+3Eu3A/XKucl7J95sDT8XoG6t2dEcIipt6ydAls=
github.com/notaryproject/notation-go v1.0.2-0.20231123031546-5de0d58b21c1/go.mod h1:tSCFsAdKAtB7AfKS/BaUf8AXzASA+9TEokMDEDutqPM=
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-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
Expand Down Expand Up @@ -51,12 +51,12 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
Expand All @@ -76,15 +76,15 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand Down
Loading