mirror of https://github.com/databricks/cli.git
Cleanup after "Add a foundation for built-in templates" (#707)
## Changes Add some cleanup based on @pietern's comments on https://github.com/databricks/cli/pull/685
This commit is contained in:
parent
aa9e1fc41c
commit
707fd6f617
|
@ -160,7 +160,10 @@ func (m *processTargetMode) Apply(ctx context.Context, b *bundle.Bundle) error {
|
|||
}
|
||||
return transformDevelopmentMode(b)
|
||||
case config.Production:
|
||||
isPrincipal := auth.IsServicePrincipal(ctx, b.WorkspaceClient(), b.Config.Workspace.CurrentUser.Id)
|
||||
isPrincipal, err := auth.IsServicePrincipal(ctx, b.WorkspaceClient(), b.Config.Workspace.CurrentUser.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return validateProductionMode(ctx, b, isPrincipal)
|
||||
case "":
|
||||
// No action
|
||||
|
|
|
@ -43,7 +43,7 @@ func getTarget(cmd *cobra.Command) (value string) {
|
|||
return target
|
||||
}
|
||||
|
||||
func GetProfile(cmd *cobra.Command) (value string) {
|
||||
func getProfile(cmd *cobra.Command) (value string) {
|
||||
// The command line flag takes precedence.
|
||||
flag := cmd.Flag("profile")
|
||||
if flag != nil {
|
||||
|
@ -70,7 +70,7 @@ func loadBundle(cmd *cobra.Command, args []string, load func(ctx context.Context
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
profile := GetProfile(cmd)
|
||||
profile := getProfile(cmd)
|
||||
if profile != "" {
|
||||
b.Config.Workspace.Profile = profile
|
||||
}
|
||||
|
|
|
@ -4,13 +4,17 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/databricks/databricks-sdk-go"
|
||||
"github.com/databricks/databricks-sdk-go/apierr"
|
||||
)
|
||||
|
||||
// Determines whether a given user id is a service principal.
|
||||
// This function uses a heuristic: if no user exists with this id, we assume
|
||||
// it's a service principal. Unfortunately, the standard service principal API is too
|
||||
// slow for our purposes.
|
||||
func IsServicePrincipal(ctx context.Context, ws *databricks.WorkspaceClient, userId string) bool {
|
||||
func IsServicePrincipal(ctx context.Context, ws *databricks.WorkspaceClient, userId string) (bool, error) {
|
||||
_, err := ws.Users.GetById(ctx, userId)
|
||||
return err != nil
|
||||
if apierr.IsMissing(err) {
|
||||
return true, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -104,7 +104,10 @@ func loadHelpers(ctx context.Context) template.FuncMap {
|
|||
return false, err
|
||||
}
|
||||
}
|
||||
result := auth.IsServicePrincipal(ctx, w, user.Id)
|
||||
result, err := auth.IsServicePrincipal(ctx, w, user.Id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
is_service_principal = &result
|
||||
return result, nil
|
||||
},
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/databricks/cli/libs/cmdio"
|
||||
)
|
||||
|
||||
const libraryDirName = "library"
|
||||
|
@ -80,7 +82,7 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir st
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
println("✨ Successfully initialized template")
|
||||
cmdio.LogString(ctx, "✨ Successfully initialized template")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue