refactor(grafanabackuper): add restore function

This commit is contained in:
Tom Neuber 2024-08-19 20:12:28 +02:00
parent 83a15b5a87
commit 1f0d76ba9e
Signed by: tom
GPG key ID: F17EFE4272D89FF6
9 changed files with 214 additions and 8 deletions

View file

@ -79,9 +79,6 @@ type DashboardCreateOpts struct {
}
func (o DashboardCreateOpts) Validate() error {
if o.FolderUID == "" && o.FolderID == 0 {
return errors.New("folder ID or UID missing")
}
if o.Dashboard == nil {
return errors.New("dashboard is nil")
}
@ -111,7 +108,7 @@ func (c *DashboardClient) Create(
reqBody.Message = opts.Message
if opts.FolderUID != "" {
reqBody.FolderUID = opts.FolderUID
} else {
} else if opts.FolderID > 0 {
reqBody.FolderID = opts.FolderID
}
@ -142,3 +139,12 @@ func (c *DashboardClient) Delete(ctx context.Context, uid string) (*Response, er
return c.client.do(req, nil)
}
func (c *DashboardClient) ParseRaw(raw []byte) (*Dashboard, error) {
var body schema.Dashboard
if err := json.Unmarshal(raw, &body); err != nil {
return nil, err
}
return DashboardFromSchema(body), nil
}