mirror of https://github.com/databricks/cli.git
Return `application_id` for service principal lookups (#1245)
## Changes Return ApplicationId for service principals lookups Fixes #1234 ## Tests Added (regression) tests
This commit is contained in:
parent
29ab96f327
commit
09d1846e13
|
@ -18,6 +18,11 @@ package variable
|
||||||
"warehouses"
|
"warehouses"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
{{ $customField :=
|
||||||
|
dict
|
||||||
|
"service-principals" "ApplicationId"
|
||||||
|
}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -116,15 +121,10 @@ func allResolvers() *resolvers {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprint(entity{{ template "field-path" .List.NamedIdMap.IdPath }}), nil
|
return fmt.Sprint(entity.{{ getOrDefault $customField .KebabName ((index .List.NamedIdMap.IdPath 0).PascalName) }}), nil
|
||||||
}
|
}
|
||||||
{{end -}}
|
{{end -}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{{- define "field-path" -}}
|
|
||||||
{{- range .}}.{{.PascalName}}{{end}}
|
|
||||||
{{- end -}}
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
"github.com/databricks/databricks-sdk-go/experimental/mocks"
|
"github.com/databricks/databricks-sdk-go/experimental/mocks"
|
||||||
"github.com/databricks/databricks-sdk-go/service/compute"
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
||||||
|
"github.com/databricks/databricks-sdk-go/service/iam"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolveClusterReference(t *testing.T) {
|
func TestResolveClusterReference(t *testing.T) {
|
||||||
|
@ -105,3 +106,30 @@ func TestNoLookupIfVariableIsSet(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "random value", *b.Config.Variables["my-cluster-id"].Value)
|
require.Equal(t, "random value", *b.Config.Variables["my-cluster-id"].Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResolveServicePrincipal(t *testing.T) {
|
||||||
|
spName := "Some SP name"
|
||||||
|
b := &bundle.Bundle{
|
||||||
|
Config: config.Root{
|
||||||
|
Variables: map[string]*variable.Variable{
|
||||||
|
"my-sp": {
|
||||||
|
Lookup: &variable.Lookup{
|
||||||
|
ServicePrincipal: spName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||||
|
spApi := m.GetMockServicePrincipalsAPI()
|
||||||
|
spApi.EXPECT().GetByDisplayName(mock.Anything, spName).Return(&iam.ServicePrincipal{
|
||||||
|
Id: "1234",
|
||||||
|
ApplicationId: "app-1234",
|
||||||
|
}, nil)
|
||||||
|
|
||||||
|
err := bundle.Apply(context.Background(), b, ResolveResourceReferences())
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "app-1234", *b.Config.Variables["my-sp"].Value)
|
||||||
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ func allResolvers() *resolvers {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.ApplicationId), nil
|
||||||
}
|
}
|
||||||
r.Warehouse = func(ctx context.Context, w *databricks.WorkspaceClient, name string) (string, error) {
|
r.Warehouse = func(ctx context.Context, w *databricks.WorkspaceClient, name string) (string, error) {
|
||||||
entity, err := w.Warehouses.GetByName(ctx, name)
|
entity, err := w.Warehouses.GetByName(ctx, name)
|
||||||
|
|
Loading…
Reference in New Issue