Commit 3fa6461a authored by Loïck Bonniot's avatar Loïck Bonniot

Merge branch 'unregister-command-does-not-work-22' into 'master'

[c] Fix unregister command

Closes #22

See merge request !94
parents 9fcd645d 65558011
Pipeline #2366 passed with stages
......@@ -22,14 +22,15 @@ var unregisterCmd = &cobra.Command{
}
// Confirmation
var ready string
var passphrase, ready string
_ = readPassword(&passphrase, false)
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()
err = user.Unregister(passphrase)
if err != nil {
fmt.Fprintln(os.Stderr, "Cannot unregister:", err.Error())
os.Exit(2)
......
package user
import (
"errors"
pb "dfss/dfssp/api"
"dfss/dfssc/common"
"dfss/dfssc/security"
"dfss/dfssp/api"
"dfss/net"
"github.com/spf13/viper"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// Unregister a user from the platform
func Unregister() error {
client, err := connect()
func Unregister(passphrase string) error {
auth := security.NewAuthContainer(passphrase)
ca, cert, key, err := auth.LoadFiles()
if err != nil {
return err
}
conn, err := net.Connect(viper.GetString("platform_addrport"), cert, key, ca, nil)
if err != nil {
return err
}
// Stop the context if it takes too long for the platform to answer
client := api.NewPlatformClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), net.DefaultTimeout)
defer cancel()
response, err := client.Unregister(ctx, &pb.Empty{})
response, err := client.Unregister(ctx, &api.Empty{})
if err != nil {
return errors.New(grpc.ErrorDesc(err))
}
if response.Code != pb.ErrorCode_SUCCESS {
return errors.New(response.Message)
return err
}
return nil
return common.EvaluateErrorCodeResponse(response)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment