mirror of https://github.com/databricks/cli.git
No need for pointers to the lookup structs
This commit is contained in:
parent
16cd2de149
commit
7a99df58ec
|
@ -4,6 +4,8 @@ package variable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
@ -40,41 +42,41 @@ type Lookup struct {
|
||||||
|
|
||||||
func (l *Lookup) constructResolver() (resolver, error) {
|
func (l *Lookup) constructResolver() (resolver, error) {
|
||||||
|
|
||||||
if l.Alert != "" {
|
if l.Alert != "" {
|
||||||
return lookupAlert{name: l.Alert}, nil
|
return lookupAlert{name: l.Alert}, nil
|
||||||
}
|
}
|
||||||
if l.ClusterPolicy != "" {
|
if l.ClusterPolicy != "" {
|
||||||
return lookupClusterPolicy{name: l.ClusterPolicy}, nil
|
return lookupClusterPolicy{name: l.ClusterPolicy}, nil
|
||||||
}
|
}
|
||||||
if l.Cluster != "" {
|
if l.Cluster != "" {
|
||||||
return lookupCluster{name: l.Cluster}, nil
|
return lookupCluster{name: l.Cluster}, nil
|
||||||
}
|
}
|
||||||
if l.Dashboard != "" {
|
if l.Dashboard != "" {
|
||||||
return lookupDashboard{name: l.Dashboard}, nil
|
return lookupDashboard{name: l.Dashboard}, nil
|
||||||
}
|
}
|
||||||
if l.InstancePool != "" {
|
if l.InstancePool != "" {
|
||||||
return lookupInstancePool{name: l.InstancePool}, nil
|
return lookupInstancePool{name: l.InstancePool}, nil
|
||||||
}
|
}
|
||||||
if l.Job != "" {
|
if l.Job != "" {
|
||||||
return lookupJob{name: l.Job}, nil
|
return lookupJob{name: l.Job}, nil
|
||||||
}
|
}
|
||||||
if l.Metastore != "" {
|
if l.Metastore != "" {
|
||||||
return lookupMetastore{name: l.Metastore}, nil
|
return lookupMetastore{name: l.Metastore}, nil
|
||||||
}
|
}
|
||||||
if l.Pipeline != "" {
|
if l.Pipeline != "" {
|
||||||
return lookupPipeline{name: l.Pipeline}, nil
|
return lookupPipeline{name: l.Pipeline}, nil
|
||||||
}
|
}
|
||||||
if l.Query != "" {
|
if l.Query != "" {
|
||||||
return lookupQuery{name: l.Query}, nil
|
return lookupQuery{name: l.Query}, nil
|
||||||
}
|
}
|
||||||
if l.ServicePrincipal != "" {
|
if l.ServicePrincipal != "" {
|
||||||
return lookupServicePrincipal{name: l.ServicePrincipal}, nil
|
return lookupServicePrincipal{name: l.ServicePrincipal}, nil
|
||||||
}
|
}
|
||||||
if l.Warehouse != "" {
|
if l.Warehouse != "" {
|
||||||
return lookupWarehouse{name: l.Warehouse}, nil
|
return lookupWarehouse{name: l.Warehouse}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("no valid lookup fields provided")
|
return nil, fmt.Errorf("no valid lookup fields provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
// func LookupFromMap(m map[string]any) *Lookup {
|
// func LookupFromMap(m map[string]any) *Lookup {
|
||||||
|
@ -160,10 +162,10 @@ return nil, fmt.Errorf("no valid lookup fields provided")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (l *Lookup) String() string {
|
func (l *Lookup) String() string {
|
||||||
r, _ := l.constructResolver()
|
r, _ := l.constructResolver()
|
||||||
if r != nil {
|
if r != nil {
|
||||||
return r.String()
|
return r.String()
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupAlert struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Alerts.GetByDisplayName(ctx, l.name)
|
entity, err := w.Alerts.GetByDisplayName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupAlert) String() string {
|
func (l lookupAlert) String() string {
|
||||||
return fmt.Sprintf("alert: %s", l.name)
|
return fmt.Sprintf("alert: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupAlert_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupAlert{name: "alert"}
|
l := lookupAlert{name: "alert"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupAlert_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupAlert{name: "alert"}
|
l := lookupAlert{name: "alert"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupAlert_String(t *testing.T) {
|
func TestLookupAlert_String(t *testing.T) {
|
||||||
l := &lookupAlert{name: "name"}
|
l := lookupAlert{name: "name"}
|
||||||
assert.Equal(t, "alert: name", l.String())
|
assert.Equal(t, "alert: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ type lookupCluster struct {
|
||||||
|
|
||||||
// We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters.
|
// We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters.
|
||||||
// Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts.
|
// Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts.
|
||||||
func (l *lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
result, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{
|
result, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{
|
||||||
FilterBy: &compute.ListClustersFilterBy{
|
FilterBy: &compute.ListClustersFilterBy{
|
||||||
ClusterSources: []compute.ClusterSource{compute.ClusterSourceApi, compute.ClusterSourceUi},
|
ClusterSources: []compute.ClusterSource{compute.ClusterSourceApi, compute.ClusterSourceUi},
|
||||||
|
@ -42,6 +42,6 @@ func (l *lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClie
|
||||||
return alternatives[0].ClusterId, nil
|
return alternatives[0].ClusterId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupCluster) String() string {
|
func (l lookupCluster) String() string {
|
||||||
return fmt.Sprintf("cluster: %s", l.name)
|
return fmt.Sprintf("cluster: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupClusterPolicy struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.ClusterPolicies.GetByName(ctx, l.name)
|
entity, err := w.ClusterPolicies.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.Workspa
|
||||||
return fmt.Sprint(entity.PolicyId), nil
|
return fmt.Sprint(entity.PolicyId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupClusterPolicy) String() string {
|
func (l lookupClusterPolicy) String() string {
|
||||||
return fmt.Sprintf("cluster-policy: %s", l.name)
|
return fmt.Sprintf("cluster-policy: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupClusterPolicy_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupClusterPolicy{name: "policy"}
|
l := lookupClusterPolicy{name: "policy"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupClusterPolicy_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupClusterPolicy{name: "policy"}
|
l := lookupClusterPolicy{name: "policy"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupClusterPolicy_String(t *testing.T) {
|
func TestLookupClusterPolicy_String(t *testing.T) {
|
||||||
l := &lookupClusterPolicy{name: "name"}
|
l := lookupClusterPolicy{name: "name"}
|
||||||
assert.Equal(t, "cluster-policy: name", l.String())
|
assert.Equal(t, "cluster-policy: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupCluster_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupCluster{name: "cluster2"}
|
l := lookupCluster{name: "cluster2"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "2345", result)
|
assert.Equal(t, "2345", result)
|
||||||
|
@ -38,13 +38,13 @@ func TestLookupCluster_ResolveNotFound(t *testing.T) {
|
||||||
Return([]compute.ClusterDetails{}, nil)
|
Return([]compute.ClusterDetails{}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupCluster{name: "cluster"}
|
l := lookupCluster{name: "cluster"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "cluster named 'cluster' does not exist")
|
assert.Contains(t, err.Error(), "cluster named 'cluster' does not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupCluster_String(t *testing.T) {
|
func TestLookupCluster_String(t *testing.T) {
|
||||||
l := &lookupCluster{name: "name"}
|
l := lookupCluster{name: "name"}
|
||||||
assert.Equal(t, "cluster: name", l.String())
|
assert.Equal(t, "cluster: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupDashboard struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Dashboards.GetByName(ctx, l.name)
|
entity, err := w.Dashboards.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceCl
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupDashboard) String() string {
|
func (l lookupDashboard) String() string {
|
||||||
return fmt.Sprintf("dashboard: %s", l.name)
|
return fmt.Sprintf("dashboard: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupDashboard_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupDashboard{name: "dashboard"}
|
l := lookupDashboard{name: "dashboard"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupDashboard_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupDashboard{name: "dashboard"}
|
l := lookupDashboard{name: "dashboard"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupDashboard_String(t *testing.T) {
|
func TestLookupDashboard_String(t *testing.T) {
|
||||||
l := &lookupDashboard{name: "name"}
|
l := lookupDashboard{name: "name"}
|
||||||
assert.Equal(t, "dashboard: name", l.String())
|
assert.Equal(t, "dashboard: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupInstancePool struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupInstancePool) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupInstancePool) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.InstancePools.GetByInstancePoolName(ctx, l.name)
|
entity, err := w.InstancePools.GetByInstancePoolName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupInstancePool) Resolve(ctx context.Context, w *databricks.Workspac
|
||||||
return fmt.Sprint(entity.InstancePoolId), nil
|
return fmt.Sprint(entity.InstancePoolId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupInstancePool) String() string {
|
func (l lookupInstancePool) String() string {
|
||||||
return fmt.Sprintf("instance-pool: %s", l.name)
|
return fmt.Sprintf("instance-pool: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupInstancePool_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupInstancePool{name: "instance_pool"}
|
l := lookupInstancePool{name: "instance_pool"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "5678", result)
|
assert.Equal(t, "5678", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupInstancePool_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupInstancePool{name: "instance_pool"}
|
l := lookupInstancePool{name: "instance_pool"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupInstancePool_String(t *testing.T) {
|
func TestLookupInstancePool_String(t *testing.T) {
|
||||||
l := &lookupInstancePool{name: "name"}
|
l := lookupInstancePool{name: "name"}
|
||||||
assert.Equal(t, "instance-pool: name", l.String())
|
assert.Equal(t, "instance-pool: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupJob struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Jobs.GetBySettingsName(ctx, l.name)
|
entity, err := w.Jobs.GetBySettingsName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient)
|
||||||
return fmt.Sprint(entity.JobId), nil
|
return fmt.Sprint(entity.JobId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupJob) String() string {
|
func (l lookupJob) String() string {
|
||||||
return fmt.Sprintf("job: %s", l.name)
|
return fmt.Sprintf("job: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupJob_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupJob{name: "job"}
|
l := lookupJob{name: "job"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "5678", result)
|
assert.Equal(t, "5678", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupJob_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupJob{name: "job"}
|
l := lookupJob{name: "job"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupJob_String(t *testing.T) {
|
func TestLookupJob_String(t *testing.T) {
|
||||||
l := &lookupJob{name: "name"}
|
l := lookupJob{name: "name"}
|
||||||
assert.Equal(t, "job: name", l.String())
|
assert.Equal(t, "job: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupMetastore struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Metastores.GetByName(ctx, l.name)
|
entity, err := w.Metastores.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceCl
|
||||||
return fmt.Sprint(entity.MetastoreId), nil
|
return fmt.Sprint(entity.MetastoreId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupMetastore) String() string {
|
func (l lookupMetastore) String() string {
|
||||||
return fmt.Sprintf("metastore: %s", l.name)
|
return fmt.Sprintf("metastore: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupMetastore_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupMetastore{name: "metastore"}
|
l := lookupMetastore{name: "metastore"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "abcd", result)
|
assert.Equal(t, "abcd", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupMetastore_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupMetastore{name: "metastore"}
|
l := lookupMetastore{name: "metastore"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupMetastore_String(t *testing.T) {
|
func TestLookupMetastore_String(t *testing.T) {
|
||||||
l := &lookupMetastore{name: "name"}
|
l := lookupMetastore{name: "name"}
|
||||||
assert.Equal(t, "metastore: name", l.String())
|
assert.Equal(t, "metastore: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupPipeline struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Pipelines.GetByName(ctx, l.name)
|
entity, err := w.Pipelines.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceCli
|
||||||
return fmt.Sprint(entity.PipelineId), nil
|
return fmt.Sprint(entity.PipelineId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupPipeline) String() string {
|
func (l lookupPipeline) String() string {
|
||||||
return fmt.Sprintf("pipeline: %s", l.name)
|
return fmt.Sprintf("pipeline: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupPipeline_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupPipeline{name: "pipeline"}
|
l := lookupPipeline{name: "pipeline"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "abcd", result)
|
assert.Equal(t, "abcd", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupPipeline_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupPipeline{name: "pipeline"}
|
l := lookupPipeline{name: "pipeline"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupPipeline_String(t *testing.T) {
|
func TestLookupPipeline_String(t *testing.T) {
|
||||||
l := &lookupPipeline{name: "name"}
|
l := lookupPipeline{name: "name"}
|
||||||
assert.Equal(t, "pipeline: name", l.String())
|
assert.Equal(t, "pipeline: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupQuery struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Queries.GetByDisplayName(ctx, l.name)
|
entity, err := w.Queries.GetByDisplayName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupQuery) String() string {
|
func (l lookupQuery) String() string {
|
||||||
return fmt.Sprintf("query: %s", l.name)
|
return fmt.Sprintf("query: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupQuery_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupQuery{name: "query"}
|
l := lookupQuery{name: "query"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupQuery_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupQuery{name: "query"}
|
l := lookupQuery{name: "query"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupQuery_String(t *testing.T) {
|
func TestLookupQuery_String(t *testing.T) {
|
||||||
l := &lookupQuery{name: "name"}
|
l := lookupQuery{name: "name"}
|
||||||
assert.Equal(t, "query: name", l.String())
|
assert.Equal(t, "query: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupServicePrincipal struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.ServicePrincipals.GetByDisplayName(ctx, l.name)
|
entity, err := w.ServicePrincipals.GetByDisplayName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.Work
|
||||||
return fmt.Sprint(entity.ApplicationId), nil
|
return fmt.Sprint(entity.ApplicationId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupServicePrincipal) String() string {
|
func (l lookupServicePrincipal) String() string {
|
||||||
return fmt.Sprintf("service-principal: %s", l.name)
|
return fmt.Sprintf("service-principal: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupServicePrincipal_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupServicePrincipal{name: "service-principal"}
|
l := lookupServicePrincipal{name: "service-principal"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "5678", result)
|
assert.Equal(t, "5678", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupServicePrincipal_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupServicePrincipal{name: "service-principal"}
|
l := lookupServicePrincipal{name: "service-principal"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupServicePrincipal_String(t *testing.T) {
|
func TestLookupServicePrincipal_String(t *testing.T) {
|
||||||
l := &lookupServicePrincipal{name: "name"}
|
l := lookupServicePrincipal{name: "name"}
|
||||||
assert.Equal(t, "service-principal: name", l.String())
|
assert.Equal(t, "service-principal: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ type lookupWarehouse struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Warehouses.GetByName(ctx, l.name)
|
entity, err := w.Warehouses.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l *lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceCl
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lookupWarehouse) String() string {
|
func (l lookupWarehouse) String() string {
|
||||||
return fmt.Sprintf("warehouse: %s", l.name)
|
return fmt.Sprintf("warehouse: %s", l.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestLookupWarehouse_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupWarehouse{name: "warehouse"}
|
l := lookupWarehouse{name: "warehouse"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "abcd", result)
|
assert.Equal(t, "abcd", result)
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupWarehouse_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := &lookupWarehouse{name: "warehouse"}
|
l := lookupWarehouse{name: "warehouse"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupWarehouse_String(t *testing.T) {
|
func TestLookupWarehouse_String(t *testing.T) {
|
||||||
l := &lookupWarehouse{name: "name"}
|
l := lookupWarehouse{name: "name"}
|
||||||
assert.Equal(t, "warehouse: name", l.String())
|
assert.Equal(t, "warehouse: name", l.String())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue