feat(grafana): add new api response for dashboard versions #65

Merged
tom merged 1 commit from tn-fix-breaking-api-change into main 2025-04-09 02:07:12 +02:00
2 changed files with 25 additions and 7 deletions
Showing only changes of commit 5106b946f3 - Show all commits

View file

@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"strconv"
"strings"
"time"
"git.ar21.de/yolokube/grafana-backuper/pkg/grafana/schema"
@ -167,15 +168,25 @@ func (c *DashboardVersionClient) list(
return nil, nil, err
}
var body schema.DashboardVersionListResponse
var versions schema.DashboardVersionListResponseV10
body := schema.DashboardVersionListResponse{}
resp, err := c.client.do(req, &body)
if err != nil {
return nil, resp, err
if !strings.Contains(err.Error(), "cannot unmarshal object") {
return nil, resp, err
}
bodyV10 := schema.DashboardVersionListResponseV10{}
resp, err = c.client.do(req, &bodyV10)
if err != nil {
return nil, resp, err
}
versions = bodyV10
} else {
versions = body.Versions
}
dashboardVersions := make([]*DashboardVersion, 0, len(body))
for _, dashboardVersion := range body {
dashboardVersions := make([]*DashboardVersion, 0, len(versions))
for _, dashboardVersion := range versions {
dashboardVersions = append(dashboardVersions, DashboardVersionFromSchema(dashboardVersion))
}

View file

@ -1,6 +1,8 @@
package schema
import "time"
import (
"time"
)
type DashboardVersion struct {
ID uint `json:"id"`
@ -15,4 +17,9 @@ type DashboardVersion struct {
Data any `json:"data"`
}
type DashboardVersionListResponse []DashboardVersion
type DashboardVersionListResponseV10 []DashboardVersion
type DashboardVersionListResponse struct {
ContinueToken string `json:"continueToken"`
Versions DashboardVersionListResponseV10 `json:"versions"`
}