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: add notation plugin uninstall command #842

Merged
merged 24 commits into from
Dec 5, 2023
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
updated
Signed-off-by: Patrick Zheng <[email protected]>
Two-Hearts committed Nov 28, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 5098fac52ca6198cc8cdce57e66d02bf684a6a8a
32 changes: 0 additions & 32 deletions cmd/notation/internal/plugin/plugin.go

This file was deleted.

28 changes: 0 additions & 28 deletions cmd/notation/internal/plugin/plugin_test.go

This file was deleted.

17 changes: 14 additions & 3 deletions cmd/notation/plugin/uninstall.go
Original file line number Diff line number Diff line change
@@ -14,15 +14,16 @@
package plugin

import (
"context"
"errors"
"fmt"
"os"

"github.com/notaryproject/notation-go/dir"
"github.com/notaryproject/notation-go/log"
"github.com/notaryproject/notation-go/plugin"
"github.com/notaryproject/notation-go/plugin/proto"
"github.com/notaryproject/notation/cmd/notation/internal/cmdutil"
notationplugin "github.com/notaryproject/notation/cmd/notation/internal/plugin"
"github.com/notaryproject/notation/internal/cmd"
"github.com/spf13/cobra"
)
@@ -72,12 +73,12 @@ func unInstallPlugin(command *cobra.Command, opts *pluginUninstallOpts) error {
logger := log.GetLogger(ctx)

pluginName := opts.pluginName
_, err := notationplugin.GetPluginMetadataIfExist(ctx, pluginName)
_, err := 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)
}
// plugin exists, but the binary is corrupted
// plugin exists, but the binary is malfunctioning
logger.Infof("Uninstalling...Found plugin %s binary file is malfunctioning: %v", pluginName, err)
}
// core process
@@ -96,3 +97,13 @@ func unInstallPlugin(command *cobra.Command, opts *pluginUninstallOpts) error {
fmt.Printf("Successfully uninstalled plugin %s\n", pluginName)
return nil
}

// getPluginMetadataIfExist returns plugin's metadata if it exists in Notation
func getPluginMetadataIfExist(ctx context.Context, pluginName string) (*proto.GetMetadataResponse, error) {
mgr := plugin.NewCLIManager(dir.PluginFS())
plugin, err := mgr.Get(ctx, pluginName)
if err != nil {
return nil, err
}
return plugin.GetMetadata(ctx, &proto.GetMetadataRequest{})
}