@@ -82,6 +82,8 @@ class ClientSession(object):
82
82
83
83
:param user: associated with the query. It is useful for access control
84
84
and query scheduling.
85
+ :param authorization_user: associated with the query. It is useful for access control
86
+ and query scheduling.
85
87
:param source: associated with the query. It is useful for access
86
88
control and query scheduling.
87
89
:param catalog: to query. The *catalog* is associated with a Trino
@@ -113,6 +115,7 @@ class ClientSession(object):
113
115
def __init__ (
114
116
self ,
115
117
user : str ,
118
+ authorization_user : str = None ,
116
119
catalog : str = None ,
117
120
schema : str = None ,
118
121
source : str = None ,
@@ -125,6 +128,7 @@ def __init__(
125
128
timezone : str = None ,
126
129
):
127
130
self ._user = user
131
+ self ._authorization_user = authorization_user
128
132
self ._catalog = catalog
129
133
self ._schema = schema
130
134
self ._source = source
@@ -144,6 +148,16 @@ def __init__(
144
148
def user (self ):
145
149
return self ._user
146
150
151
+ @property
152
+ def authorization_user (self ):
153
+ with self ._object_lock :
154
+ return self ._authorization_user
155
+
156
+ @authorization_user .setter
157
+ def authorization_user (self , authorization_user ):
158
+ with self ._object_lock :
159
+ self ._authorization_user = authorization_user
160
+
147
161
@property
148
162
def catalog (self ):
149
163
with self ._object_lock :
@@ -441,6 +455,7 @@ def http_headers(self) -> Dict[str, str]:
441
455
headers [constants .HEADER_SCHEMA ] = self ._client_session .schema
442
456
headers [constants .HEADER_SOURCE ] = self ._client_session .source
443
457
headers [constants .HEADER_USER ] = self ._client_session .user
458
+ headers [constants .HEADER_AUTHORIZATION_USER ] = self ._client_session .authorization_user
444
459
headers [constants .HEADER_TIMEZONE ] = self ._client_session .timezone
445
460
headers [constants .HEADER_CLIENT_CAPABILITIES ] = 'PARAMETRIC_DATETIME'
446
461
headers ["user-agent" ] = f"{ constants .CLIENT_NAME } /{ __version__ } "
@@ -631,6 +646,12 @@ def process(self, http_response) -> TrinoStatus:
631
646
):
632
647
self ._client_session .prepared_statements .pop (name , None )
633
648
649
+ if constants .HEADER_SET_AUTHORIZATION_USER in http_response .headers :
650
+ self ._client_session .authorization_user = http_response .headers [constants .HEADER_SET_AUTHORIZATION_USER ]
651
+
652
+ if constants .HEADER_RESET_AUTHORIZATION_USER in http_response .headers :
653
+ self ._client_session .authorization_user = None
654
+
634
655
self ._next_uri = response .get ("nextUri" )
635
656
636
657
data = response .get ("data" ) if response .get ("data" ) else []
0 commit comments