2015-03-11 19:03:28 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
func (c *Sys) SealStatus() (*SealStatusResponse, error) {
|
2015-03-13 17:32:22 +00:00
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/seal-status")
|
2015-10-28 19:59:39 +00:00
|
|
|
return sealStatusRequest(c, r)
|
2015-03-11 19:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) Seal() error {
|
2015-03-13 17:32:22 +00:00
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/seal")
|
2015-03-11 19:03:28 +00:00
|
|
|
resp, err := c.c.RawRequest(r)
|
2015-03-31 18:46:55 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
2015-03-11 19:03:28 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-10-28 19:59:39 +00:00
|
|
|
func (c *Sys) ResetUnsealProcess() (*SealStatusResponse, error) {
|
|
|
|
body := map[string]interface{}{"reset": true}
|
|
|
|
|
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/unseal")
|
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sealStatusRequest(c, r)
|
|
|
|
}
|
|
|
|
|
2015-03-11 19:03:28 +00:00
|
|
|
func (c *Sys) Unseal(shard string) (*SealStatusResponse, error) {
|
|
|
|
body := map[string]interface{}{"key": shard}
|
|
|
|
|
2015-03-13 17:32:22 +00:00
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/unseal")
|
2015-03-11 19:03:28 +00:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-10-28 19:59:39 +00:00
|
|
|
return sealStatusRequest(c, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func sealStatusRequest(c *Sys, r *Request) (*SealStatusResponse, error) {
|
2015-03-11 19:03:28 +00:00
|
|
|
resp, err := c.c.RawRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result SealStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type SealStatusResponse struct {
|
|
|
|
Sealed bool
|
|
|
|
T int
|
|
|
|
N int
|
|
|
|
Progress int
|
|
|
|
}
|