435c0d9fc8
This PR switches the Nomad repository from using govendor to Go modules for managing dependencies. Aspects of the Nomad workflow remain pretty much the same. The usual Makefile targets should continue to work as they always did. The API submodule simply defers to the parent Nomad version on the repository, keeping the semantics of API versioning that currently exists.
40 lines
909 B
Go
40 lines
909 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// Permissions represents the response of GET /permissions
|
|
type Permissions map[string]PermCategory
|
|
|
|
// PermCategory represents Permissions's fields
|
|
type PermCategory map[string][]string
|
|
|
|
// permissions represents the permissions
|
|
type permissionsResponse struct {
|
|
Permissions Permissions `json:"permissions"`
|
|
}
|
|
|
|
// GetPermissions returns the permissions
|
|
func (s *API) GetPermissions() (Permissions, error) {
|
|
resp, err := s.GetResponsePaginate(AccountAPI, fmt.Sprintf("tokens/%s/permissions", s.Token), url.Values{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
body, err := s.handleHTTPError([]int{http.StatusOK}, resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var permissions permissionsResponse
|
|
|
|
if err = json.Unmarshal(body, &permissions); err != nil {
|
|
return nil, err
|
|
}
|
|
return permissions.Permissions, nil
|
|
}
|