-
Notifications
You must be signed in to change notification settings - Fork 0
/
unregister.go
38 lines (33 loc) · 879 Bytes
/
unregister.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cmd
import (
"fmt"
"os"
"dfss/dfssc/security"
"dfss/dfssc/user"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var unregisterCmd = &cobra.Command{
Use: "unregister",
Short: "delete current client information on platform",
Run: func(cmd *cobra.Command, args []string) {
// Read info from provided certificate
cert, err := security.GetCertificate(viper.GetString("file_cert"))
if err != nil {
fmt.Fprintln(os.Stderr, "An error occurred:", err.Error())
os.Exit(2)
}
// Confirmation
var ready string
readStringParam("Do you REALLY want to delete "+cert.Subject.CommonName+"? Type 'yes' to confirm", "", &ready)
if ready != "yes" {
fmt.Fprintln(os.Stderr, "Unregistering aborted!")
os.Exit(1)
}
err = user.Unregister()
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot unregister:", err.Error())
os.Exit(2)
}
},
}