Skip to content

Commit 5579ce8

Browse files
Refactoring out of internal and dsn parsing
Moved implementation out of internal. Allow specifying auth type and parameters in dsn string. Refactored dsn parsing. Added tests to dsn parsing. Change default authenticator back to Noop Signed-off-by: Raymond Cypher <raymond.cypher@databricks.com>
1 parent 0127175 commit 5579ce8

20 files changed

Lines changed: 454 additions & 432 deletions

File tree

auth/auth.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
package auth
22

3-
import "net/http"
3+
import (
4+
"net/http"
5+
"strings"
6+
)
47

58
type Authenticator interface {
69
Authenticate(*http.Request) error
710
}
11+
12+
type AuthType int
13+
14+
const (
15+
AuthTypeUnknown AuthType = iota
16+
AuthTypePat
17+
AuthTypeOauthU2M
18+
AuthTypeOauthM2M
19+
)
20+
21+
var authTypeNames []string = []string{"Unknown", "Pat", "OauthU2m", "OauthM2M"}
22+
23+
func (at AuthType) String() string {
24+
if at >= 0 && int(at) < len(authTypeNames) {
25+
return authTypeNames[at]
26+
}
27+
28+
return authTypeNames[0]
29+
}
30+
31+
func ParseAuthType(typeString string) AuthType {
32+
typeString = strings.ToLower(typeString)
33+
for i, n := range authTypeNames {
34+
if strings.ToLower(n) == typeString {
35+
return AuthType(i)
36+
}
37+
}
38+
39+
return AuthTypeUnknown
40+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"golang.org/x/oauth2/clientcredentials"
1717
)
1818

19-
func NewClient(clientID, clientSecret, hostName string) auth.Authenticator {
19+
func NewAuthenticator(clientID, clientSecret, hostName string) auth.Authenticator {
2020
scopes := oauth.GetScopes(hostName, []string{})
2121
return &authClient{
2222
clientID: clientID,

auth/oauth/oauth.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import (
1111
)
1212

1313
const (
14-
azureEnterpriseAppId = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d"
14+
azureClientId = "96eecda7-19ea-49cc-abb5-240097d554f5"
15+
azureTenantId = "4a67d088-db5c-48f1-9ff2-0aace800ae68"
16+
azureRedirctURL = "localhost:8030"
17+
awsClientId = "databricks-sql-connector"
18+
awsRedirctURL = "localhost:8030"
1519
)
1620

1721
func GetEndpoint(ctx context.Context, hostName string) (oauth2.Endpoint, error) {
@@ -44,15 +48,15 @@ func GetEndpoint(ctx context.Context, hostName string) (oauth2.Endpoint, error)
4448
}
4549

4650
func GetScopes(hostName string, scopes []string) []string {
47-
for _, s := range []string{oidc.ScopeOfflineAccess, oidc.ScopeOpenID} {
51+
for _, s := range []string{oidc.ScopeOfflineAccess} {
4852
if !hasScope(scopes, s) {
4953
scopes = append(scopes, s)
5054
}
5155
}
5256

5357
cloudType := InferCloudFromHost(hostName)
5458
if cloudType == Azure {
55-
userImpersonationScope := fmt.Sprintf("%s/user_impersonation", azureEnterpriseAppId)
59+
userImpersonationScope := fmt.Sprintf("%s/user_impersonation", azureTenantId)
5660
if !hasScope(scopes, userImpersonationScope) {
5761
scopes = append(scopes, userImpersonationScope)
5862
}
@@ -85,14 +89,11 @@ var databricksAzureDomains []string = []string{
8589
".databricks.azure.us",
8690
}
8791

88-
var databricksGCPDomains []string = []string{".gcp.databricks.com"}
89-
9092
type CloudType int
9193

9294
const (
9395
AWS = iota
9496
Azure
95-
GCP
9697
Unknown
9798
)
9899

@@ -102,8 +103,6 @@ func (cl CloudType) String() string {
102103
return "AWS"
103104
case Azure:
104105
return "Azure"
105-
case GCP:
106-
return "GCP"
107106
}
108107

109108
return "Unknown"
@@ -123,11 +122,5 @@ func InferCloudFromHost(hostname string) CloudType {
123122
}
124123
}
125124

126-
for _, d := range databricksGCPDomains {
127-
if strings.Contains(hostname, d) {
128-
return GCP
129-
}
130-
}
131-
132125
return Unknown
133126
}

0 commit comments

Comments
 (0)