mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-04 12:01:23 +02:00
Vault SSH: Revoking key after SSH session from CLI
This commit is contained in:
parent
280efd28f6
commit
0a59e84cef
10
api/ssh.go
10
api/ssh.go
@ -15,6 +15,16 @@ func (c *Client) SSH() *SSH {
|
||||
return &SSH{c: c}
|
||||
}
|
||||
|
||||
// Invokes the SSH backend API to revoke a key identified by its lease ID.
|
||||
func (c *SSH) KeyRevoke(id string) error {
|
||||
r := c.c.NewRequest("PUT", "/v1/sys/revoke/"+id)
|
||||
resp, err := c.c.RawRequest(r)
|
||||
if err == nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Invokes the SSH backend API to create a dynamic key
|
||||
func (c *SSH) KeyCreate(role string, data map[string]interface{}) (*Secret, error) {
|
||||
r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/ssh/creds/%s", role))
|
||||
|
||||
@ -80,7 +80,12 @@ func (c *SSHCommand) Run(args []string) int {
|
||||
|
||||
err = os.Remove(sshDynamicKeyFileName)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error deleting temporary file:%s", sshDynamicKeyFileName))
|
||||
c.Ui.Error("Error cleaning up") // Intentionally not mentioning the exact error
|
||||
}
|
||||
|
||||
err = client.SSH().KeyRevoke(keySecret.LeaseID)
|
||||
if err != nil {
|
||||
c.Ui.Error("Error cleaning up") // Intentionally not mentioning the exact error
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user