-
Notifications
You must be signed in to change notification settings - Fork 1
/
disconnect.go
63 lines (48 loc) · 1.34 KB
/
disconnect.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package vaulthcplib
import (
"fmt"
"strings"
"github.com/hashicorp/hcp-sdk-go/config"
"github.com/mitchellh/go-homedir"
"github.com/hashicorp/cli"
)
var _ cli.Command = (*HCPDisconnectCommand)(nil)
type HCPDisconnectCommand struct {
Ui cli.Ui
}
func (c *HCPDisconnectCommand) Help() string {
helpText := `
Usage: vault hcp disconnect [options]
Cleans up the cache with the HCP credentials used to connect to a HCP Vault cluster.
$ vault hcp disconnect
`
return strings.TrimSpace(helpText)
}
func (c *HCPDisconnectCommand) Run(_ []string) int {
path, err := homedir.Dir()
if err != nil {
c.Ui.Error(fmt.Sprintf("\nFailed to find home directory: %s", err))
return 1
}
if err := eraseConfig(path); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to disconnect from HCP Vault Cluster: %s", err))
return 1
}
opts := []config.HCPConfigOption{config.FromEnv()}
cfg, err := config.NewHCPConfig(opts...)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to disconnect from HCP Vault Cluster: %s", err))
return 1
}
err = cfg.Logout()
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to disconnect from HCP Vault Cluster: %s", err))
return 1
}
return 0
}
func (c *HCPDisconnectCommand) Synopsis() string {
return "Disconnect from the HCP Vault Cluster"
}