databricks-cli/bundle/config/mutator/translate_paths_dashboards.go

29 lines
781 B
Go
Raw Normal View History

2024-09-03 08:35:41 +00:00
package mutator
import (
"fmt"
"github.com/databricks/cli/libs/dyn"
)
2024-10-01 17:47:08 +00:00
func (t *translateContext) applyDashboardTranslations(v dyn.Value) (dyn.Value, error) {
// Convert the `file_path` field to a local absolute path.
2024-10-18 14:21:52 +00:00
// We load the file at this path and use its contents for the dashboard contents.
2024-10-01 17:47:08 +00:00
pattern := dyn.NewPattern(
2024-09-03 08:35:41 +00:00
dyn.Key("resources"),
dyn.Key("dashboards"),
dyn.AnyKey(),
2024-10-01 17:47:08 +00:00
dyn.Key("file_path"),
2024-09-03 08:35:41 +00:00
)
2024-10-01 17:47:08 +00:00
return dyn.MapByPattern(v, pattern, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
key := p[2].Key()
dir, err := v.Location().Directory()
2024-09-03 08:35:41 +00:00
if err != nil {
2024-10-01 17:47:08 +00:00
return dyn.InvalidValue, fmt.Errorf("unable to determine directory for dashboard %s: %w", key, err)
2024-09-03 08:35:41 +00:00
}
2024-10-01 17:47:08 +00:00
return t.rewriteRelativeTo(p, v, t.retainLocalAbsoluteFilePath, dir, "")
})
2024-09-03 08:35:41 +00:00
}