From 8eda58c23f9a88a34bf1153e7a5128b138eb7d55 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Sat, 26 Oct 2024 22:42:41 +0300 Subject: [PATCH 1/2] feat: add prompting to confirm delete certificate Signed-off-by: pashakostohrys --- cmd/argocd/commands/cert.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/cmd/argocd/commands/cert.go b/cmd/argocd/commands/cert.go index 0a8204b89d9e0..710a7d4ab93e0 100644 --- a/cmd/argocd/commands/cert.go +++ b/cmd/argocd/commands/cert.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" "github.com/argoproj/argo-cd/v2/cmd/argocd/commands/headless" + "github.com/argoproj/argo-cd/v2/cmd/argocd/commands/utils" argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient" certificatepkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/certificate" appsv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" @@ -236,19 +237,26 @@ func NewCertRemoveCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command err := fmt.Errorf("A single wildcard is not allowed as REPOSERVER name.") errors.CheckError(err) } - certQuery = certificatepkg.RepositoryCertificateQuery{ - HostNamePattern: hostNamePattern, - CertType: certType, - CertSubType: certSubType, - } - removed, err := certIf.DeleteCertificate(ctx, &certQuery) - errors.CheckError(err) - if len(removed.Items) > 0 { - for _, cert := range removed.Items { - fmt.Printf("Removed cert for '%s' of type '%s' (subtype '%s')\n", cert.ServerName, cert.CertType, cert.CertSubType) + + promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled) + canDelete := promptUtil.Confirm(fmt.Sprintf("Are you sure you want to remove all certificates for '%s'? [y/n]", hostNamePattern)) + if canDelete { + certQuery = certificatepkg.RepositoryCertificateQuery{ + HostNamePattern: hostNamePattern, + CertType: certType, + CertSubType: certSubType, + } + removed, err := certIf.DeleteCertificate(ctx, &certQuery) + errors.CheckError(err) + if len(removed.Items) > 0 { + for _, cert := range removed.Items { + fmt.Printf("Removed cert for '%s' of type '%s' (subtype '%s')\n", cert.ServerName, cert.CertType, cert.CertSubType) + } + } else { + fmt.Println("No certificates were removed (none matched the given patterns)") } } else { - fmt.Println("No certificates were removed (none matched the given patterns)") + fmt.Printf("The command to to remove all certificates for '%s' was cancelled.\n", hostNamePattern) } }, } From 8143b0a299e03f201e2ee40979c658885af13894 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Mon, 28 Oct 2024 13:47:04 +0200 Subject: [PATCH 2/2] feat: add prompting to confirm delete certificate Signed-off-by: pashakostohrys --- cmd/argocd/commands/cert.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/argocd/commands/cert.go b/cmd/argocd/commands/cert.go index 710a7d4ab93e0..d123a9ae66599 100644 --- a/cmd/argocd/commands/cert.go +++ b/cmd/argocd/commands/cert.go @@ -253,10 +253,10 @@ func NewCertRemoveCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command fmt.Printf("Removed cert for '%s' of type '%s' (subtype '%s')\n", cert.ServerName, cert.CertType, cert.CertSubType) } } else { - fmt.Println("No certificates were removed (none matched the given patterns)") + fmt.Println("No certificates were removed (none matched the given pattern)") } } else { - fmt.Printf("The command to to remove all certificates for '%s' was cancelled.\n", hostNamePattern) + fmt.Printf("The command to remove all certificates for '%s' was cancelled.\n", hostNamePattern) } }, }