-
Notifications
You must be signed in to change notification settings - Fork 255
/
remove.go
76 lines (60 loc) · 1.74 KB
/
remove.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package eab
import (
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli"
"go.step.sm/cli-utils/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils/cautils"
)
func removeCommand() cli.Command {
return cli.Command{
Name: "remove",
Action: cli.ActionFunc(removeAction),
Usage: "remove an ACME EAB Key from the CA",
UsageText: `**step ca acme eab remove** <provisioner> <eab-key-id>
[**--admin-cert**=<file>] [**--admin-key**=<file>] [**--admin-subject**=<subject>]
[**--admin-provisioner**=<name>] [**--admin-password-file**=<file>]
[**--ca-url**=<uri>] [**--root**=<file>] [**--context**=<name>]`,
Flags: []cli.Flag{
flags.AdminCert,
flags.AdminKey,
flags.AdminSubject,
flags.AdminProvisioner,
flags.AdminPasswordFile,
flags.CaURL,
flags.Root,
flags.Context,
},
Description: `**step ca acme eab remove** removes an ACME EAB Key from the CA.
## POSITIONAL ARGUMENTS
<provisioner>
: Name of the provisioner to remove an ACME EAB key for
<eab-key-id>
: The ACME EAB Key ID to remove
## EXAMPLES
Remove ACME EAB Key with Key ID "zFGdKC1sHmNf3Wsx3OujY808chxwEdmr" from my_acme_provisioner:
'''
$ step ca acme eab remove my_acme_provisioner zFGdKC1sHmNf3Wsx3OujY808chxwEdmr
'''
`,
}
}
func removeAction(ctx *cli.Context) error {
if err := errs.NumberOfArguments(ctx, 2); err != nil {
return err
}
args := ctx.Args()
provisioner := args.Get(0)
keyID := args.Get(1)
client, err := cautils.NewAdminClient(ctx)
if err != nil {
return errors.Wrap(err, "error creating admin client")
}
err = client.RemoveExternalAccountKey(provisioner, keyID)
if err != nil {
return errors.Wrap(notImplemented(err), "error removing ACME EAB key")
}
fmt.Println("Key was deleted successfully!")
return nil
}