Commit 65558011 authored by Loïck Bonniot's avatar Loïck Bonniot

[c] Fix unregister command

parent 9fcd645d
Pipeline #2364 passed with stage
...@@ -22,14 +22,15 @@ var unregisterCmd = &cobra.Command{ ...@@ -22,14 +22,15 @@ var unregisterCmd = &cobra.Command{
} }
// Confirmation // 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) readStringParam("Do you REALLY want to delete "+cert.Subject.CommonName+"? Type 'yes' to confirm", "", &ready)
if ready != "yes" { if ready != "yes" {
fmt.Fprintln(os.Stderr, "Unregistering aborted!") fmt.Fprintln(os.Stderr, "Unregistering aborted!")
os.Exit(1) os.Exit(1)
} }
err = user.Unregister() err = user.Unregister(passphrase)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "Cannot unregister:", err.Error()) fmt.Fprintln(os.Stderr, "Cannot unregister:", err.Error())
os.Exit(2) os.Exit(2)
......
package user package user
import ( import (
"errors" "dfss/dfssc/common"
"dfss/dfssc/security"
pb "dfss/dfssp/api" "dfss/dfssp/api"
"dfss/net" "dfss/net"
"github.com/spf13/viper"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc"
) )
// Unregister a user from the platform // Unregister a user from the platform
func Unregister() error { func Unregister(passphrase string) error {
client, err := connect() 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 { if err != nil {
return err 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) ctx, cancel := context.WithTimeout(context.Background(), net.DefaultTimeout)
defer cancel() defer cancel()
response, err := client.Unregister(ctx, &pb.Empty{}) response, err := client.Unregister(ctx, &api.Empty{})
if err != nil { if err != nil {
return errors.New(grpc.ErrorDesc(err)) return err
}
if response.Code != pb.ErrorCode_SUCCESS {
return errors.New(response.Message)
} }
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