From 3a29f45522678de1775a90009db8b34925c8bcc9 Mon Sep 17 00:00:00 2001 From: Federico Fapitalle Date: Fri, 24 May 2024 15:31:29 -0300 Subject: [PATCH 1/3] feat(folders): use API search endpoint for testing folder existence --- folders.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/folders.go b/folders.go index 2c960800..45171e86 100644 --- a/folders.go +++ b/folders.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "net/url" "strings" ) @@ -69,7 +70,7 @@ func (client *Client) CreateFolder(ctx context.Context, name string) (*Folder, e // GetFolderByTitle finds a folder, given its title. func (client *Client) GetFolderByTitle(ctx context.Context, title string) (*Folder, error) { - resp, err := client.get(ctx, "/api/folders?limit=1000") + resp, err := client.get(ctx, fmt.Sprintf("/api/search?query=%s", url.QueryEscape(title))) if err != nil { return nil, err } From 20c68643897316de3d14cd26ee7950697347d6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Tue, 18 Jun 2024 13:15:05 +0200 Subject: [PATCH 2/3] Specify resource type in folder search API call --- folders.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folders.go b/folders.go index 45171e86..eaeaa5db 100644 --- a/folders.go +++ b/folders.go @@ -70,7 +70,7 @@ func (client *Client) CreateFolder(ctx context.Context, name string) (*Folder, e // GetFolderByTitle finds a folder, given its title. func (client *Client) GetFolderByTitle(ctx context.Context, title string) (*Folder, error) { - resp, err := client.get(ctx, fmt.Sprintf("/api/search?query=%s", url.QueryEscape(title))) + resp, err := client.get(ctx, fmt.Sprintf("/api/search?type=dash-folder&query=%s", url.QueryEscape(title))) if err != nil { return nil, err } From e135fa35fcf1104eb7f698eef1d3e56f889d98fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Tue, 18 Jun 2024 13:22:48 +0200 Subject: [PATCH 3/3] Parse parentUid for folders --- folders.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/folders.go b/folders.go index 2c960800..32d8a119 100644 --- a/folders.go +++ b/folders.go @@ -15,9 +15,10 @@ var ErrFolderNotFound = errors.New("folder not found") // Folder represents a dashboard folder. // See https://grafana.com/docs/grafana/latest/reference/dashboard_folders/ type Folder struct { - ID uint `json:"id"` - UID string `json:"uid"` - Title string `json:"title"` + ID uint `json:"id"` + UID string `json:"uid"` + ParentUID string `json:"parentUid"` + Title string `json:"title"` } // FindOrCreateFolder returns the folder by its name or creates it if it doesn't exist.