mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
<!-- Thank you for opening a PR! Here are some things you need to know before submitting: 1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Developer-Guidelines 2. Label this PR accordingly with the '/kind' line 3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Writing-and-running-tests 4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/PR-Review Documentation: If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Contributing-to-Docs --> **What type of PR is this:** <!-- Add one of the following kinds: /kind bug /kind cleanup /kind tests /kind documentation Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well. --> /kind feature **What does this PR do / why we need it:** This PR does the following: - Moves "registry" to preference - Gets rid of unused preference configuration options - Reorders the parameters for preference for the usage in --help **Which issue(s) this PR fixes:** <!-- Specifying the issue will automatically close it when this PR is merged --> https://github.com/redhat-developer/odo/issues/5402 **PR acceptance criteria:** - [X] Unit test - [X] Integration test - [X] Documentation **How to test changes / Special notes to the reviewer:**
108 lines
2.9 KiB
Go
108 lines
2.9 KiB
Go
package registry
|
|
|
|
import (
|
|
// Built-in packages
|
|
"fmt"
|
|
|
|
// Third-party packages
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
"github.com/zalando/go-keyring"
|
|
ktemplates "k8s.io/kubectl/pkg/util/templates"
|
|
|
|
// odo packages
|
|
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
|
|
"github.com/redhat-developer/odo/pkg/odo/cmdline"
|
|
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
|
|
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
|
|
"github.com/redhat-developer/odo/pkg/util"
|
|
)
|
|
|
|
const deleteCommandName = "delete"
|
|
|
|
// "odo registry delete" command description and examples
|
|
var (
|
|
deleteLongDesc = ktemplates.LongDesc(`Delete devfile registry`)
|
|
|
|
deleteExample = ktemplates.Examples(`# Delete devfile registry
|
|
%[1]s CheRegistry
|
|
`)
|
|
)
|
|
|
|
// DeleteOptions encapsulates the options for the "odo registry delete" command
|
|
type DeleteOptions struct {
|
|
// Clients
|
|
clientset *clientset.Clientset
|
|
|
|
// Parameters
|
|
registryName string
|
|
|
|
// Flags
|
|
forceFlag bool
|
|
|
|
operation string
|
|
registryURL string
|
|
user string
|
|
}
|
|
|
|
// NewDeleteOptions creates a new DeleteOptions instance
|
|
func NewDeleteOptions() *DeleteOptions {
|
|
return &DeleteOptions{}
|
|
}
|
|
|
|
func (o *DeleteOptions) SetClientset(clientset *clientset.Clientset) {
|
|
o.clientset = clientset
|
|
}
|
|
|
|
// Complete completes DeleteOptions after they've been created
|
|
func (o *DeleteOptions) Complete(cmdline cmdline.Cmdline, args []string) (err error) {
|
|
o.operation = "delete"
|
|
o.registryName = args[0]
|
|
o.registryURL = ""
|
|
o.user = "default"
|
|
return nil
|
|
}
|
|
|
|
// Validate validates the DeleteOptions based on completed values
|
|
func (o *DeleteOptions) Validate() (err error) {
|
|
return nil
|
|
}
|
|
|
|
// Run contains the logic for "odo registry delete" command
|
|
func (o *DeleteOptions) Run() (err error) {
|
|
isSecure := registryUtil.IsSecure(o.clientset.PreferenceClient, o.registryName)
|
|
err = o.clientset.PreferenceClient.RegistryHandler(o.operation, o.registryName, o.registryURL, o.forceFlag, false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if isSecure {
|
|
err = keyring.Delete(util.CredentialPrefix+o.registryName, o.user)
|
|
if err != nil {
|
|
return errors.Wrap(err, "unable to delete registry credential from keyring")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// NewCmdDelete implements the "odo registry delete" command
|
|
func NewCmdDelete(name, fullName string) *cobra.Command {
|
|
o := NewDeleteOptions()
|
|
registryDeleteCmd := &cobra.Command{
|
|
Use: fmt.Sprintf("%s <registry name>", name),
|
|
Short: deleteLongDesc,
|
|
Long: deleteLongDesc,
|
|
Example: fmt.Sprintf(fmt.Sprint(deleteExample), fullName),
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
genericclioptions.GenericRun(o, cmd, args)
|
|
},
|
|
}
|
|
clientset.Add(registryDeleteCmd, clientset.PREFERENCE)
|
|
|
|
registryDeleteCmd.Flags().BoolVarP(&o.forceFlag, "force", "f", false, "Don't ask for confirmation, delete the registry directly")
|
|
|
|
return registryDeleteCmd
|
|
}
|