mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
* Grafana provider * grafana_data_source resource. Allows data sources to be created in Grafana. Supports all data source types that are accepted in the current version of Grafana, and will support any future ones that fit into the existing structure. * Vendoring of apparentlymart/go-grafana-api This is in anticipation of adding a Grafana provider plugin. * grafana_dashboard resource * Website documentation for the Grafana provider.
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package gapi
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io/ioutil"
|
|
)
|
|
|
|
type Org struct {
|
|
Id int64
|
|
Name string
|
|
}
|
|
|
|
func (c *Client) Orgs() ([]Org, error) {
|
|
orgs := make([]Org, 0)
|
|
|
|
req, err := c.newRequest("GET", "/api/orgs/", nil)
|
|
if err != nil {
|
|
return orgs, err
|
|
}
|
|
resp, err := c.Do(req)
|
|
if err != nil {
|
|
return orgs, err
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return orgs, errors.New(resp.Status)
|
|
}
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return orgs, err
|
|
}
|
|
err = json.Unmarshal(data, &orgs)
|
|
return orgs, err
|
|
}
|
|
|
|
func (c *Client) NewOrg(name string) error {
|
|
settings := map[string]string{
|
|
"name": name,
|
|
}
|
|
data, err := json.Marshal(settings)
|
|
req, err := c.newRequest("POST", "/api/orgs", bytes.NewBuffer(data))
|
|
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
|
|
}
|
|
|
|
func (c *Client) DeleteOrg(id int64) error {
|
|
req, err := c.newRequest("DELETE", fmt.Sprintf("/api/orgs/%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
|
|
}
|