2015-03-16 02:47:32 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
// Logical is used to perform logical backend operations on Vault.
|
|
|
|
type Logical struct {
|
|
|
|
c *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// Logical is used to return the client for logical-backend API calls.
|
|
|
|
func (c *Client) Logical() *Logical {
|
|
|
|
return &Logical{c: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Logical) Read(path string) (*Secret, error) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/"+path)
|
|
|
|
resp, err := c.c.RawRequest(r)
|
2015-04-07 18:15:20 +00:00
|
|
|
if resp != nil && resp.StatusCode == 404 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2015-03-16 02:47:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
return ParseSecret(resp.Body)
|
|
|
|
}
|
|
|
|
|
2015-04-06 16:53:43 +00:00
|
|
|
func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, error) {
|
2015-03-16 02:47:32 +00:00
|
|
|
r := c.c.NewRequest("PUT", "/v1/"+path)
|
|
|
|
if err := r.SetJSONBody(data); err != nil {
|
2015-04-06 16:53:43 +00:00
|
|
|
return nil, err
|
2015-03-16 02:47:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.c.RawRequest(r)
|
|
|
|
if err != nil {
|
2015-04-06 16:53:43 +00:00
|
|
|
return nil, err
|
2015-03-16 02:47:32 +00:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2015-04-06 16:53:43 +00:00
|
|
|
if resp.StatusCode == 200 {
|
|
|
|
return ParseSecret(resp.Body)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
2015-03-16 02:47:32 +00:00
|
|
|
}
|
2015-04-07 18:04:56 +00:00
|
|
|
|
|
|
|
func (c *Logical) Delete(path string) (*Secret, error) {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/"+path)
|
|
|
|
resp, err := c.c.RawRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2015-04-07 18:15:20 +00:00
|
|
|
if resp.StatusCode == 200 {
|
|
|
|
return ParseSecret(resp.Body)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
2015-04-07 18:04:56 +00:00
|
|
|
}
|