2016-03-02 21:42:32 +03:00
|
|
|
package api
|
|
|
|
|
2016-08-08 23:00:31 +03:00
|
|
|
import "fmt"
|
2016-03-02 21:42:32 +03:00
|
|
|
|
2016-08-08 23:00:31 +03:00
|
|
|
func (c *Sys) CapabilitiesSelf(path string) ([]string, error) {
|
|
|
|
return c.Capabilities(c.c.Token(), path)
|
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,
|
|
|
|
}
|
|
|
|
|
2016-08-08 23:00:31 +03:00
|
|
|
reqPath := "/v1/sys/capabilities"
|
|
|
|
if token == c.c.Token() {
|
|
|
|
reqPath = fmt.Sprintf("%s-self", reqPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
r := c.c.NewRequest("POST", reqPath)
|
2016-03-02 21:42:32 +03: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-08-14 21:52:45 +03:00
|
|
|
var result map[string]interface{}
|
|
|
|
err = resp.DecodeJSON(&result)
|
2016-03-17 22:14:17 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-08-08 23:00:31 +03:00
|
|
|
|
2016-03-17 22:14:17 +03:00
|
|
|
var capabilities []string
|
2016-08-14 21:52:45 +03:00
|
|
|
capabilitiesRaw := result["capabilities"].([]interface{})
|
2016-03-17 22:14:17 +03:00
|
|
|
for _, capability := range capabilitiesRaw {
|
|
|
|
capabilities = append(capabilities, capability.(string))
|
|
|
|
}
|
|
|
|
return capabilities, nil
|
2016-03-02 21:42:32 +03:00
|
|
|
}
|