mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 20:22:11 +08:00
Provisioning: validate files we read (#103197)
This commit is contained in:
@ -5,12 +5,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
|
"github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
|
||||||
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
|
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
|
||||||
"github.com/grafana/grafana/pkg/registry/apis/provisioning/repository"
|
"github.com/grafana/grafana/pkg/registry/apis/provisioning/repository"
|
||||||
"github.com/grafana/grafana/pkg/registry/apis/provisioning/safepath"
|
"github.com/grafana/grafana/pkg/registry/apis/provisioning/safepath"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DualReadWriter is a wrapper around a repository that can read and write resources
|
// DualReadWriter is a wrapper around a repository that can read and write resources
|
||||||
@ -36,7 +37,7 @@ func (r *DualReadWriter) Read(ctx context.Context, path string, ref string) (*Pa
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed, err := r.parser.Parse(ctx, info, false)
|
parsed, err := r.parser.Parse(ctx, info, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -260,10 +260,19 @@ func TestIntegrationProvisioning_ImportAllPanelsFromLocalRepository(t *testing.T
|
|||||||
_, err := helper.Repositories.Resource.Create(ctx, localTmp, metav1.CreateOptions{})
|
_, err := helper.Repositories.Resource.Create(ctx, localTmp, metav1.CreateOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Make sure the repo can see the file
|
// Make sure the repo can read and validate the file
|
||||||
_, err = helper.Repositories.Resource.Get(ctx, repo, metav1.GetOptions{}, "files", "all-panels.json")
|
obj, err := helper.Repositories.Resource.Get(ctx, repo, metav1.GetOptions{}, "files", "all-panels.json")
|
||||||
require.NoError(t, err, "valid path should be fine")
|
require.NoError(t, err, "valid path should be fine")
|
||||||
|
|
||||||
|
resource, _, err := unstructured.NestedMap(obj.Object, "resource")
|
||||||
|
require.NoError(t, err, "missing resource")
|
||||||
|
action, _, err := unstructured.NestedString(resource, "action")
|
||||||
|
require.NoError(t, err, "invalid action")
|
||||||
|
|
||||||
|
require.NotNil(t, resource["file"], "the raw file")
|
||||||
|
require.NotNil(t, resource["dryRun"], "dryRun result")
|
||||||
|
require.Equal(t, "create", action)
|
||||||
|
|
||||||
// But the dashboard shouldn't exist yet
|
// But the dashboard shouldn't exist yet
|
||||||
const allPanels = "n1jR8vnnz"
|
const allPanels = "n1jR8vnnz"
|
||||||
_, err = helper.Dashboards.Resource.Get(ctx, allPanels, metav1.GetOptions{})
|
_, err = helper.Dashboards.Resource.Get(ctx, allPanels, metav1.GetOptions{})
|
||||||
|
Reference in New Issue
Block a user