@@ -82,6 +82,8 @@ class ClientSession(object):
8282
8383 :param user: associated with the query. It is useful for access control
8484 and query scheduling.
85+ :param authorization_user: associated with the query. It is useful for access control
86+ and query scheduling.
8587 :param source: associated with the query. It is useful for access
8688 control and query scheduling.
8789 :param catalog: to query. The *catalog* is associated with a Trino
@@ -113,6 +115,7 @@ class ClientSession(object):
113115 def __init__ (
114116 self ,
115117 user : str ,
118+ authorization_user : str = None ,
116119 catalog : str = None ,
117120 schema : str = None ,
118121 source : str = None ,
@@ -125,6 +128,7 @@ def __init__(
125128 timezone : str = None ,
126129 ):
127130 self ._user = user
131+ self ._authorization_user = authorization_user
128132 self ._catalog = catalog
129133 self ._schema = schema
130134 self ._source = source
@@ -144,6 +148,16 @@ def __init__(
144148 def user (self ):
145149 return self ._user
146150
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+
147161 @property
148162 def catalog (self ):
149163 with self ._object_lock :
@@ -441,6 +455,7 @@ def http_headers(self) -> Dict[str, str]:
441455 headers [constants .HEADER_SCHEMA ] = self ._client_session .schema
442456 headers [constants .HEADER_SOURCE ] = self ._client_session .source
443457 headers [constants .HEADER_USER ] = self ._client_session .user
458+ headers [constants .HEADER_AUTHORIZATION_USER ] = self ._client_session .authorization_user
444459 headers [constants .HEADER_TIMEZONE ] = self ._client_session .timezone
445460 headers [constants .HEADER_CLIENT_CAPABILITIES ] = 'PARAMETRIC_DATETIME'
446461 headers ["user-agent" ] = f"{ constants .CLIENT_NAME } /{ __version__ } "
@@ -630,6 +645,12 @@ def process(self, http_response) -> TrinoStatus:
630645 ):
631646 self ._client_session .prepared_statements .pop (name , None )
632647
648+ if constants .HEADER_SET_AUTHORIZATION_USER in http_response .headers :
649+ self ._client_session .authorization_user = http_response .headers [constants .HEADER_SET_AUTHORIZATION_USER ]
650+
651+ if constants .HEADER_RESET_AUTHORIZATION_USER in http_response .headers :
652+ self ._client_session .authorization_user = None
653+
633654 self ._next_uri = response .get ("nextUri" )
634655
635656 data = response .get ("data" ) if response .get ("data" ) else []
0 commit comments