commit 1646fdebffc4c9069b824f65f8639120c224f312 from: Oliver Lowe date: Tue Jan 18 15:04:52 2022 UTC Actually return permissions grante to the client Before we were just returning an empty response or something non-meaningful commit - cb9dde9996675a4d56608eab8b57109da8484c29 commit + 1646fdebffc4c9069b824f65f8639120c224f312 blob - abf172361df21abb4d49a34ecdc7152bed0c610c blob + 797ffc7d61ba66c1916413dc17d6e1909b03b8e3 --- icinga.go +++ icinga.go @@ -76,19 +76,28 @@ var ErrNoMatch = errors.New("no object matches filter" // skips TLS certificate verification. func Dial(addr, username, password string, client *http.Client) (*Client, error) { c := &Client{addr, username, password, client} - if _, err := c.Permissions(); err != nil { + if _, err := Permissions(c); err != nil { return nil, err } return c, nil } -func (c *Client) Permissions() (response, error) { +// Permissions returns the permissions granted to the Client. +func Permissions(c *Client) ([]string, error) { resp, err := c.get("", "") if err != nil { - return response{}, err + return nil, err } - if resp.StatusCode == http.StatusOK { - return response{}, nil + if resp.StatusCode != http.StatusOK { + return nil, errors.New(resp.Status) } - return response{}, errors.New(resp.Status) + defer resp.Body.Close() + apiresp, err := parseAPIResponse(resp.Body) + if err != nil { + return nil, err + } + for i := range apiresp.Results { + return apiresp.Results[i].Permissions, nil + } + return nil, errors.New("no permissions") } blob - 361a05a781c92dbda52c8eff75efdc3723fa8769 blob + f80e37d055df98e1df88ffe8fd5fb1f9d518b6e0 --- response.go +++ response.go @@ -10,10 +10,11 @@ import ( type apiResponse struct { Results []struct { - Name string - Type string - Errors []string - Attrs json.RawMessage + Name string + Type string + Errors []string + Permissions []string + Attrs json.RawMessage } Status string }