2015-03-11 19:03:28 +00:00
|
|
|
package api
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
import "context"
|
|
|
|
|
2015-03-11 19:03:28 +00:00
|
|
|
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")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2018-10-23 06:34:02 +00:00
|
|
|
func (c *Sys) UnsealWithOptions(opts *UnsealOpts) (*SealStatusResponse, error) {
|
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/unseal")
|
|
|
|
if err := r.SetJSONBody(opts); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sealStatusRequest(c, r)
|
|
|
|
}
|
|
|
|
|
2015-10-28 19:59:39 +00:00
|
|
|
func sealStatusRequest(c *Sys, r *Request) (*SealStatusResponse, error) {
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2015-03-11 19:03:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result SealStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type SealStatusResponse struct {
|
2017-12-18 14:58:14 +00:00
|
|
|
Type string `json:"type"`
|
2018-09-27 21:03:37 +00:00
|
|
|
Initialized bool `json:"initialized"`
|
2017-12-18 14:58:14 +00:00
|
|
|
Sealed bool `json:"sealed"`
|
|
|
|
T int `json:"t"`
|
|
|
|
N int `json:"n"`
|
|
|
|
Progress int `json:"progress"`
|
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
Version string `json:"version"`
|
2018-10-23 06:34:02 +00:00
|
|
|
Migration bool `json:"migration"`
|
2017-12-18 14:58:14 +00:00
|
|
|
ClusterName string `json:"cluster_name,omitempty"`
|
|
|
|
ClusterID string `json:"cluster_id,omitempty"`
|
|
|
|
RecoverySeal bool `json:"recovery_seal"`
|
2015-03-11 19:03:28 +00:00
|
|
|
}
|
2018-10-23 06:34:02 +00:00
|
|
|
|
|
|
|
type UnsealOpts struct {
|
|
|
|
Key string `json:"key"`
|
|
|
|
Reset bool `json:"reset"`
|
|
|
|
Migrate bool `json:"migrate"`
|
|
|
|
}
|