Skip to content

Commit 3525dd3

Browse files
committed
Fix review issues: unified-host, HTTP method, config path, skip status
- isAccountLevelConfig now handles both AccountHost and UnifiedHost - checkIdentity uses isAccountLevelConfig instead of raw HostType check - Use http.MethodGet and authCfg.Host instead of empty strings - Remove hardcoded config file path (let SDK resolve it) - Add "skip" to CheckResult status doc comment - checkCurrentProfile shows resolved profile from config file Co-authored-by: Isaac
1 parent cd9a1a6 commit 3525dd3

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

cmd/doctor/checks.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10-
"path/filepath"
1110
"time"
1211

1312
"github.com/databricks/cli/internal/build"
@@ -38,7 +37,7 @@ func runChecks(cmd *cobra.Command) []CheckResult {
3837

3938
results = append(results, checkCLIVersion())
4039
results = append(results, checkConfigFile(cmd))
41-
results = append(results, checkCurrentProfile(cmd))
40+
results = append(results, checkCurrentProfile(cmd, cfg))
4241

4342
authResult, authCfg := checkAuth(cmd, cfg, err)
4443
results = append(results, authResult)
@@ -105,7 +104,7 @@ func checkConfigFile(cmd *cobra.Command) CheckResult {
105104
}
106105
}
107106

108-
func checkCurrentProfile(cmd *cobra.Command) CheckResult {
107+
func checkCurrentProfile(cmd *cobra.Command, resolvedCfg *config.Config) CheckResult {
109108
ctx := cmd.Context()
110109

111110
profileFlag := cmd.Flag("profile")
@@ -125,6 +124,15 @@ func checkCurrentProfile(cmd *cobra.Command) CheckResult {
125124
}
126125
}
127126

127+
// Check if the SDK resolved a profile (e.g. DEFAULT section in .databrickscfg).
128+
if resolvedCfg != nil && resolvedCfg.Profile != "" {
129+
return CheckResult{
130+
Name: "Current Profile",
131+
Status: statusInfo,
132+
Message: resolvedCfg.Profile + " (resolved from config file)",
133+
}
134+
}
135+
128136
return CheckResult{
129137
Name: "Current Profile",
130138
Status: statusInfo,
@@ -138,8 +146,6 @@ func resolveConfig(cmd *cobra.Command) (*config.Config, error) {
138146

139147
if configFile := env.Get(ctx, "DATABRICKS_CONFIG_FILE"); configFile != "" {
140148
cfg.ConfigFile = configFile
141-
} else if home := env.Get(ctx, env.HomeEnvVar()); home != "" {
142-
cfg.ConfigFile = filepath.Join(home, ".databrickscfg")
143149
}
144150

145151
cfg.Loaders = []config.Loader{
@@ -158,7 +164,17 @@ func resolveConfig(cmd *cobra.Command) (*config.Config, error) {
158164

159165
// isAccountLevelConfig returns true if the resolved config targets account-level APIs.
160166
func isAccountLevelConfig(cfg *config.Config) bool {
161-
return cfg.AccountID != "" && cfg.Host != "" && cfg.HostType() == config.AccountHost
167+
if cfg.AccountID == "" || cfg.Host == "" {
168+
return false
169+
}
170+
switch cfg.HostType() {
171+
case config.AccountHost:
172+
return true
173+
case config.UnifiedHost:
174+
return true
175+
default:
176+
return false
177+
}
162178
}
163179

164180
// checkAuth uses the resolved config to authenticate.
@@ -203,7 +219,7 @@ func checkAuth(cmd *cobra.Command, cfg *config.Config, resolveErr error) (CheckR
203219
authCfg = w.Config
204220
}
205221

206-
req, err := http.NewRequestWithContext(ctx, "", "", nil)
222+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, authCfg.Host, nil)
207223
if err != nil {
208224
return CheckResult{
209225
Name: "Authentication",
@@ -240,7 +256,7 @@ func checkIdentity(cmd *cobra.Command, authCfg *config.Config) CheckResult {
240256
defer cancel()
241257

242258
// Account-level configs don't support the /me endpoint for workspace identity.
243-
if authCfg.HostType() == config.AccountHost {
259+
if isAccountLevelConfig(authCfg) {
244260
return CheckResult{
245261
Name: "Identity",
246262
Status: statusSkip,

cmd/doctor/doctor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// CheckResult holds the outcome of a single diagnostic check.
1616
type CheckResult struct {
1717
Name string `json:"name"`
18-
Status string `json:"status"` // "pass", "fail", "warn", "info"
18+
Status string `json:"status"` // "pass", "fail", "warn", "info", "skip"
1919
Message string `json:"message"`
2020
Detail string `json:"detail,omitempty"`
2121
}

cmd/doctor/doctor_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestCheckCurrentProfileDefault(t *testing.T) {
143143
ctx := cmdio.MockDiscard(t.Context())
144144
cmd := newTestCmd(ctx)
145145

146-
result := checkCurrentProfile(cmd)
146+
result := checkCurrentProfile(cmd, nil)
147147
assert.Equal(t, "Current Profile", result.Name)
148148
assert.Equal(t, statusInfo, result.Status)
149149
assert.Equal(t, "none (using environment or defaults)", result.Message)
@@ -156,7 +156,7 @@ func TestCheckCurrentProfileFromFlag(t *testing.T) {
156156
require.NoError(t, err)
157157
cmd.Flag("profile").Changed = true
158158

159-
result := checkCurrentProfile(cmd)
159+
result := checkCurrentProfile(cmd, nil)
160160
assert.Equal(t, "Current Profile", result.Name)
161161
assert.Equal(t, statusInfo, result.Status)
162162
assert.Equal(t, "staging", result.Message)
@@ -167,7 +167,7 @@ func TestCheckCurrentProfileFromEnv(t *testing.T) {
167167
ctx = env.Set(ctx, "DATABRICKS_CONFIG_PROFILE", "from-env")
168168
cmd := newTestCmd(ctx)
169169

170-
result := checkCurrentProfile(cmd)
170+
result := checkCurrentProfile(cmd, nil)
171171
assert.Equal(t, statusInfo, result.Status)
172172
assert.Equal(t, "from-env (from DATABRICKS_CONFIG_PROFILE)", result.Message)
173173
}
@@ -180,7 +180,7 @@ func TestCheckCurrentProfileFlagOverridesEnv(t *testing.T) {
180180
require.NoError(t, err)
181181
cmd.Flag("profile").Changed = true
182182

183-
result := checkCurrentProfile(cmd)
183+
result := checkCurrentProfile(cmd, nil)
184184
assert.Equal(t, "from-flag", result.Message)
185185
}
186186

0 commit comments

Comments
 (0)