Don't attempt auth in `auth profiles --skip-validate` (#1282)

This makes the command almost instant, no matter how many profiles cfg
file has. One downside is that we don't set AuthType for profiles that
don't have it defined.

We can technically infer AuthType based on ConfigAttributes tags, but
their names are different from the names of actual auth providers (and
some tags cover multiple providers at the same time).
This commit is contained in:
Ilia Babanov 2024-04-05 12:19:54 +02:00 committed by GitHub
parent 6ac45e8bae
commit 338fe1fe62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 9 deletions

View File

@ -3,7 +3,6 @@ package auth
import ( import (
"context" "context"
"fmt" "fmt"
"net/http"
"os" "os"
"sync" "sync"
"time" "time"
@ -45,13 +44,7 @@ func (c *profileMetadata) Load(ctx context.Context, skipValidate bool) {
} }
if skipValidate { if skipValidate {
err := cfg.Authenticate(&http.Request{ c.Host = cfg.CanonicalHostName()
Header: make(http.Header),
})
if err != nil {
return
}
c.Host = cfg.Host
c.AuthType = cfg.AuthType c.AuthType = cfg.AuthType
return return
} }

View File

@ -21,8 +21,9 @@ func TestProfiles(t *testing.T) {
err := databrickscfg.SaveToProfile(ctx, &config.Config{ err := databrickscfg.SaveToProfile(ctx, &config.Config{
ConfigFile: configFile, ConfigFile: configFile,
Profile: "profile1", Profile: "profile1",
Host: "https://abc.cloud.databricks.com", Host: "abc.cloud.databricks.com",
Token: "token1", Token: "token1",
AuthType: "pat",
}) })
require.NoError(t, err) require.NoError(t, err)