2016-01-09 02:21:02 +00:00
|
|
|
package api
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
func (c *Sys) GenerateRootStatus() (*GenerateRootStatusResponse, error) {
|
|
|
|
r := c.c.NewRequest("GET", "/v1/sys/generate-root/attempt")
|
2016-01-09 02:21:02 +00:00
|
|
|
resp, err := c.c.RawRequest(r)
|
|
|
|
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) {
|
2016-01-09 02:21:02 +00:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"otp": otp,
|
|
|
|
"pgp_key": pgpKey,
|
|
|
|
}
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/generate-root/attempt")
|
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
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.c.RawRequest(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 {
|
|
|
|
r := c.c.NewRequest("DELETE", "/v1/sys/generate-root/attempt")
|
2016-01-09 02:21:02 +00:00
|
|
|
resp, err := c.c.RawRequest(r)
|
|
|
|
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) {
|
2016-01-09 02:21:02 +00:00
|
|
|
body := map[string]interface{}{
|
|
|
|
"key": shard,
|
|
|
|
"nonce": nonce,
|
|
|
|
}
|
|
|
|
|
2016-01-15 15:55:35 +00:00
|
|
|
r := c.c.NewRequest("PUT", "/v1/sys/generate-root/update")
|
2016-01-09 02:21:02 +00:00
|
|
|
if err := r.SetJSONBody(body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.c.RawRequest(r)
|
|
|
|
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 {
|
2016-01-09 02:21:02 +00:00
|
|
|
Nonce string
|
|
|
|
Started bool
|
|
|
|
Progress int
|
|
|
|
Required int
|
|
|
|
Complete bool
|
|
|
|
EncodedRootToken string `json:"encoded_root_token"`
|
|
|
|
PGPFingerprint string `json:"pgp_fingerprint"`
|
|
|
|
}
|