2016-03-02 18:42:32 +00:00
|
|
|
package api
|
|
|
|
|
2016-03-04 18:21:07 +00:00
|
|
|
func (c *Sys) CapabilitiesSelf(path string) ([]string, error) {
|
2016-03-02 18:42:32 +00: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 19:14:17 +00:00
|
|
|
var result map[string]interface{}
|
2016-03-02 18:42:32 +00:00
|
|
|
err = resp.DecodeJSON(&result)
|
2016-03-17 19:14:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var capabilities []string
|
2016-03-18 02:29:53 +00:00
|
|
|
capabilitiesRaw := result["capabilities"].([]interface{})
|
2016-03-17 19:14:17 +00:00
|
|
|
for _, capability := range capabilitiesRaw {
|
|
|
|
capabilities = append(capabilities, capability.(string))
|
|
|
|
}
|
|
|
|
return capabilities, nil
|
2016-03-02 18:42:32 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 18:21:07 +00:00
|
|
|
func (c *Sys) Capabilities(token, path string) ([]string, error) {
|
2016-03-02 18:42:32 +00: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 19:14:17 +00:00
|
|
|
var result map[string]interface{}
|
2016-03-02 18:42:32 +00:00
|
|
|
err = resp.DecodeJSON(&result)
|
2016-03-17 19:14:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var capabilities []string
|
2016-03-18 02:29:53 +00:00
|
|
|
capabilitiesRaw := result["capabilities"].([]interface{})
|
2016-03-17 19:14:17 +00:00
|
|
|
for _, capability := range capabilitiesRaw {
|
|
|
|
capabilities = append(capabilities, capability.(string))
|
|
|
|
}
|
|
|
|
return capabilities, nil
|
2016-03-02 18:42:32 +00:00
|
|
|
}
|