From d15bc926d72fd19514327061dd928149e5ebc001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Thu, 19 Sep 2024 15:03:49 +0200 Subject: [PATCH] Fix a panic when diffing on LibraryElement resources (#498) --- pkg/grafana/library-element-handler.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/grafana/library-element-handler.go b/pkg/grafana/library-element-handler.go index 16d9c70b..d43c1c79 100644 --- a/pkg/grafana/library-element-handler.go +++ b/pkg/grafana/library-element-handler.go @@ -35,15 +35,22 @@ const ( // ResourceFilePath returns the location on disk where a resource should be updated func (h *LibraryElementHandler) ResourceFilePath(resource grizzly.Resource, filetype string) string { + var kindCode int kind := "element" - t := resource.GetSpecValue("kind").(float64) - switch t { + if t, ok := resource.GetSpecValue("kind").(int); ok { + kindCode = t + } else if t, ok := resource.GetSpecValue("kind").(float64); ok { + kindCode = int(t) + } + + switch kindCode { case 1: kind = "panel" case 2: kind = "variable" } + return fmt.Sprintf(libraryElementPattern, kind, resource.Name(), filetype) }