terraform/vendor/github.com/apparentlymart/go-grafana-api/admin.go

47 lines
853 B
Go
Raw Normal View History

package gapi
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"github.com/grafana/grafana/pkg/api/dtos"
)
func (c *Client) CreateUserForm(settings dtos.AdminCreateUserForm) error {
data, err := json.Marshal(settings)
req, err := c.newRequest("POST", "/api/admin/users", bytes.NewBuffer(data))
if err != nil {
return err
}
resp, err := c.Do(req)
if err != nil {
return err
}
data, err = ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if resp.StatusCode != 200 {
return errors.New(resp.Status)
}
return err
}
func (c *Client) DeleteUser(id int64) error {
req, err := c.newRequest("DELETE", fmt.Sprintf("/api/admin/users/%d", id), nil)
if err != nil {
return err
}
resp, err := c.Do(req)
if err != nil {
return err
}
if resp.StatusCode != 200 {
return errors.New(resp.Status)
}
return err
}