github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/client/cmd_pgp_drop.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package client
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"golang.org/x/net/context"
    10  
    11  	"github.com/keybase/cli"
    12  	"github.com/keybase/client/go/libcmdline"
    13  	"github.com/keybase/client/go/libkb"
    14  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    15  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    16  )
    17  
    18  type CmdPGPDrop struct {
    19  	libkb.Contextified
    20  	id keybase1.KID
    21  }
    22  
    23  func (c *CmdPGPDrop) ParseArgv(ctx *cli.Context) (err error) {
    24  	if len(ctx.Args()) != 1 {
    25  		return fmt.Errorf("drop takes exactly one key")
    26  	}
    27  	c.id, err = keybase1.KIDFromStringChecked(ctx.Args()[0])
    28  	if err != nil {
    29  		return fmt.Errorf("bad key: %v", err)
    30  	}
    31  	return nil
    32  }
    33  
    34  func (c *CmdPGPDrop) Run() (err error) {
    35  	cli, err := GetRevokeClient(c.G())
    36  	if err != nil {
    37  		return err
    38  	}
    39  
    40  	protocols := []rpc.Protocol{
    41  		NewSecretUIProtocol(c.G()),
    42  	}
    43  	if err = RegisterProtocolsWithContext(protocols, c.G()); err != nil {
    44  		return err
    45  	}
    46  
    47  	return cli.RevokeKey(context.TODO(), keybase1.RevokeKeyArg{
    48  		KeyID: c.id,
    49  	})
    50  }
    51  
    52  func NewCmdPGPDrop(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    53  	return cli.Command{
    54  		Name:         "drop",
    55  		ArgumentHelp: "<key-id>",
    56  		Usage:        "Drop Keybase's use of a PGP key",
    57  		Flags:        []cli.Flag{},
    58  		Action: func(c *cli.Context) {
    59  			cl.ChooseCommand(&CmdPGPDrop{Contextified: libkb.NewContextified(g)}, "drop", c)
    60  		},
    61  		Description: `"keybase pgp drop" signs a statement saying the given PGP
    62     key should no longer be associated with this account. It will **not** sign a PGP-style
    63     revocation cert for this key; you'll have to do that on your own.`,
    64  	}
    65  }
    66  
    67  func (c *CmdPGPDrop) GetUsage() libkb.Usage {
    68  	return libkb.Usage{
    69  		Config:     true,
    70  		GpgKeyring: true,
    71  		KbKeyring:  true,
    72  		API:        true,
    73  	}
    74  }