2016-01-09 02:21:02 +00:00
|
|
|
package api
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
import "context"
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
func (c *Sys) GenerateRootStatus() (*GenerateRootStatusResponse, error) {
|
2017-11-10 18:19:42 +00:00
|
|
|
return c.generateRootStatusCommon("/v1/sys/generate-root/attempt")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) GenerateDROperationTokenStatus() (*GenerateRootStatusResponse, error) {
|
2017-11-14 01:28:34 +00:00
|
|
|
return c.generateRootStatusCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt")
|
2017-11-10 18:19:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 04:55:31 +00:00
|
|
|
func (c *Sys) GenerateRecoveryOperationTokenStatus() (*GenerateRootStatusResponse, error) {
|
|
|
|
return c.generateRootStatusCommon("/v1/sys/generate-recovery-token/attempt")
|
|
|
|
}
|
|
|
|
|
2017-11-10 18:19:42 +00:00
|
|
|
func (c *Sys) generateRootStatusCommon(path string) (*GenerateRootStatusResponse, error) {
|
|
|
|
r := c.c.NewRequest("GET", path)
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-01-09 02:21:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
var result GenerateRootStatusResponse
|
2016-01-09 02:21:02 +00:00
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-02-12 19:24:36 +00:00
|
|
|
func (c *Sys) GenerateRootInit(otp, pgpKey string) (*GenerateRootStatusResponse, error) {
|
2017-11-10 18:19:42 +00:00
|
|
|
return c.generateRootInitCommon("/v1/sys/generate-root/attempt", otp, pgpKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) GenerateDROperationTokenInit(otp, pgpKey string) (*GenerateRootStatusResponse, error) {
|
2017-11-14 01:28:34 +00:00
|
|
|
return c.generateRootInitCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt", otp, pgpKey)
|
2017-11-10 18:19:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 04:55:31 +00:00
|
|
|
func (c *Sys) GenerateRecoveryOperationTokenInit(otp, pgpKey string) (*GenerateRootStatusResponse, error) {
|
|
|
|
return c.generateRootInitCommon("/v1/sys/generate-recovery-token/attempt", otp, pgpKey)
|
|
|
|
}
|
|
|
|
|
2017-11-10 18:19:42 +00:00
|
|
|
func (c *Sys) generateRootInitCommon(path, otp, pgpKey string) (*GenerateRootStatusResponse, error) {
|
2016-01-09 02:21:02 +00:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"otp": otp,
|
|
|
|
"pgp_key": pgpKey,
|
|
|
|
}
|
|
|
|
|
2017-11-10 18:19:42 +00:00
|
|
|
r := c.c.NewRequest("PUT", path)
|
2016-01-09 02:21:02 +00:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
2016-02-12 19:24:36 +00:00
|
|
|
return nil, err
|
2016-01-09 02:21:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-02-12 19:24:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-01-09 02:21:02 +00:00
|
|
|
}
|
2016-02-12 19:24:36 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result GenerateRootStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
2016-01-09 02:21:02 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
func (c *Sys) GenerateRootCancel() error {
|
2017-11-10 18:19:42 +00:00
|
|
|
return c.generateRootCancelCommon("/v1/sys/generate-root/attempt")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) GenerateDROperationTokenCancel() error {
|
2017-11-14 01:28:34 +00:00
|
|
|
return c.generateRootCancelCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt")
|
2017-11-10 18:19:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 04:55:31 +00:00
|
|
|
func (c *Sys) GenerateRecoveryOperationTokenCancel() error {
|
|
|
|
return c.generateRootCancelCommon("/v1/sys/generate-recovery-token/attempt")
|
|
|
|
}
|
|
|
|
|
2017-11-10 18:19:42 +00:00
|
|
|
func (c *Sys) generateRootCancelCommon(path string) error {
|
|
|
|
r := c.c.NewRequest("DELETE", path)
|
2018-07-24 22:49:55 +00:00
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-01-09 02:21:02 +00:00
|
|
|
if err == nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
func (c *Sys) GenerateRootUpdate(shard, nonce string) (*GenerateRootStatusResponse, error) {
|
2017-11-10 18:19:42 +00:00
|
|
|
return c.generateRootUpdateCommon("/v1/sys/generate-root/update", shard, nonce)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) GenerateDROperationTokenUpdate(shard, nonce string) (*GenerateRootStatusResponse, error) {
|
2017-11-14 01:28:34 +00:00
|
|
|
return c.generateRootUpdateCommon("/v1/sys/replication/dr/secondary/generate-operation-token/update", shard, nonce)
|
2017-11-10 18:19:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 04:55:31 +00:00
|
|
|
func (c *Sys) GenerateRecoveryOperationTokenUpdate(shard, nonce string) (*GenerateRootStatusResponse, error) {
|
|
|
|
return c.generateRootUpdateCommon("/v1/sys/generate-recovery-token/update", shard, nonce)
|
|
|
|
}
|
|
|
|
|
2017-11-10 18:19:42 +00:00
|
|
|
func (c *Sys) generateRootUpdateCommon(path, shard, nonce string) (*GenerateRootStatusResponse, error) {
|
2016-01-09 02:21:02 +00:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
2017-11-10 18:19:42 +00:00
|
|
|
r := c.c.NewRequest("PUT", path)
|
2016-01-09 02:21:02 +00:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-24 22:49:55 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
defer cancelFunc()
|
|
|
|
resp, err := c.c.RawRequestWithContext(ctx, r)
|
2016-01-09 02:21:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
var result GenerateRootStatusResponse
|
2016-01-09 02:21:02 +00:00
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
type GenerateRootStatusResponse struct {
|
2018-02-12 23:12:16 +00:00
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
Started bool `json:"started"`
|
|
|
|
Progress int `json:"progress"`
|
|
|
|
Required int `json:"required"`
|
|
|
|
Complete bool `json:"complete"`
|
2017-11-13 20:44:26 +00:00
|
|
|
EncodedToken string `json:"encoded_token"`
|
2016-01-09 02:21:02 +00:00
|
|
|
EncodedRootToken string `json:"encoded_root_token"`
|
|
|
|
PGPFingerprint string `json:"pgp_fingerprint"`
|
2018-08-22 18:37:40 +00:00
|
|
|
OTP string `json:"otp"`
|
|
|
|
OTPLength int `json:"otp_length"`
|
2016-01-09 02:21:02 +00:00
|
|
|
}
|