Skip to content

Commit d55b850

Browse files
feat: forward accessToken to trino sql driver with query args
1 parent e07d3e5 commit d55b850

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pkg/trino/datasource.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/grafana/grafana-plugin-sdk-go/data/sqlutil"
1414
"github.com/grafana/sqlds/v2"
1515
"github.com/pkg/errors"
16+
"github.com/trinodb/grafana-trino/pkg/trino/constants"
1617
"github.com/trinodb/grafana-trino/pkg/trino/driver"
1718
"github.com/trinodb/grafana-trino/pkg/trino/models"
1819
)
@@ -79,11 +80,20 @@ func (s *TrinoDatasource) Converters() (sc []sqlutil.Converter) {
7980
}
8081

8182
func (s *TrinoDatasource) SetQueryArgs(ctx context.Context, headers http.Header) []interface{} {
82-
user := ctx.Value("X-Trino-User")
83-
if user == nil {
84-
return []interface{}{}
83+
var args []interface{}
84+
85+
user := ctx.Value(constants.TrinoUserHeader)
86+
accessToken := ctx.Value(constants.AccessTokenKey)
87+
88+
if user != nil {
89+
args = append(args, sql.Named(constants.TrinoUserHeader, string(user.(*backend.User).Login)))
8590
}
86-
return []interface{}{sql.Named("X-Trino-User", string(user.(*backend.User).Login))}
91+
92+
if accessToken != nil {
93+
args = append(args, sql.Named(constants.AccessTokenKey, accessToken.(string)))
94+
}
95+
96+
return args
8797
}
8898

8999
func (s *TrinoDatasource) Schemas(ctx context.Context, options sqlds.Options) ([]string, error) {

0 commit comments

Comments
 (0)