refactor(grafanabackuper): add restore function
This commit is contained in:
parent
83a15b5a87
commit
1f0d76ba9e
9 changed files with 214 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package schema
|
|||
import "time"
|
||||
|
||||
type DashboardCreateRequest struct {
|
||||
Dashboard any `json:"dasboard"`
|
||||
Dashboard any `json:"dashboard"`
|
||||
FolderID uint `json:"folderId,omitempty"`
|
||||
FolderUID string `json:"folderUid"`
|
||||
Message string `json:"message,omitempty"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue