unregister.go 751 Bytes
Newer Older
Richer Maximilien's avatar
Richer Maximilien committed
1 2 3
package user

import (
Loïck Bonniot's avatar
Loïck Bonniot committed
4 5 6
	"dfss/dfssc/common"
	"dfss/dfssc/security"
	"dfss/dfssp/api"
Richer Maximilien's avatar
Richer Maximilien committed
7
	"dfss/net"
Loïck Bonniot's avatar
Loïck Bonniot committed
8
	"github.com/spf13/viper"
Caro Axel's avatar
Caro Axel committed
9
	"golang.org/x/net/context"
Richer Maximilien's avatar
Richer Maximilien committed
10 11 12
)

// Unregister a user from the platform
Loïck Bonniot's avatar
Loïck Bonniot committed
13 14 15 16 17 18 19 20
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)
Richer Maximilien's avatar
Richer Maximilien committed
21 22 23 24
	if err != nil {
		return err
	}

Loïck Bonniot's avatar
Loïck Bonniot committed
25
	client := api.NewPlatformClient(conn)
Richer Maximilien's avatar
Richer Maximilien committed
26 27
	ctx, cancel := context.WithTimeout(context.Background(), net.DefaultTimeout)
	defer cancel()
Loïck Bonniot's avatar
Loïck Bonniot committed
28 29
	response, err := client.Unregister(ctx, &api.Empty{})

Richer Maximilien's avatar
Richer Maximilien committed
30
	if err != nil {
Loïck Bonniot's avatar
Loïck Bonniot committed
31
		return err
Richer Maximilien's avatar
Richer Maximilien committed
32 33
	}

Loïck Bonniot's avatar
Loïck Bonniot committed
34
	return common.EvaluateErrorCodeResponse(response)
Richer Maximilien's avatar
Richer Maximilien committed
35
}