2015-03-12 00:46:25 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Secret is the structure returned for every secret within Vault.
|
|
|
|
type Secret struct {
|
2015-04-08 20:35:32 +00:00
|
|
|
LeaseID string `json:"lease_id"`
|
2015-04-05 00:42:19 +00:00
|
|
|
Renewable bool `json:"renewable"`
|
2015-03-16 20:29:51 +00:00
|
|
|
LeaseDuration int `json:"lease_duration"`
|
|
|
|
Data map[string]interface{} `json:"data"`
|
2015-04-04 22:40:41 +00:00
|
|
|
Auth *SecretAuth `json:"auth,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auth is the structure containing auth information if we have it.
|
|
|
|
type SecretAuth struct {
|
|
|
|
ClientToken string `json:"client_Token"`
|
|
|
|
Policies []string `json:"policies"`
|
|
|
|
Metadata map[string]string `json:"metadata"`
|
|
|
|
|
|
|
|
LeaseDuration int `json:"lease_duration"`
|
|
|
|
Renewable bool `json:"renewable"`
|
2015-03-12 00:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParseSecret is used to parse a secret value from JSON from an io.Reader.
|
|
|
|
func ParseSecret(r io.Reader) (*Secret, error) {
|
|
|
|
// First decode the JSON into a map[string]interface{}
|
2015-03-16 03:35:33 +00:00
|
|
|
var secret Secret
|
2015-03-12 00:46:25 +00:00
|
|
|
dec := json.NewDecoder(r)
|
2015-03-16 03:35:33 +00:00
|
|
|
if err := dec.Decode(&secret); err != nil {
|
2015-03-12 00:46:25 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-03-16 03:35:33 +00:00
|
|
|
return &secret, nil
|
2015-03-12 00:46:25 +00:00
|
|
|
}
|