Skip to content

Commit

Permalink
Require authentication when a user runs bundle init
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-goenka committed Dec 20, 2024
1 parent 07fff20 commit 47a9ca1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
21 changes: 0 additions & 21 deletions libs/template/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,13 @@ func loadHelpers(ctx context.Context) template.FuncMap {
return w.Config.Host, nil
},
"user_name": func() (string, error) {
if cachedUser == nil {
var err error
cachedUser, err = w.CurrentUser.Me(ctx)
if err != nil {
return "", err
}
}
result := cachedUser.UserName
if result == "" {
result = cachedUser.Id
}
return result, nil
},
"short_name": func() (string, error) {
if cachedUser == nil {
var err error
cachedUser, err = w.CurrentUser.Me(ctx)
if err != nil {
return "", err
}
}
return iamutil.GetShortUserName(cachedUser), nil
},
// Get the default workspace catalog. If there is no default, or if
Expand All @@ -156,13 +142,6 @@ func loadHelpers(ctx context.Context) template.FuncMap {
if cachedIsServicePrincipal != nil {
return *cachedIsServicePrincipal, nil
}
if cachedUser == nil {
var err error
cachedUser, err = w.CurrentUser.Me(ctx)
if err != nil {
return false, err
}
}
result := iamutil.IsServicePrincipal(cachedUser)
cachedIsServicePrincipal = &result
return result, nil
Expand Down
10 changes: 10 additions & 0 deletions libs/template/materialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/fs"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/filer"
)
Expand Down Expand Up @@ -42,6 +43,15 @@ func Materialize(ctx context.Context, configFilePath string, templateFS fs.FS, o
}
}

// Assert that the user is authenticated when materializing a template. We restrict
// usage of templates to authenticated users to log telemetry, even if the template
// does not require any authenticated functionality.
w := root.WorkspaceClient(ctx)
cachedUser, err = w.CurrentUser.Me(ctx)
if err != nil {
return fmt.Errorf("could not fetch information about the current user: %w", err)
}

helpers := loadHelpers(ctx)
r, err := newRenderer(ctx, config.values, helpers, templateFS, templateDirName, libraryDirName)
if err != nil {
Expand Down

0 comments on commit 47a9ca1

Please sign in to comment.