11package doctor
22
33import (
4+ "errors"
45 "fmt"
6+ "io"
57 "net/http"
8+ "time"
69
710 "github.com/databricks/cli/internal/build"
811 "github.com/databricks/cli/libs/databrickscfg/profile"
12+ "github.com/databricks/cli/libs/env"
913 "github.com/databricks/databricks-sdk-go"
1014 "github.com/databricks/databricks-sdk-go/config"
1115 "github.com/spf13/cobra"
@@ -14,7 +18,10 @@ import (
1418const (
1519 statusPass = "pass"
1620 statusFail = "fail"
21+ statusWarn = "warn"
1722 statusInfo = "info"
23+
24+ networkTimeout = 10 * time .Second
1825)
1926
2027// runChecks runs all diagnostic checks and returns the results.
@@ -67,6 +74,14 @@ func checkConfigFile(cmd *cobra.Command) CheckResult {
6774
6875 profiles , err := profiler .LoadProfiles (ctx , profile .MatchAllProfiles )
6976 if err != nil {
77+ // Config file absence is not a hard failure since auth can work via env vars.
78+ if errors .Is (err , profile .ErrNoConfiguration ) {
79+ return CheckResult {
80+ Name : "Config File" ,
81+ Status : statusWarn ,
82+ Message : "No config file found (auth can still work via environment variables)" ,
83+ }
84+ }
7085 return CheckResult {
7186 Name : "Config File" ,
7287 Status : statusFail ,
@@ -83,18 +98,34 @@ func checkConfigFile(cmd *cobra.Command) CheckResult {
8398}
8499
85100func checkCurrentProfile (cmd * cobra.Command ) CheckResult {
101+ ctx := cmd .Context ()
102+
86103 profileFlag := cmd .Flag ("profile" )
87- profileName := "default"
88104 if profileFlag != nil && profileFlag .Changed {
89- profileName = profileFlag .Value .String ()
105+ return CheckResult {
106+ Name : "Current Profile" ,
107+ Status : statusInfo ,
108+ Message : profileFlag .Value .String (),
109+ }
90110 }
111+
112+ if envProfile := env .Get (ctx , "DATABRICKS_CONFIG_PROFILE" ); envProfile != "" {
113+ return CheckResult {
114+ Name : "Current Profile" ,
115+ Status : statusInfo ,
116+ Message : envProfile + " (from DATABRICKS_CONFIG_PROFILE)" ,
117+ }
118+ }
119+
91120 return CheckResult {
92121 Name : "Current Profile" ,
93122 Status : statusInfo ,
94- Message : profileName ,
123+ Message : "none (using environment or defaults)" ,
95124 }
96125}
97126
127+ // checkAuth uses the SDK's standard config resolution to authenticate.
128+ // This respects --profile, --host, environment variables, and config file.
98129func checkAuth (cmd * cobra.Command ) (CheckResult , * databricks.WorkspaceClient ) {
99130 ctx := cmd .Context ()
100131 cfg := & config.Config {}
@@ -198,7 +229,8 @@ func checkNetworkWithHost(cmd *cobra.Command, host string) CheckResult {
198229 }
199230 }
200231
201- resp , err := http .DefaultClient .Do (req )
232+ client := & http.Client {Timeout : networkTimeout }
233+ resp , err := client .Do (req )
202234 if err != nil {
203235 return CheckResult {
204236 Name : "Network" ,
@@ -207,7 +239,8 @@ func checkNetworkWithHost(cmd *cobra.Command, host string) CheckResult {
207239 Detail : err .Error (),
208240 }
209241 }
210- resp .Body .Close ()
242+ defer resp .Body .Close ()
243+ io .Copy (io .Discard , resp .Body )
211244
212245 return CheckResult {
213246 Name : "Network" ,
0 commit comments