Skip to content
Permalink
Browse files

grafana: add SwitchUserOrg

  • Loading branch information...
birdayz committed May 6, 2019
1 parent bf6892e commit 81cde0ef1a9742cbd17f94fc1d1a471f3bd7df71
Showing with 21 additions and 0 deletions.
  1. +21 −0 pkg/grafana/client.go
@@ -212,3 +212,24 @@ func (c *Client) MakeUserAdmin(userID int) error {
}
return nil
}

func (c *Client) SwitchUserOrg(userID int, orgID int) error {
req, err := http.NewRequest("POST", c.baseURL+"/api/users/"+strconv.Itoa(userID)+"/using/"+strconv.Itoa(orgID), http.NoBody)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")

req.SetBasicAuth(c.user, c.password)
resp, err := c.c.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Wrong status code: %v", resp.StatusCode)
}
return nil

}

0 comments on commit 81cde0e

Please sign in to comment.
You can’t perform that action at this time.