mirror of https://github.com/databricks/cli.git
WIP: DATABRICKS_CA_BUNDLE
This commit is contained in:
parent
a44c52a399
commit
46f61fad09
|
@ -60,10 +60,10 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
profileName = profile
|
persistentAuth.Profile = profile
|
||||||
}
|
}
|
||||||
|
|
||||||
err := setHost(ctx, profileName, persistentAuth, args)
|
err := setHost(ctx, persistentAuth, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -127,10 +127,10 @@ func newLoginCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
|
||||||
return cmd
|
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.
|
// 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 {
|
_, 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.
|
// Tolerate ErrNoConfiguration here, as we will write out a configuration as part of the login flow.
|
||||||
if err != nil && !errors.Is(err, databrickscfg.ErrNoConfiguration) {
|
if err != nil && !errors.Is(err, databrickscfg.ErrNoConfiguration) {
|
||||||
|
|
|
@ -26,14 +26,14 @@ func newTokenCommand(persistentAuth *auth.PersistentAuth) *cobra.Command {
|
||||||
var profileName string
|
var profileName string
|
||||||
profileFlag := cmd.Flag("profile")
|
profileFlag := cmd.Flag("profile")
|
||||||
if profileFlag != nil {
|
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 a profile is provided we read the host from the .databrickscfg file
|
||||||
if profileName != "" && len(args) > 0 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -69,3 +69,5 @@ require (
|
||||||
google.golang.org/protobuf v1.32.0 // indirect
|
google.golang.org/protobuf v1.32.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace github.com/databricks/databricks-sdk-go => /Users/miles/databricks-sdk-go
|
||||||
|
|
|
@ -16,6 +16,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/auth/cache"
|
"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/databricks/databricks-sdk-go/retries"
|
||||||
"github.com/pkg/browser"
|
"github.com/pkg/browser"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
@ -42,6 +44,7 @@ var ( // Databricks SDK API: `databricks OAuth is not` will be checked for prese
|
||||||
type PersistentAuth struct {
|
type PersistentAuth struct {
|
||||||
Host string
|
Host string
|
||||||
AccountID string
|
AccountID string
|
||||||
|
Profile string
|
||||||
|
|
||||||
http httpGet
|
http httpGet
|
||||||
cache tokenCache
|
cache tokenCache
|
||||||
|
@ -82,6 +85,7 @@ func (a *PersistentAuth) Load(ctx context.Context) (*oauth2.Token, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// eagerly refresh token
|
// eagerly refresh token
|
||||||
|
ctx = context.WithValue(ctx, oauth2.HTTPClient, a.http)
|
||||||
refreshed, err := cfg.TokenSource(ctx, t).Token()
|
refreshed, err := cfg.TokenSource(ctx, t).Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("token refresh: %w", err)
|
return nil, fmt.Errorf("token refresh: %w", err)
|
||||||
|
@ -96,7 +100,9 @@ func (a *PersistentAuth) Load(ctx context.Context) (*oauth2.Token, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PersistentAuth) ProfileName() string {
|
func (a *PersistentAuth) ProfileName() string {
|
||||||
// TODO: get profile name from interactive input
|
if a.Profile != "" {
|
||||||
|
return a.Profile
|
||||||
|
}
|
||||||
if a.AccountID != "" {
|
if a.AccountID != "" {
|
||||||
return fmt.Sprintf("ACCOUNT-%s", a.AccountID)
|
return fmt.Sprintf("ACCOUNT-%s", a.AccountID)
|
||||||
}
|
}
|
||||||
|
@ -138,7 +144,25 @@ func (a *PersistentAuth) init(ctx context.Context) error {
|
||||||
return ErrFetchCredentials
|
return ErrFetchCredentials
|
||||||
}
|
}
|
||||||
if a.http == nil {
|
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 {
|
if a.cache == nil {
|
||||||
a.cache = &cache.TokenCache{}
|
a.cache = &cache.TokenCache{}
|
||||||
|
|
Loading…
Reference in New Issue