databricks-cli/bundle/config/resources/dashboard.go

75 lines
2.4 KiB
Go
Raw Normal View History

2024-09-03 08:35:41 +00:00
package resources
import (
"context"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/dashboards"
)
type Dashboard struct {
ID string `json:"id,omitempty" bundle:"readonly"`
Permissions []Permission `json:"permissions,omitempty"`
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
// ===========================
// === BEGIN OF API FIELDS ===
// ===========================
2024-09-27 14:39:51 +00:00
// DisplayName is the display name of the dashboard (both as title and as basename in the workspace).
DisplayName string `json:"display_name"`
2024-09-03 08:35:41 +00:00
2024-09-27 14:39:51 +00:00
// WarehouseID is the ID of the SQL Warehouse used to run the dashboard's queries.
WarehouseID string `json:"warehouse_id"`
2024-10-01 17:47:20 +00:00
// SerializedDashboard holds the contents of the dashboard in serialized JSON form.
2024-09-27 14:39:51 +00:00
// Note: its type is any and not string such that it can be inlined as YAML.
// If it is not a string, its contents will be marshalled as JSON.
SerializedDashboard any `json:"serialized_dashboard,omitempty"`
// ParentPath is the workspace path of the folder containing the dashboard.
// Includes leading slash and no trailing slash.
//
// Defaults to ${workspace.resource_path} if not set.
2024-09-03 08:35:41 +00:00
ParentPath string `json:"parent_path,omitempty"`
2024-09-27 14:39:51 +00:00
// EmbedCredentials is a flag to indicate if the publisher's credentials should
// be embedded in the published dashboard. These embedded credentials will be used
// to execute the published dashboard's queries.
//
// Defaults to false if not set.
EmbedCredentials bool `json:"embed_credentials,omitempty"`
2024-09-03 08:35:41 +00:00
// ===========================
// ==== END OF API FIELDS ====
// ===========================
2024-09-27 14:39:51 +00:00
// FilePath points to the local `.lvdash.json` file containing the dashboard definition.
FilePath string `json:"file_path,omitempty"`
2024-09-03 08:35:41 +00:00
}
func (s *Dashboard) UnmarshalJSON(b []byte) error {
return marshal.Unmarshal(b, s)
}
func (s Dashboard) MarshalJSON() ([]byte, error) {
return marshal.Marshal(s)
}
2024-09-27 14:39:51 +00:00
func (*Dashboard) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
2024-09-03 08:35:41 +00:00
_, err := w.Lakeview.Get(ctx, dashboards.GetDashboardRequest{
DashboardId: id,
})
if err != nil {
log.Debugf(ctx, "Dashboard %s does not exist", id)
return false, err
}
return true, nil
}
2024-09-27 14:39:51 +00:00
func (*Dashboard) TerraformResourceName() string {
2024-09-03 08:35:41 +00:00
return "databricks_dashboard"
}