open-vault/api/ssh.go

72 lines
1.7 KiB
Go
Raw Normal View History

package api
2015-06-30 02:00:08 +00:00
import (
"encoding/json"
"fmt"
)
2015-07-02 21:23:09 +00:00
// SSH is used to return a client to invoke operations on SSH backend.
2015-07-01 15:58:49 +00:00
type SSH struct {
c *Client
}
2015-07-02 21:23:09 +00:00
// SSH is used to return the client for logical-backend API calls.
2015-07-01 15:58:49 +00:00
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
}
2015-07-02 21:23:09 +00:00
// Invokes the SSH backend API to create a dynamic key
2015-07-01 15:58:49 +00:00
func (c *SSH) KeyCreate(role string, data map[string]interface{}) (*Secret, error) {
r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/ssh/creds/%s", role))
if err := r.SetJSONBody(data); err != nil {
return nil, err
}
resp, err := c.c.RawRequest(r)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return ParseSecret(resp.Body)
}
2015-06-30 02:00:08 +00:00
2015-07-02 21:23:09 +00:00
// Invokes the SSH backend API to list the roles associated with given IP address.
2015-07-01 15:58:49 +00:00
func (c *SSH) Lookup(data map[string]interface{}) (*SSHRoles, error) {
2015-06-30 02:00:08 +00:00
r := c.c.NewRequest("PUT", "/v1/ssh/lookup")
if err := r.SetJSONBody(data); err != nil {
return nil, err
}
resp, err := c.c.RawRequest(r)
if err != nil {
return nil, err
}
defer resp.Body.Close()
2015-07-01 15:58:49 +00:00
var roles SSHRoles
2015-06-30 02:00:08 +00:00
dec := json.NewDecoder(resp.Body)
if err := dec.Decode(&roles); err != nil {
return nil, err
}
return &roles, nil
}
2015-07-02 21:23:09 +00:00
// Structures for the requests/resposne are all down here. They aren't
// individually documentd because the map almost directly to the raw HTTP API
// documentation. Please refer to that documentation for more details.
2015-07-01 15:58:49 +00:00
type SSHRoles struct {
2015-06-30 02:00:08 +00:00
Data map[string]interface{} `json:"data"`
}