@@ -90,8 +90,9 @@ func NewSampleDatasource(ctx context.Context, settings backend.DataSourceInstanc
9090 port = portInt
9191 }
9292
93- if datasourceSettings .AuthenticationMethod == "m2m" || datasourceSettings .AuthenticationMethod == "oauth2_client_credentials" {
93+ if datasourceSettings .AuthenticationMethod == "m2m" || datasourceSettings .AuthenticationMethod == "oauth2_client_credentials" || datasourceSettings . AuthenticationMethod == "azure_entra_pass_thru" {
9494 var authenticator auth.Authenticator
95+ var tokenStorage * integrations.TokenStorage
9596
9697 if datasourceSettings .AuthenticationMethod == "oauth2_client_credentials" {
9798 if datasourceSettings .ExternalCredentialsUrl == "" {
@@ -111,6 +112,9 @@ func NewSampleDatasource(ctx context.Context, settings backend.DataSourceInstanc
111112 datasourceSettings .Hostname ,
112113 []string {},
113114 )
115+ } else if datasourceSettings .AuthenticationMethod == "azure_entra_pass_thru" {
116+ tokenStorage = integrations .NewTokenStorage ("" )
117+ authenticator = integrations .NewAuthenticator (tokenStorage )
114118 } else {
115119 log .DefaultLogger .Info ("Authentication Method Parse Error" , "err" , nil )
116120 return nil , fmt .Errorf ("authentication Method Parse Error" )
@@ -132,18 +136,14 @@ func NewSampleDatasource(ctx context.Context, settings backend.DataSourceInstanc
132136 log .DefaultLogger .Info ("Init Databricks SQL DB" )
133137 databricksDB := sql .OpenDB (connector )
134138
135- if err := databricksDB .Ping (); err != nil {
136- log .DefaultLogger .Info ("Ping Error (Could not ping Databricks)" , "err" , err )
137- return nil , err
138- }
139-
140139 SetDatasourceSettings (databricksDB , connectionSettings )
141140 log .DefaultLogger .Info ("Store Databricks SQL DB Connection" )
142141 return & Datasource {
143142 connector : connector ,
144143 databricksDB : databricksDB ,
145144 connectionSettings : connectionSettings ,
146- datasourceSettings : * datasourceSettings ,
145+ tokenStorage : tokenStorage ,
146+ authMethod : datasourceSettings .AuthenticationMethod ,
147147 }, nil
148148 }
149149 } else if datasourceSettings .AuthenticationMethod == "dsn" || datasourceSettings .AuthenticationMethod == "" {
@@ -175,34 +175,9 @@ func NewSampleDatasource(ctx context.Context, settings backend.DataSourceInstanc
175175 connector : connector ,
176176 databricksDB : databricksDB ,
177177 connectionSettings : connectionSettings ,
178- datasourceSettings : * datasourceSettings ,
178+ authMethod : datasourceSettings . AuthenticationMethod ,
179179 }, nil
180180
181- } else if datasourceSettings .AuthenticationMethod == "azure_entra_pass_thru" {
182-
183- tokenStorage := integrations .NewTokenStorage ("" )
184- authenticator := integrations .NewAuthenticator (tokenStorage )
185- connector , err := dbsql .NewConnector (
186- dbsql .WithServerHostname (datasourceSettings .Hostname ),
187- dbsql .WithHTTPPath (datasourceSettings .Path ),
188- dbsql .WithPort (port ),
189- dbsql .WithAuthenticator (authenticator ),
190- dbsql .WithTimeout (connectionSettings .Timeout ),
191- dbsql .WithMaxRows (connectionSettings .MaxRows ),
192- dbsql .WithRetries (connectionSettings .Retries , connectionSettings .RetryBackoff , connectionSettings .MaxRetryDuration ),
193- )
194- if err != nil {
195- log .DefaultLogger .Info ("Connector Error" , "err" , err )
196- return nil , err
197- }
198-
199- return & Datasource {
200- connector : connector ,
201- databricksDB : nil ,
202- connectionSettings : connectionSettings ,
203- datasourceSettings : * datasourceSettings ,
204- tokenStorage : tokenStorage ,
205- }, nil
206181 }
207182
208183 return nil , fmt .Errorf ("Invalid Connection Method" )
@@ -324,7 +299,7 @@ type Datasource struct {
324299 connector driver.Connector
325300 databricksDB * sql.DB
326301 connectionSettings ConnectionSettings
327- datasourceSettings DatasourceSettings
302+ authMethod string
328303 tokenStorage * integrations.TokenStorage
329304}
330305
@@ -346,9 +321,9 @@ func (d *Datasource) Dispose() {
346321func (d * Datasource ) QueryData (ctx context.Context , req * backend.QueryDataRequest ) (* backend.QueryDataResponse , error ) {
347322 log .DefaultLogger .Info ("QueryData called" , "request" , req )
348323
349- if d .datasourceSettings . AuthenticationMethod == "azure_entra_pass_thru" {
324+ if d .authMethod == "azure_entra_pass_thru" {
350325 token := req .GetHTTPHeader (backend .OAuthIdentityTokenHeaderName )
351- err := d .CheckAzureEntraPassThru (token )
326+ err := d .CheckAzureEntraToken (token )
352327 if err != nil {
353328 log .DefaultLogger .Error ("Azure Entra Connection Failed" , "err" , err )
354329 return nil , err
@@ -456,31 +431,17 @@ func (d *Datasource) query(ctx context.Context, pCtx backend.PluginContext, quer
456431 return response
457432}
458433
459- func (d * Datasource ) CheckAzureEntraPassThru (token string ) error {
434+ func (d * Datasource ) CheckAzureEntraToken (token string ) error {
460435 if token == "" {
461436 log .DefaultLogger .Info ("Token is empty" )
462437 return fmt .Errorf ("no Azure Entra Token provided" )
463438 }
464- if d . databricksDB != nil && token == d .tokenStorage .Get () {
439+ if token == d .tokenStorage .Get () {
465440 return nil
466441 }
467- if token != d .tokenStorage .Get () {
468- log .DefaultLogger .Info ("Token changed" )
469- d .tokenStorage .Update (strings .TrimPrefix (token , "Bearer " ))
470- }
471- if d .databricksDB == nil {
472- log .DefaultLogger .Info ("Init Databricks SQL DB" )
473- databricksDB := sql .OpenDB (d .connector )
474442
475- if err := databricksDB .Ping (); err != nil {
476- log .DefaultLogger .Info ("Ping Error (Could not ping Databricks)" , "err" , err )
477- return err
478- }
479-
480- SetDatasourceSettings (databricksDB , d .connectionSettings )
481- log .DefaultLogger .Info ("Store Databricks SQL DB Connection" )
482- d .databricksDB = databricksDB
483- }
443+ log .DefaultLogger .Info ("Token changed" )
444+ d .tokenStorage .Update (strings .TrimPrefix (token , "Bearer " ))
484445
485446 return nil
486447}
@@ -490,10 +451,10 @@ func (d *Datasource) CheckAzureEntraPassThru(token string) error {
490451// datasource configuration page which allows users to verify that
491452// a datasource is working as expected.
492453func (d * Datasource ) CheckHealth (ctx context.Context , req * backend.CheckHealthRequest ) (* backend.CheckHealthResult , error ) {
493- if d .datasourceSettings . AuthenticationMethod == "azure_entra_pass_thru" {
454+ if d .authMethod == "azure_entra_pass_thru" {
494455
495456 token := req .GetHTTPHeader (backend .OAuthIdentityTokenHeaderName )
496- err := d .CheckAzureEntraPassThru (token )
457+ err := d .CheckAzureEntraToken (token )
497458 if err != nil {
498459 return & backend.CheckHealthResult {
499460 Status : backend .HealthStatusError ,
0 commit comments