-
Notifications
You must be signed in to change notification settings - Fork 92
feat: add notation plugin uninstall command #842
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5b0589e
added zip suport
2c4671a
added tar.gz support
13ca773
updated
6138e77
added uninstall
0e9f095
added install from URL
6de0edb
updated
4b90dd5
fix
3951ee7
updated
031b539
notation pluing uninstall
ce88481
notation plugin uninstall
fe70191
test
4ed3a9b
update
d723b81
updated based on spec
c985fa5
fixing e2e
5b67ef2
fixing e2e
0407c97
added license headers
cb7e8e6
updated per code review
abe3eb9
updated per code review
4580723
updated dependency
0d8513a
updated dependency
72e668b
updated per code review
5098fac
updated
d764eba
update
08fce42
updated per code review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright The Notary Project Authors. | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package plugin | ||
|
|
||
| import "github.com/spf13/cobra" | ||
|
|
||
| func Cmd() *cobra.Command { | ||
| command := &cobra.Command{ | ||
| Use: "plugin", | ||
| Short: "Manage plugins", | ||
| } | ||
|
|
||
| command.AddCommand( | ||
| listCommand(), | ||
| uninstallCommand(nil), | ||
| ) | ||
|
|
||
| return command | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Copyright The Notary Project Authors. | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package plugin | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/notaryproject/notation-go/dir" | ||
| "github.com/notaryproject/notation-go/plugin" | ||
| "github.com/notaryproject/notation/cmd/notation/internal/cmdutil" | ||
| "github.com/notaryproject/notation/internal/cmd" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type pluginUninstallOpts struct { | ||
| cmd.LoggingFlagOpts | ||
| pluginName string | ||
| confirmed bool | ||
| } | ||
|
|
||
| func uninstallCommand(opts *pluginUninstallOpts) *cobra.Command { | ||
| if opts == nil { | ||
| opts = &pluginUninstallOpts{} | ||
| } | ||
| command := &cobra.Command{ | ||
| Use: "uninstall [flags] <plugin_name>", | ||
| Aliases: []string{"remove", "rm"}, | ||
| Short: "Uninstall a plugin", | ||
| Long: `Uninstall a plugin | ||
|
|
||
| Example - Uninstall plugin: | ||
| notation plugin uninstall wabbit-plugin | ||
| `, | ||
| Args: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) == 0 { | ||
| return errors.New("plugin name is required") | ||
| } | ||
| if len(args) > 1 { | ||
| return errors.New("only one plugin can be removed at a time") | ||
| } | ||
| opts.pluginName = args[0] | ||
| return nil | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return uninstallPlugin(cmd, opts) | ||
| }, | ||
| } | ||
|
|
||
| opts.LoggingFlagOpts.ApplyFlags(command.Flags()) | ||
| command.Flags().BoolVarP(&opts.confirmed, "yes", "y", false, "do not prompt for confirmation") | ||
| return command | ||
| } | ||
|
|
||
| func uninstallPlugin(command *cobra.Command, opts *pluginUninstallOpts) error { | ||
| // set logger | ||
| ctx := opts.LoggingFlagOpts.InitializeLogger(command.Context()) | ||
| pluginName := opts.pluginName | ||
| exist, err := checkPluginExistence(ctx, pluginName) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to check plugin existence: %w", err) | ||
| } | ||
| if !exist { | ||
| return fmt.Errorf("unable to find plugin %s.\nTo view a list of installed plugins, use `notation plugin list`", pluginName) | ||
| } | ||
| // core process | ||
| 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 when asking for confirmation: %w", err) | ||
| } | ||
| if !confirmed { | ||
| return nil | ||
| } | ||
| mgr := plugin.NewCLIManager(dir.PluginFS()) | ||
| if err := mgr.Uninstall(ctx, pluginName); err != nil { | ||
| return fmt.Errorf("failed to uninstall %s: %w", pluginName, err) | ||
| } | ||
| fmt.Printf("Successfully uninstalled plugin %s\n", pluginName) | ||
| return nil | ||
| } | ||
|
|
||
| // checkPluginExistence returns true if plugin exists in the system | ||
| func checkPluginExistence(ctx context.Context, pluginName string) (bool, error) { | ||
| mgr := plugin.NewCLIManager(dir.PluginFS()) | ||
| _, err := mgr.Get(ctx, pluginName) | ||
| if err != nil { | ||
| if errors.Is(err, os.ErrNotExist) { // plugin does not exist | ||
| return false, nil | ||
| } | ||
| return false, err | ||
| } | ||
| return true, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright The Notary Project Authors. | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package plugin | ||
|
|
||
| import ( | ||
| . "github.com/notaryproject/notation/test/e2e/internal/notation" | ||
| "github.com/notaryproject/notation/test/e2e/internal/utils" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| ) | ||
|
|
||
| var _ = Describe("notation plugin uninstall", func() { | ||
| It("with valid plugin name", func() { | ||
| Host(nil, func(notation *utils.ExecOpts, _ *Artifact, vhost *utils.VirtualHost) { | ||
| vhost.SetOption(AddPlugin(NotationE2EPluginPath)) | ||
| notation.Exec("plugin", "uninstall", "--yes", "e2e-plugin"). | ||
| MatchContent("Successfully uninstalled plugin e2e-plugin\n") | ||
| }) | ||
| }) | ||
|
|
||
| It("with plugin does not exist", func() { | ||
| Host(nil, func(notation *utils.ExecOpts, _ *Artifact, vhost *utils.VirtualHost) { | ||
| notation.ExpectFailure().Exec("plugin", "uninstall", "--yes", "non-exist"). | ||
| MatchErrContent("Error: unable to find plugin non-exist.\nTo view a list of installed plugins, use `notation plugin list`\n") | ||
| }) | ||
| }) | ||
|
|
||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.