github.com/keybase/client/go@v0.0.0-20240520164431-4f512a4c85a3/client/cmd_sigs_revoke.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  	"strings"
     9  
    10  	"golang.org/x/net/context"
    11  
    12  	"github.com/keybase/cli"
    13  	"github.com/keybase/client/go/libcmdline"
    14  	"github.com/keybase/client/go/libkb"
    15  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    16  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
    17  )
    18  
    19  type CmdSigsRevoke struct {
    20  	libkb.Contextified
    21  	queries []string
    22  }
    23  
    24  func (c *CmdSigsRevoke) ParseArgv(ctx *cli.Context) error {
    25  	if len(ctx.Args()) == 0 {
    26  		return fmt.Errorf("No arguments given to sigs revoke.")
    27  	}
    28  
    29  	for _, arg := range ctx.Args() {
    30  		if len(arg) < keybase1.SigIDQueryMin {
    31  			return fmt.Errorf("sig id %q is too short; must be at least 16 characters long", arg)
    32  		}
    33  		c.queries = append(c.queries, strings.TrimSuffix(arg, "..."))
    34  	}
    35  
    36  	return nil
    37  }
    38  
    39  func (c *CmdSigsRevoke) Run() error {
    40  	cli, err := GetRevokeClient(c.G())
    41  	if err != nil {
    42  		return err
    43  	}
    44  
    45  	protocols := []rpc.Protocol{
    46  		NewSecretUIProtocol(c.G()),
    47  	}
    48  	if err = RegisterProtocolsWithContext(protocols, c.G()); err != nil {
    49  		return err
    50  	}
    51  
    52  	return cli.RevokeSigs(context.TODO(), keybase1.RevokeSigsArg{
    53  		SigIDQueries: c.queries,
    54  	})
    55  }
    56  
    57  func NewCmdSigsRevoke(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    58  	return cli.Command{
    59  		Name:         "revoke",
    60  		ArgumentHelp: "<sig-id>",
    61  		Usage:        "revoke a signature by sig ID",
    62  		Action: func(c *cli.Context) {
    63  			cl.ChooseCommand(&CmdSigsRevoke{Contextified: libkb.NewContextified(g)}, "revoke", c)
    64  		},
    65  		Flags: nil,
    66  		Description: `"keybase sigs revoke" revokes a signature in your sigchain
    67     by its ID. You can look up what is in your sigchain via "keybase sigs list". This is
    68     an advanced feature that we don't recommend using unless you know what you're doing.
    69  `,
    70  	}
    71  }
    72  
    73  func (c *CmdSigsRevoke) GetUsage() libkb.Usage {
    74  	return libkb.Usage{
    75  		Config:     true,
    76  		GpgKeyring: true,
    77  		KbKeyring:  true,
    78  		API:        true,
    79  	}
    80  }