databricks-cli/bundle/config/variable/lookup.go

107 lines
2.4 KiB
Go
Raw Normal View History

// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package variable
import (
"context"
"fmt"
"strings"
"github.com/databricks/databricks-sdk-go"
)
2024-11-20 21:40:43 +00:00
type resolver interface {
2024-11-20 21:40:33 +00:00
Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error)
String() string
}
type Lookup struct {
Alert string `json:"alert,omitempty"`
ClusterPolicy string `json:"cluster_policy,omitempty"`
Cluster string `json:"cluster,omitempty"`
Dashboard string `json:"dashboard,omitempty"`
InstancePool string `json:"instance_pool,omitempty"`
Job string `json:"job,omitempty"`
Metastore string `json:"metastore,omitempty"`
Pipeline string `json:"pipeline,omitempty"`
Query string `json:"query,omitempty"`
ServicePrincipal string `json:"service_principal,omitempty"`
Warehouse string `json:"warehouse,omitempty"`
}
2024-11-20 21:40:43 +00:00
func (l *Lookup) constructResolver() (resolver, error) {
2024-11-20 21:53:24 +00:00
var resolvers []resolver
if l.Alert != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupAlert{name: l.Alert})
}
if l.ClusterPolicy != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupClusterPolicy{name: l.ClusterPolicy})
}
if l.Cluster != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupCluster{name: l.Cluster})
}
if l.Dashboard != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupDashboard{name: l.Dashboard})
}
if l.InstancePool != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupInstancePool{name: l.InstancePool})
}
if l.Job != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupJob{name: l.Job})
}
if l.Metastore != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupMetastore{name: l.Metastore})
}
if l.Pipeline != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupPipeline{name: l.Pipeline})
}
if l.Query != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupQuery{name: l.Query})
}
if l.ServicePrincipal != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupServicePrincipal{name: l.ServicePrincipal})
}
if l.Warehouse != "" {
2024-11-20 21:53:24 +00:00
resolvers = append(resolvers, lookupWarehouse{name: l.Warehouse})
}
2024-11-20 21:53:24 +00:00
switch len(resolvers) {
case 0:
return nil, fmt.Errorf("no valid lookup fields provided")
case 1:
return resolvers[0], nil
default:
return nil, fmt.Errorf("exactly one lookup field must be provided")
}
}
2024-11-20 21:53:24 +00:00
func (l *Lookup) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
r, err := l.constructResolver()
if err != nil {
return "", err
}
2024-11-20 21:53:24 +00:00
return r.Resolve(ctx, w)
}
2024-11-20 21:53:24 +00:00
func (l *Lookup) String() string {
r, _ := l.constructResolver()
if r == nil {
return ""
}
2024-11-20 21:53:24 +00:00
return r.String()
}