@@ -10,56 +10,49 @@ import (
10
10
)
11
11
12
12
// Constructs all Databricks OIDC Credentials Strategies
13
- func buildOidcTokenCredentialStrategies (cfg * Config ) ([]CredentialsStrategy , error ) {
14
- // Maps in Go are unordered, so we need to maintain an order of the strategies.
15
- idTokenSourceOrder := []string {
16
- "github-oidc" ,
17
- // Add new providers at the end of the list
13
+ func buildOidcTokenCredentialStrategies (cfg * Config ) []CredentialsStrategy {
14
+ type namedIdTokenSource struct {
15
+ name string
16
+ tokenSource IDTokenSource
18
17
}
19
- idTokenSources := map [string ]IDTokenSource {
20
- "github-oidc" : & githubIDTokenSource {
21
- actionsIDTokenRequestURL : cfg .ActionsIDTokenRequestURL ,
22
- actionsIDTokenRequestToken : cfg .ActionsIDTokenRequestToken ,
23
- refreshClient : cfg .refreshClient ,
18
+ idTokenSources := []namedIdTokenSource {
19
+ {
20
+ name : "github-oidc" ,
21
+ tokenSource : & githubIDTokenSource {
22
+ actionsIDTokenRequestURL : cfg .ActionsIDTokenRequestURL ,
23
+ actionsIDTokenRequestToken : cfg .ActionsIDTokenRequestToken ,
24
+ refreshClient : cfg .refreshClient ,
25
+ },
24
26
},
25
27
// Add new providers at the end of the list
26
28
}
27
-
28
29
strategies := []CredentialsStrategy {}
29
- for _ , name := range idTokenSourceOrder {
30
- provider , ok := idTokenSources [name ]
31
- if ! ok {
32
- return nil , fmt .Errorf ("no provider found for %s" , name )
33
- }
34
- oidcConfig := & DatabricksOIDCTokenSourceConfig {
30
+ for _ , idTokenSource := range idTokenSources {
31
+ oidcConfig := DatabricksOIDCTokenSourceConfig {
35
32
ClientID : cfg .ClientID ,
36
- Host : cfg .Host ,
33
+ Host : cfg .CanonicalHostName () ,
37
34
TokenEndpointProvider : cfg .getOidcEndpoints ,
38
35
Audience : cfg .TokenAudience ,
39
- IdTokenSource : provider ,
36
+ IdTokenSource : idTokenSource . tokenSource ,
40
37
}
41
38
if cfg .IsAccountClient () {
42
39
oidcConfig .AccountID = cfg .AccountID
43
40
}
44
41
tokenSource := NewDatabricksOIDCTokenSource (oidcConfig )
45
- strategies = append (strategies , NewTokenSourceStrategy (name , tokenSource ))
42
+ strategies = append (strategies , NewTokenSourceStrategy (idTokenSource . name , tokenSource ))
46
43
}
47
- return strategies , nil
44
+ return strategies
48
45
}
49
46
50
- func buildDefaultStrategies (cfg * Config ) ( []CredentialsStrategy , error ) {
47
+ func buildDefaultStrategies (cfg * Config ) []CredentialsStrategy {
51
48
strategies := []CredentialsStrategy {}
52
49
strategies = append (strategies ,
53
50
PatCredentials {},
54
51
BasicCredentials {},
55
52
M2mCredentials {},
56
53
DatabricksCliCredentials ,
57
54
MetadataServiceCredentials {})
58
- oidcStrategies , err := buildOidcTokenCredentialStrategies (cfg )
59
- if err != nil {
60
- return nil , err
61
- }
62
- strategies = append (strategies , oidcStrategies ... )
55
+ strategies = append (strategies , buildOidcTokenCredentialStrategies (cfg )... )
63
56
strategies = append (strategies ,
64
57
// Attempt to configure auth from most specific to most generic (the Azure CLI).
65
58
AzureGithubOIDCCredentials {},
@@ -69,7 +62,7 @@ func buildDefaultStrategies(cfg *Config) ([]CredentialsStrategy, error) {
69
62
// Attempt to configure auth from most specific to most generic (Google Application Default Credentials).
70
63
GoogleCredentials {},
71
64
GoogleDefaultCredentials {})
72
- return strategies , nil
65
+ return strategies
73
66
}
74
67
75
68
type DefaultCredentials struct {
@@ -90,11 +83,11 @@ var errorMessage = fmt.Sprintf("cannot configure default credentials, please che
90
83
var ErrCannotConfigureAuth = errors .New (errorMessage )
91
84
92
85
func (c * DefaultCredentials ) Configure (ctx context.Context , cfg * Config ) (credentials.CredentialsProvider , error ) {
93
- strategies , err := buildDefaultStrategies ( cfg )
86
+ err := cfg . EnsureResolved ( )
94
87
if err != nil {
95
88
return nil , err
96
89
}
97
- for _ , p := range strategies {
90
+ for _ , p := range buildDefaultStrategies ( cfg ) {
98
91
if cfg .AuthType != "" && p .Name () != cfg .AuthType {
99
92
// ignore other auth types if one is explicitly enforced
100
93
logger .Infof (ctx , "Ignoring %s auth, because %s is preferred" , p .Name (), cfg .AuthType )
0 commit comments