13
13
import cgi
14
14
from contextlib import closing
15
15
16
+ from typing import Iterable , List , Optional , TYPE_CHECKING , Tuple , Union
17
+
16
18
# The maximum size of a file that can be published in a single request is 64MB
17
19
FILESIZE_LIMIT = 1024 * 1024 * 64 # 64MB
18
20
19
21
ALLOWED_FILE_EXTENSIONS = ["tfl" , "tflx" ]
20
22
21
23
logger = logging .getLogger ("tableau.endpoint.flows" )
22
24
25
+ if TYPE_CHECKING :
26
+ from .. import DQWItem
27
+ from ..request_options import RequestOptions
28
+ from ...models .permissions_item import Permission , PermissionsRule
29
+
30
+
31
+ FilePath = Union [str , os .PathLike ]
32
+
23
33
24
34
class Flows (Endpoint ):
25
35
def __init__ (self , parent_srv ):
@@ -29,12 +39,12 @@ def __init__(self, parent_srv):
29
39
self ._data_quality_warnings = _DataQualityWarningEndpoint (self .parent_srv , "flow" )
30
40
31
41
@property
32
- def baseurl (self ):
42
+ def baseurl (self ) -> str :
33
43
return "{0}/sites/{1}/flows" .format (self .parent_srv .baseurl , self .parent_srv .site_id )
34
44
35
45
# Get all flows
36
46
@api (version = "3.3" )
37
- def get (self , req_options = None ):
47
+ def get (self , req_options : Optional [ "RequestOptions" ] = None ) -> Tuple [ List [ FlowItem ], PaginationItem ] :
38
48
logger .info ("Querying all flows on site" )
39
49
url = self .baseurl
40
50
server_response = self .get_request (url , req_options )
@@ -44,7 +54,7 @@ def get(self, req_options=None):
44
54
45
55
# Get 1 flow by id
46
56
@api (version = "3.3" )
47
- def get_by_id (self , flow_id ) :
57
+ def get_by_id (self , flow_id : str ) -> FlowItem :
48
58
if not flow_id :
49
59
error = "Flow ID undefined."
50
60
raise ValueError (error )
@@ -55,7 +65,7 @@ def get_by_id(self, flow_id):
55
65
56
66
# Populate flow item's connections
57
67
@api (version = "3.3" )
58
- def populate_connections (self , flow_item ) :
68
+ def populate_connections (self , flow_item : FlowItem ) -> None :
59
69
if not flow_item .id :
60
70
error = "Flow item missing ID. Flow must be retrieved from server first."
61
71
raise MissingRequiredFieldError (error )
@@ -66,15 +76,15 @@ def connections_fetcher():
66
76
flow_item ._set_connections (connections_fetcher )
67
77
logger .info ("Populated connections for flow (ID: {0})" .format (flow_item .id ))
68
78
69
- def _get_flow_connections (self , flow_item , req_options = None ):
79
+ def _get_flow_connections (self , flow_item , req_options : Optional [ "RequestOptions" ] = None ) -> List [ ConnectionItem ] :
70
80
url = "{0}/{1}/connections" .format (self .baseurl , flow_item .id )
71
81
server_response = self .get_request (url , req_options )
72
82
connections = ConnectionItem .from_response (server_response .content , self .parent_srv .namespace )
73
83
return connections
74
84
75
85
# Delete 1 flow by id
76
86
@api (version = "3.3" )
77
- def delete (self , flow_id ) :
87
+ def delete (self , flow_id : str ) -> None :
78
88
if not flow_id :
79
89
error = "Flow ID undefined."
80
90
raise ValueError (error )
@@ -84,7 +94,7 @@ def delete(self, flow_id):
84
94
85
95
# Download 1 flow by id
86
96
@api (version = "3.3" )
87
- def download (self , flow_id , filepath = None ):
97
+ def download (self , flow_id : str , filepath : FilePath = None ) -> str :
88
98
if not flow_id :
89
99
error = "Flow ID undefined."
90
100
raise ValueError (error )
@@ -105,7 +115,7 @@ def download(self, flow_id, filepath=None):
105
115
106
116
# Update flow
107
117
@api (version = "3.3" )
108
- def update (self , flow_item ) :
118
+ def update (self , flow_item : FlowItem ) -> FlowItem :
109
119
if not flow_item .id :
110
120
error = "Flow item missing ID. Flow must be retrieved from server first."
111
121
raise MissingRequiredFieldError (error )
@@ -122,7 +132,7 @@ def update(self, flow_item):
122
132
123
133
# Update flow connections
124
134
@api (version = "3.3" )
125
- def update_connection (self , flow_item , connection_item ) :
135
+ def update_connection (self , flow_item : FlowItem , connection_item : ConnectionItem ) -> ConnectionItem :
126
136
url = "{0}/{1}/connections/{2}" .format (self .baseurl , flow_item .id , connection_item .id )
127
137
128
138
update_req = RequestFactory .Connection .update_req (connection_item )
@@ -133,7 +143,7 @@ def update_connection(self, flow_item, connection_item):
133
143
return connection
134
144
135
145
@api (version = "3.3" )
136
- def refresh (self , flow_item ) :
146
+ def refresh (self , flow_item : FlowItem ) -> JobItem :
137
147
url = "{0}/{1}/run" .format (self .baseurl , flow_item .id )
138
148
empty_req = RequestFactory .Empty .empty_req ()
139
149
server_response = self .post_request (url , empty_req )
@@ -142,7 +152,9 @@ def refresh(self, flow_item):
142
152
143
153
# Publish flow
144
154
@api (version = "3.3" )
145
- def publish (self , flow_item , file_path , mode , connections = None ):
155
+ def publish (
156
+ self , flow_item : FlowItem , file_path : FilePath , mode : str , connections : Optional [List [ConnectionItem ]] = None
157
+ ) -> FlowItem :
146
158
if not os .path .isfile (file_path ):
147
159
error = "File path does not lead to an existing file."
148
160
raise IOError (error )
@@ -189,13 +201,8 @@ def publish(self, flow_item, file_path, mode, connections=None):
189
201
logger .info ("Published {0} (ID: {1})" .format (filename , new_flow .id ))
190
202
return new_flow
191
203
192
- server_response = self .post_request (url , xml_request , content_type )
193
- new_flow = FlowItem .from_response (server_response .content , self .parent_srv .namespace )[0 ]
194
- logger .info ("Published {0} (ID: {1})" .format (filename , new_flow .id ))
195
- return new_flow
196
-
197
204
@api (version = "3.3" )
198
- def populate_permissions (self , item ) :
205
+ def populate_permissions (self , item : FlowItem ) -> None :
199
206
self ._permissions .populate (item )
200
207
201
208
@api (version = "3.3" )
@@ -209,25 +216,25 @@ def update_permission(self, item, permission_item):
209
216
self ._permissions .update (item , permission_item )
210
217
211
218
@api (version = "3.3" )
212
- def update_permissions (self , item , permission_item ) :
219
+ def update_permissions (self , item : FlowItem , permission_item : Iterable [ "PermissionsRule" ]) -> None :
213
220
self ._permissions .update (item , permission_item )
214
221
215
222
@api (version = "3.3" )
216
- def delete_permission (self , item , capability_item ) :
223
+ def delete_permission (self , item : FlowItem , capability_item : "PermissionsRule" ) -> None :
217
224
self ._permissions .delete (item , capability_item )
218
225
219
226
@api (version = "3.5" )
220
- def populate_dqw (self , item ) :
227
+ def populate_dqw (self , item : FlowItem ) -> None :
221
228
self ._data_quality_warnings .populate (item )
222
229
223
230
@api (version = "3.5" )
224
- def update_dqw (self , item , warning ) :
231
+ def update_dqw (self , item : FlowItem , warning : "DQWItem" ) -> None :
225
232
return self ._data_quality_warnings .update (item , warning )
226
233
227
234
@api (version = "3.5" )
228
- def add_dqw (self , item , warning ) :
235
+ def add_dqw (self , item : FlowItem , warning : "DQWItem" ) -> None :
229
236
return self ._data_quality_warnings .add (item , warning )
230
237
231
238
@api (version = "3.5" )
232
- def delete_dqw (self , item ) :
239
+ def delete_dqw (self , item : FlowItem ) -> None :
233
240
self ._data_quality_warnings .clear (item )
0 commit comments