Dashboards: Add Dashboard Schema validation (2) (#103844)
* Activate schema validation and align underlying systems * update to save as v0 if not the right schema version * Resolve merge conflicts * Move RequireApiErrorStatus to tests package * Add mutation tests * Fix lint * Only do min version check if dashboard is v1 * Fix lint and disable provisioning test * Revert provisioning changes * Revert more tests and add schema test * Reran gen * SQL Dashboard save * Adjust APIVERSION * Fixed mutation test * Add logging on downgrade --------- Co-authored-by: Marco de Abreu <18629099+marcoabreu@users.noreply.github.com> Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
co-authored by
Marco de Abreu
Stephanie Hingtgen
parent
07a225649d
commit
c47ab101d1
@@ -38,17 +38,21 @@ func (r *DualReadWriter) Read(ctx context.Context, path string, ref string) (*Pa
|
||||
|
||||
info, err := r.repo.Read(ctx, path, ref)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read file: %w", err)
|
||||
_, ok := utils.ExtractApiErrorStatus(err)
|
||||
if ok {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("Read file failed: %w", err)
|
||||
}
|
||||
|
||||
parsed, err := r.parser.Parse(ctx, info)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse file: %w", err)
|
||||
return nil, apierrors.NewBadRequest(fmt.Sprintf("Parse file failed: %v", err))
|
||||
}
|
||||
|
||||
// Fail as we use the dry run for this response and it's not about updating the resource
|
||||
if err := parsed.DryRun(ctx); err != nil {
|
||||
return nil, fmt.Errorf("run dry run: %w", err)
|
||||
return nil, apierrors.NewBadRequest(fmt.Sprintf("Dry run failed: %v", err))
|
||||
}
|
||||
|
||||
// Authorize based on the existing resource
|
||||
|
||||
@@ -19,8 +19,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnableToReadResourceBytes = errors.New("unable to read bytes as a resource")
|
||||
ErrClassicResourceIsAlreadyK8sForm = errors.New("classic resource is already structured with apiVersion and kind")
|
||||
ErrUnableToReadResourceBytes = errors.New("unable to read bytes as a resource")
|
||||
ErrUnableToReadPanelsMissing = errors.New("panels property is required")
|
||||
ErrUnableToReadSchemaVersionMissing = errors.New("schemaVersion property is required")
|
||||
ErrUnableToReadTagsMissing = errors.New("tags property is required")
|
||||
ErrClassicResourceIsAlreadyK8sForm = errors.New("classic resource is already structured with apiVersion and kind")
|
||||
)
|
||||
|
||||
// This reads a "classic" file format and will convert it to an unstructured k8s resource
|
||||
|
||||
Reference in New Issue
Block a user