/
verify.go
52 lines (47 loc) · 1.43 KB
/
verify.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package user
import (
"errors"
"github.com/appcelerator/amp/api/rpc/account"
"github.com/appcelerator/amp/api/rpc/version"
"github.com/appcelerator/amp/cli"
"github.com/appcelerator/amp/cmd/amplifier/server/configuration"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"google.golang.org/grpc/status"
)
// NewVerifyCommand returns a new instance of the verify command.
func NewVerifyCommand(c cli.Interface) *cobra.Command {
return &cobra.Command{
Use: "verify TOKEN",
Short: "Verify account",
PreRunE: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return verify(c, args)
},
}
}
func verify(c cli.Interface, args []string) error {
conn := c.ClientConn()
clientVer := version.NewVersionClient(conn)
requestVer := &version.GetRequest{}
reply, err := clientVer.VersionGet(context.Background(), requestVer)
if err != nil {
if s, ok := status.FromError(err); ok {
return errors.New(s.Message())
}
}
if reply.Info.Registration == configuration.RegistrationNone {
return errors.New("`amp user verify` disabled. This cluster has no registration policy")
}
client := account.NewAccountClient(conn)
request := &account.VerificationRequest{
Token: args[0],
}
if _, err := client.Verify(context.Background(), request); err != nil {
if s, ok := status.FromError(err); ok {
return errors.New(s.Message())
}
}
c.Console().Println("Your account has now been activated.")
return nil
}