-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathconfig_type.go
More file actions
51 lines (45 loc) · 1.81 KB
/
config_type.go
File metadata and controls
51 lines (45 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package auth
import (
"strings"
"github.com/databricks/databricks-sdk-go/config"
)
// IsSPOG returns true if the config represents a SPOG (Single Pane of Glass)
// host with account-scoped OIDC. Detection is based on:
// 1. The resolved DiscoveryURL containing /oidc/accounts/ (from .well-known).
// 2. The Experimental_IsUnifiedHost flag as a legacy fallback.
//
// The accountID parameter is separate from cfg.AccountID so that callers can
// control the source: ResolveConfigType passes cfg.AccountID (from config file),
// while ToOAuthArgument passes the caller-provided value to avoid env var
// contamination (DATABRICKS_ACCOUNT_ID or .well-known back-fill).
func IsSPOG(cfg *config.Config, accountID string) bool {
if accountID == "" {
return false
}
if cfg.DiscoveryURL != "" && strings.Contains(cfg.DiscoveryURL, "/oidc/accounts/") {
return true
}
return cfg.Experimental_IsUnifiedHost
}
// ResolveConfigType determines the effective ConfigType for a resolved config.
// The SDK's ConfigType() classifies based on the host URL prefix alone, which
// misclassifies SPOG hosts (they don't match the accounts.* prefix). This
// function additionally uses IsSPOG to detect SPOG hosts.
//
// The cfg must already be resolved (via EnsureResolved) before calling this.
func ResolveConfigType(cfg *config.Config) config.ConfigType {
configType := cfg.ConfigType()
if configType == config.AccountConfig {
return configType
}
if !IsSPOG(cfg, cfg.AccountID) {
return configType
}
// The WorkspaceConfig return is a no-op when configType is already
// WorkspaceConfig, but is needed for InvalidConfig (legacy IsUnifiedHost
// profiles where the SDK dropped the UnifiedHost case in v0.126.0).
if cfg.WorkspaceID != "" && cfg.WorkspaceID != WorkspaceIDNone {
return config.WorkspaceConfig
}
return config.AccountConfig
}