Skip to content

Commit

Permalink
Surya/core 9183/additional imptofu rpcs (#14910)
Browse files Browse the repository at this point in the history
Surya/core 9183/additional imptofu rpcs (#14910)
  • Loading branch information
heronhaye authored Dec 5, 2018
1 parent e5069bf commit e46b4b0
Show file tree
Hide file tree
Showing 47 changed files with 2,166 additions and 71 deletions.
15 changes: 8 additions & 7 deletions go/chat/sbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/keybase/client/go/emails"
"github.com/keybase/client/go/engine"
"github.com/keybase/client/go/kbtest"
"github.com/keybase/client/go/libkb"
Expand Down Expand Up @@ -88,7 +89,7 @@ func proveRooter(t *testing.T, g *libkb.GlobalContext, fu *kbtest.FakeUser) {

func addAndVerifyPhone(t *testing.T, g *libkb.GlobalContext, phoneNumber keybase1.PhoneNumber) {
mctx := libkb.NewMetaContextTODO(g)
require.NoError(t, phonenumbers.AddPhoneNumber(mctx, phoneNumber))
require.NoError(t, phonenumbers.AddPhoneNumber(mctx, phoneNumber, keybase1.IdentityVisibility_PRIVATE))

code, err := kbtest.GetPhoneVerificationCode(libkb.NewMetaContextTODO(g), phoneNumber)
require.NoError(t, err)
Expand Down Expand Up @@ -243,29 +244,29 @@ func TestChatSrvRooter(t *testing.T) {
}

func TestChatSrvPhone(t *testing.T) {
t.Skip("skipped because no RPC to set to discoverable yet CORE-9526")

var phone string
runChatSBSScenario(t, sbsTestCase{
getChatAssertion: func(user *kbtest.FakeUser) string {
phone = kbtest.GenerateTestPhoneNumber()
return fmt.Sprintf("%s@phone", phone)
},
sbsVerify: func(user *kbtest.FakeUser, g *libkb.GlobalContext) {
addAndVerifyPhone(t, g, keybase1.PhoneNumber("+"+phone))
phoneNumber := keybase1.PhoneNumber("+" + phone)
addAndVerifyPhone(t, g, phoneNumber)
phonenumbers.SetVisibilityPhoneNumber(libkb.NewMetaContextTODO(g), phoneNumber, keybase1.IdentityVisibility_PUBLIC)
},
})
}

func TestChatSrvEmail(t *testing.T) {
t.Skip("skipped because no RPC to set to discoverable yet CORE-9526")

runChatSBSScenario(t, sbsTestCase{
getChatAssertion: func(user *kbtest.FakeUser) string {
return fmt.Sprintf("[%s]@email", user.Email)
},
sbsVerify: func(user *kbtest.FakeUser, g *libkb.GlobalContext) {
kbtest.VerifyEmailAuto(libkb.NewMetaContextTODO(g), user.Email)
email := keybase1.EmailAddress(user.Email)
kbtest.VerifyEmailAuto(libkb.NewMetaContextTODO(g), email)
emails.SetVisibilityEmail(libkb.NewMetaContextTODO(g), email, keybase1.IdentityVisibility_PUBLIC)
},
})
}
25 changes: 25 additions & 0 deletions go/client/cmd_email.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
)

func NewCmdEmail(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "email",
Usage: "Manage your emails",
Subcommands: []cli.Command{
NewCmdAddEmail(cl, g),
NewCmdEditEmail(cl, g),
NewCmdDeleteEmail(cl, g),
NewCmdListEmails(cl, g),
NewCmdSetVisibilityEmail(cl, g),
NewCmdSetPrimaryEmail(cl, g),
},
}
}
73 changes: 73 additions & 0 deletions go/client/cmd_email_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2018 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
"errors"
"fmt"
"strings"

"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)

type CmdAddEmail struct {
libkb.Contextified
Email string
Visibility keybase1.IdentityVisibility
}

func NewCmdAddEmail(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &CmdAddEmail{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "add",
Usage: "Add email to your Keybase account",
ArgumentHelp: "<email> <private|public>",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "add", c)
},
}
}

func (c *CmdAddEmail) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 2 {
return errors.New("invalid number of arguments.")
}
c.Email = ctx.Args()[0]
visibility, ok := keybase1.IdentityVisibilityMap[strings.ToUpper(ctx.Args()[1])]
if !ok {
return fmt.Errorf("Unknown identity visibility: %s", visibility)
}
c.Visibility = visibility
return nil
}

func (c *CmdAddEmail) Run() error {
cli, err := GetEmailsClient(c.G())
if err != nil {
return err
}
arg := keybase1.AddEmailArg{
Email: keybase1.EmailAddress(c.Email),
Visibility: c.Visibility,
}
err = cli.AddEmail(context.Background(), arg)
if err != nil {
return err
}
fmt.Println("A verification code has been sent to your email.")
return nil
}

func (c *CmdAddEmail) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}
59 changes: 59 additions & 0 deletions go/client/cmd_email_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2018 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
"errors"

"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)

type CmdDeleteEmail struct {
libkb.Contextified
Email string
}

func NewCmdDeleteEmail(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &CmdDeleteEmail{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "delete",
Usage: "Delete email from your Keybase account",
ArgumentHelp: "<email>",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "delete", c)
},
}
}

func (c *CmdDeleteEmail) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
return errors.New("invalid number of arguments.")
}
c.Email = ctx.Args()[0]
return nil
}

func (c *CmdDeleteEmail) Run() error {
cli, err := GetEmailsClient(c.G())
if err != nil {
return err
}
arg := keybase1.DeleteEmailArg{
Email: keybase1.EmailAddress(c.Email),
}
return cli.DeleteEmail(context.Background(), arg)
}

func (c *CmdDeleteEmail) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}
76 changes: 76 additions & 0 deletions go/client/cmd_email_edit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2018 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
"errors"
"fmt"
"strings"

"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)

type CmdEditEmail struct {
libkb.Contextified
OldEmail string
Email string
Visibility keybase1.IdentityVisibility
}

func NewCmdEditEmail(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &CmdEditEmail{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "edit",
Usage: "Edit a email",
ArgumentHelp: "<old email> <new email> <private|public (visibility for new email)>",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "edit", c)
},
}
}

func (c *CmdEditEmail) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 3 {
return errors.New("invalid number of arguments.")
}
c.OldEmail = ctx.Args()[0]
c.Email = ctx.Args()[1]
visibility, ok := keybase1.IdentityVisibilityMap[strings.ToUpper(ctx.Args()[2])]
if !ok {
return fmt.Errorf("Unknown identity visibility: %s", visibility)
}
c.Visibility = visibility
return nil
}

func (c *CmdEditEmail) Run() error {
cli, err := GetEmailsClient(c.G())
if err != nil {
return err
}
arg := keybase1.EditEmailArg{
OldEmail: keybase1.EmailAddress(c.OldEmail),
Email: keybase1.EmailAddress(c.Email),
Visibility: c.Visibility,
}
err = cli.EditEmail(context.Background(), arg)
if err != nil {
return err
}
fmt.Println("A verification code has been sent to your email.`")
return nil
}

func (c *CmdEditEmail) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}
82 changes: 82 additions & 0 deletions go/client/cmd_email_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2018 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.

package client

import (
"encoding/json"
"errors"

"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)

type CmdListEmails struct {
libkb.Contextified
json bool
}

func NewCmdListEmails(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &CmdListEmails{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "list",
Usage: "List emails attached to your account",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "j, json",
Usage: "Output as JSON",
},
},
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "list", c)
},
}
}

func (c *CmdListEmails) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 0 {
return errors.New("invalid number of arguments.")
}
c.json = ctx.Bool("json")
return nil
}

func (c *CmdListEmails) Run() error {
cli, err := GetEmailsClient(c.G())
if err != nil {
return err
}
resp, err := cli.GetEmails(context.Background(), 0)
if err != nil {
return err
}

ui := c.G().UI.GetTerminalUI()
if c.json {
b, err := json.Marshal(resp)
if err != nil {
return err
}
ui.Printf("%s\n", string(b))
return nil
}

for _, p := range resp {
visibilityName := keybase1.IdentityVisibilityRevMap[p.Visibility]
ui.Printf("%s (visibility: %s, verified: %t, primary: %t)\n", p.Email,
visibilityName, p.IsVerified, p.IsPrimary)
}
return nil
}

func (c *CmdListEmails) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}
Loading

0 comments on commit e46b4b0

Please sign in to comment.