refactor(grafana): replace dashboard info with import compatible layout

This commit is contained in:
Tom Neuber 2024-07-27 18:53:38 +02:00
parent 4aad919153
commit 577f821b9d
Signed by: tom
GPG key ID: F17EFE4272D89FF6
8 changed files with 173 additions and 110 deletions

View file

@ -11,7 +11,7 @@ import (
"git.ar21.de/yolokube/grafana-backuper/pkg/grafana/schema"
)
type DashboardMeta struct {
type Dashboard struct {
IsStarred bool
Type string
CanSave bool
@ -54,20 +54,20 @@ type DashboardClient struct {
client *Client
}
func (c *DashboardClient) Get(ctx context.Context, uid string) (*DashboardMeta, *Response, error) {
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/dashboards/uid/%s", uid), nil)
func (c *DashboardClient) Get(ctx context.Context, uid string) (*Dashboard, *Response, error) {
req, err := c.client.newRequest(ctx, "GET", fmt.Sprintf("/dashboards/uid/%s", uid), nil)
if err != nil {
return nil, nil, err
}
var body schema.DashboardMeta
var body schema.Dashboard
resp, err := c.client.Do(req, &body)
resp, err := c.client.do(req, &body)
if err != nil {
return nil, resp, err
}
return DashboardMetaFromSchema(body), resp, nil
return DashboardFromSchema(body), resp, nil
}
type DashboardCreateOpts struct {
@ -120,13 +120,13 @@ func (c *DashboardClient) Create(
return nil, nil, err
}
req, err := c.client.NewRequest(ctx, "POST", "/dashboards/db", bytes.NewReader(reqBodyData))
req, err := c.client.newRequest(ctx, "POST", "/dashboards/db", bytes.NewReader(reqBodyData))
if err != nil {
return nil, nil, err
}
var respBody schema.DashboardCreateResponse
resp, err := c.client.Do(req, &respBody)
resp, err := c.client.do(req, &respBody)
if err != nil {
return nil, resp, err
}
@ -135,10 +135,10 @@ func (c *DashboardClient) Create(
}
func (c *DashboardClient) Delete(ctx context.Context, uid string) (*Response, error) {
req, err := c.client.NewRequest(ctx, "DELETE", fmt.Sprintf("/dashboards/uid/%s", uid), nil)
req, err := c.client.newRequest(ctx, "DELETE", fmt.Sprintf("/dashboards/uid/%s", uid), nil)
if err != nil {
return nil, err
}
return c.client.Do(req, nil)
return c.client.do(req, nil)
}