2019-05-28 01:16:50 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-06-16 11:02:49 +00:00
|
|
|
"fmt"
|
2019-05-28 01:16:50 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"gopkg.in/AlecAivazis/survey.v1"
|
|
|
|
)
|
|
|
|
|
2019-07-12 01:02:46 +00:00
|
|
|
func makeDelete(initClient CredentialsClientInit) *cobra.Command {
|
2019-08-01 03:17:38 +00:00
|
|
|
flags := credentialFlagSet{}.withHostFlag()
|
|
|
|
|
2019-05-28 01:16:50 +00:00
|
|
|
deleteCmd := &cobra.Command{
|
2019-06-16 11:02:49 +00:00
|
|
|
Use: "delete",
|
2019-05-28 01:16:50 +00:00
|
|
|
Short: "Delete a credential using the given ID",
|
|
|
|
Long: `Delete a credential using the given ID, permanently. THERE IS NO UNDOING THIS ACTION.`,
|
|
|
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2019-08-01 03:17:38 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
|
2019-06-16 11:02:49 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
client := initClient(ctx)
|
|
|
|
|
2019-08-01 03:17:38 +00:00
|
|
|
cred := selectCredential(client, flags.sourceHost)
|
2019-06-16 11:02:49 +00:00
|
|
|
|
|
|
|
fmt.Println(cred)
|
|
|
|
|
2019-05-28 01:16:50 +00:00
|
|
|
var confirmed bool
|
|
|
|
prompt := &survey.Confirm{Message: "Are you sure you want to permanently delete this credential?"}
|
|
|
|
check(survey.AskOne(prompt, &confirmed, nil))
|
|
|
|
|
|
|
|
if confirmed {
|
2019-06-12 23:51:29 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*25)
|
2019-05-28 01:16:50 +00:00
|
|
|
defer cancel()
|
|
|
|
|
2019-06-16 11:02:49 +00:00
|
|
|
check(initClient(ctx).Delete(ctx, cred.ID))
|
2019-05-28 01:16:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-08-01 03:17:38 +00:00
|
|
|
flags.register(deleteCmd)
|
|
|
|
|
2019-05-28 01:16:50 +00:00
|
|
|
return deleteCmd
|
|
|
|
}
|