2016-03-02 21:42:32 +03:00
|
|
|
package api
|
|
|
|
|
2016-03-17 21:07:55 +03:00
|
|
|
import "log"
|
|
|
|
|
2016-03-04 21:21:07 +03:00
|
|
|
func (c *Sys) CapabilitiesSelf(path string) ([]string, error) {
|
2016-03-02 21:42:32 +03:00
|
|
|
body := map[string]string{
|
|
|
|
"path": path,
|
|
|
|
}
|
|
|
|
|
|
|
|
r := c.c.NewRequest("POST", "/v1/sys/capabilities-self")
|
|
|
|
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-03-17 21:07:55 +03:00
|
|
|
log.Printf("capabilities self: resp: %#v\n", resp.Body)
|
2016-03-03 19:08:27 +03:00
|
|
|
var result CapabilitiesResponse
|
2016-03-02 21:42:32 +03:00
|
|
|
err = resp.DecodeJSON(&result)
|
2016-03-04 21:21:07 +03:00
|
|
|
return result.Capabilities, err
|
2016-03-02 21:42:32 +03:00
|
|
|
}
|
|
|
|
|
2016-03-04 21:21:07 +03:00
|
|
|
func (c *Sys) Capabilities(token, path string) ([]string, error) {
|
2016-03-02 21:42:32 +03:00
|
|
|
body := map[string]string{
|
|
|
|
"token": token,
|
|
|
|
"path": path,
|
|
|
|
}
|
|
|
|
|
|
|
|
r := c.c.NewRequest("POST", "/v1/sys/capabilities")
|
|
|
|
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-03-17 21:07:55 +03:00
|
|
|
log.Printf("capabilities: resp: %#v\n", resp.Body)
|
2016-03-03 19:08:27 +03:00
|
|
|
var result CapabilitiesResponse
|
2016-03-02 21:42:32 +03:00
|
|
|
err = resp.DecodeJSON(&result)
|
2016-03-04 21:21:07 +03:00
|
|
|
return result.Capabilities, err
|
2016-03-02 21:42:32 +03:00
|
|
|
}
|
|
|
|
|
2016-03-03 19:08:27 +03:00
|
|
|
type CapabilitiesResponse struct {
|
2016-03-02 21:42:32 +03:00
|
|
|
Capabilities []string `json:"capabilities"`
|
|
|
|
}
|