2024-08-13 12:50:15 +00:00
|
|
|
package validate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-08-20 00:22:00 +00:00
|
|
|
"slices"
|
2024-08-13 12:50:15 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/libs/diag"
|
|
|
|
"github.com/databricks/cli/libs/dyn"
|
|
|
|
)
|
|
|
|
|
|
|
|
func AllResourcesHaveValues() bundle.Mutator {
|
|
|
|
return &allResourcesHaveValues{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type allResourcesHaveValues struct{}
|
|
|
|
|
|
|
|
func (m *allResourcesHaveValues) Name() string {
|
|
|
|
return "validate:AllResourcesHaveValues"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *allResourcesHaveValues) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2024-08-20 00:22:00 +00:00
|
|
|
diags := diag.Diagnostics{}
|
2024-08-13 12:50:15 +00:00
|
|
|
|
|
|
|
_, err := dyn.MapByPattern(
|
2024-08-20 00:22:00 +00:00
|
|
|
b.Config.Value(),
|
|
|
|
dyn.NewPattern(dyn.Key("resources"), dyn.AnyKey(), dyn.AnyKey()),
|
2024-08-13 12:50:15 +00:00
|
|
|
func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
2024-08-20 00:22:00 +00:00
|
|
|
if v.Kind() != dyn.KindNil {
|
|
|
|
return v, nil
|
2024-08-13 12:50:15 +00:00
|
|
|
}
|
2024-08-20 00:22:00 +00:00
|
|
|
|
|
|
|
// Type of the resource, stripped of the trailing 's' to make it
|
|
|
|
// singular.
|
|
|
|
rType := strings.TrimSuffix(p[1].Key(), "s")
|
|
|
|
|
|
|
|
// Name of the resource. Eg: "foo" in "jobs.foo".
|
|
|
|
rName := p[2].Key()
|
|
|
|
|
|
|
|
diags = append(diags, diag.Diagnostic{
|
|
|
|
Severity: diag.Error,
|
|
|
|
Summary: fmt.Sprintf("%s %s is not defined", rType, rName),
|
|
|
|
Locations: v.Locations(),
|
|
|
|
Paths: []dyn.Path{slices.Clone(p)},
|
|
|
|
})
|
|
|
|
|
2024-08-13 12:50:15 +00:00
|
|
|
return v, nil
|
|
|
|
},
|
|
|
|
)
|
2024-08-20 00:22:00 +00:00
|
|
|
if err != nil {
|
|
|
|
diags = append(diags, diag.FromErr(err)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return diags
|
2024-08-13 12:50:15 +00:00
|
|
|
}
|