You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
801 B
46 lines
801 B
5 years ago
|
package keybase
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
)
|
||
|
|
||
|
// kvAPIOut sends a JSON request to the kvstore API and returns its response.
|
||
|
func kvAPIOut(k *Keybase, kv KVAPI) (KVAPI, error) {
|
||
|
jsonBytes, _ := json.Marshal(kv)
|
||
|
|
||
|
cmdOut, err := k.Exec("kvstore", "api", "-m", string(jsonBytes))
|
||
|
if err != nil {
|
||
|
return KVAPI{}, err
|
||
|
}
|
||
|
|
||
|
var r KVAPI
|
||
|
if err := json.Unmarshal(cmdOut, &r); err != nil {
|
||
|
return KVAPI{}, err
|
||
|
}
|
||
|
|
||
|
if r.Error != nil {
|
||
|
return KVAPI{}, errors.New(r.Error.Message)
|
||
|
}
|
||
|
|
||
|
return r, nil
|
||
|
}
|
||
|
|
||
|
// Namespaces returns all namespaces for a team
|
||
|
func (kv KV) Namespaces() (KVAPI, error) {
|
||
|
m := KVAPI{
|
||
|
Params: &kvParams{},
|
||
|
}
|
||
|
m.Params.Options = kvOptions{
|
||
|
Team: kv.Team,
|
||
|
}
|
||
|
|
||
|
m.Method = "list"
|
||
|
|
||
|
r, err := kvAPIOut(kv.keybase, m)
|
||
|
if err != nil {
|
||
|
return r, err
|
||
|
}
|
||
|
return r, nil
|
||
|
}
|