Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support DATABRICKS_CA_BUNDLE for allowing custom CA Certificates for Proxies #1277

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
if err != nil {
return err
}
profileName = profile
persistentAuth.Profile = profile
}

err := setHost(ctx, profileName, persistentAuth, args)
err := setHost(ctx, persistentAuth, args)
if err != nil {
return err
}
Expand Down Expand Up @@ -127,10 +127,10 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
return cmd
}

func setHost(ctx context.Context, profileName string, persistentAuth *auth.PersistentAuth, args []string) error {
func setHost(ctx context.Context, persistentAuth *auth.PersistentAuth, args []string) error {
// If the chosen profile has a hostname and the user hasn't specified a host, infer the host from the profile.
_, profiles, err := databrickscfg.LoadProfiles(ctx, func(p databrickscfg.Profile) bool {
return p.Name == profileName
return p.Name == persistentAuth.Profile
})
// Tolerate ErrNoConfiguration here, as we will write out a configuration as part of the login flow.
if err != nil && !errors.Is(err, databrickscfg.ErrNoConfiguration) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func newTokenCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
var profileName string
profileFlag := cmd.Flag("profile")
if profileFlag != nil {
profileName = profileFlag.Value.String()
persistentAuth.Profile = profileFlag.Value.String()
// If a profile is provided we read the host from the .databrickscfg file
if profileName != "" && len(args) > 0 {
return errors.New("providing both a profile and a host parameters is not supported")
return errors.New("providing both a profile and a hostname is not supported")
}
}

err := setHost(ctx, profileName, persistentAuth, args)
err := setHost(ctx, persistentAuth, args)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ require (
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/databricks/databricks-sdk-go => /Users/miles/databricks-sdk-go
28 changes: 26 additions & 2 deletions libs/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"time"

"github.com/databricks/cli/libs/auth/cache"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/httpclient"
"github.com/databricks/databricks-sdk-go/retries"
"github.com/pkg/browser"
"golang.org/x/oauth2"
Expand All @@ -42,6 +44,7 @@ var ( // Databricks SDK API: `databricks OAuth is not` will be checked for prese
type PersistentAuth struct {
Host string
AccountID string
Profile string

http httpGet
cache tokenCache
Expand Down Expand Up @@ -82,6 +85,7 @@ func (a *PersistentAuth) Load(ctx context.Context) (*oauth2.Token, error) {
return nil, err
}
// eagerly refresh token
ctx = context.WithValue(ctx, oauth2.HTTPClient, a.http)
refreshed, err := cfg.TokenSource(ctx, t).Token()
if err != nil {
return nil, fmt.Errorf("token refresh: %w", err)
Expand All @@ -96,7 +100,9 @@ func (a *PersistentAuth) Load(ctx context.Context) (*oauth2.Token, error) {
}

func (a *PersistentAuth) ProfileName() string {
// TODO: get profile name from interactive input
if a.Profile != "" {
return a.Profile
}
if a.AccountID != "" {
return fmt.Sprintf("ACCOUNT-%s", a.AccountID)
}
Expand Down Expand Up @@ -138,7 +144,25 @@ func (a *PersistentAuth) init(ctx context.Context) error {
return ErrFetchCredentials
}
if a.http == nil {
a.http = http.DefaultClient
c := &config.Config{
Profile: a.Profile,
Host: a.Host,
AccountID: a.AccountID,
}
c.EnsureResolved()
clientConfig := httpclient.ClientConfig{
DebugHeaders: c.DebugHeaders,
DebugTruncateBytes: c.DebugTruncateBytes,
InsecureSkipVerify: c.InsecureSkipVerify,
CABundle: c.CABundle,
RetryTimeout: time.Duration(c.RetryTimeoutSeconds) * time.Second,
HTTPTimeout: time.Duration(c.HTTPTimeoutSeconds) * time.Second,
}
httpClient, err := httpclient.NewHttpClient(clientConfig)
if err != nil {
return err
}
a.http = httpClient
}
if a.cache == nil {
a.cache = &cache.TokenCache{}
Expand Down
Loading