[v3.2] Add grafana dashboard importing API (#11)

* Add API to import grafana templates to kubesphere dashboard
* Merge and fix the latest codes from kubesphere #2501

Signed-off-by: zhu733756 <talonzhu@yunify.com>
This commit is contained in:
zhu733756
2021-08-16 11:41:29 +08:00
committed by zhu733756
parent 9df6df5544
commit 242ceb54f6
217 changed files with 119028 additions and 96 deletions

34
vendor/github.com/grafana-tools/sdk/rest-snapshot.go generated vendored Normal file
View File

@@ -0,0 +1,34 @@
package sdk
import (
"context"
"encoding/json"
"fmt"
"github.com/pkg/errors"
)
// https://grafana.com/docs/grafana/latest/http_api/snapshot/
// CreateAnnotation creates a new snapshot.
func (r *Client) CreateSnapshot(ctx context.Context, a CreateSnapshotRequest) (StatusMessage, error) {
var (
raw []byte
resp StatusMessage
err error
code int
)
if raw, err = json.Marshal(a); err != nil {
return StatusMessage{}, errors.Wrap(err, "marshal request")
}
if raw, code, err = r.post(ctx, "api/snapshots", nil, raw); err != nil {
return StatusMessage{}, errors.Wrap(err, "create snapshot")
}
if code/100 != 2 {
return StatusMessage{}, fmt.Errorf("bad response: %d", code)
}
if err = json.Unmarshal(raw, &resp); err != nil {
return StatusMessage{}, errors.Wrap(err, "unmarshal response message")
}
return resp, nil
}