1
+ import logging
1
2
from typing import List , Optional
2
3
3
4
from defusedxml .ElementTree import fromstring
4
5
5
6
from .connection_credentials import ConnectionCredentials
7
+ from .property_decorators import property_is_boolean
6
8
7
9
8
10
class ConnectionItem (object ):
@@ -17,6 +19,7 @@ def __init__(self):
17
19
self .server_port : Optional [str ] = None
18
20
self .username : Optional [str ] = None
19
21
self .connection_credentials : Optional [ConnectionCredentials ] = None
22
+ self ._query_tagging : Optional [bool ] = None
20
23
21
24
@property
22
25
def datasource_id (self ) -> Optional [str ]:
@@ -34,6 +37,22 @@ def id(self) -> Optional[str]:
34
37
def connection_type (self ) -> Optional [str ]:
35
38
return self ._connection_type
36
39
40
+ @property
41
+ def query_tagging (self ) -> Optional [bool ]:
42
+ return self ._query_tagging
43
+
44
+ @query_tagging .setter
45
+ @property_is_boolean
46
+ def query_tagging (self , value : Optional [bool ]):
47
+ # if connection type = hyper, Snowflake, or Teradata, we can't change this value: it is always true
48
+ if self ._connection_type in ["hyper" , "snowflake" , "teradata" ]:
49
+ logger = logging .getLogger ("tableauserverclient.models.connection_item" )
50
+ logger .debug (
51
+ "Cannot update value: Query tagging is always enabled for {} connections" .format (self ._connection_type )
52
+ )
53
+ return
54
+ self ._query_tagging = value
55
+
37
56
def __repr__ (self ):
38
57
return "<ConnectionItem#{_id} embed={embed_password} type={_connection_type} username={username}>" .format (
39
58
** self .__dict__
@@ -52,6 +71,7 @@ def from_response(cls, resp, ns) -> List["ConnectionItem"]:
52
71
connection_item .server_address = connection_xml .get ("serverAddress" , None )
53
72
connection_item .server_port = connection_xml .get ("serverPort" , None )
54
73
connection_item .username = connection_xml .get ("userName" , None )
74
+ connection_item ._query_tagging = string_to_bool (connection_xml .get ("queryTaggingEnabled" , None ))
55
75
datasource_elem = connection_xml .find (".//t:datasource" , namespaces = ns )
56
76
if datasource_elem is not None :
57
77
connection_item ._datasource_id = datasource_elem .get ("id" , None )
@@ -93,4 +113,4 @@ def from_xml_element(cls, parsed_response, ns) -> List["ConnectionItem"]:
93
113
94
114
# Used to convert string represented boolean to a boolean type
95
115
def string_to_bool (s : str ) -> bool :
96
- return s .lower () == "true"
116
+ return s is not None and s .lower () == "true"
0 commit comments