Skip to content

Commit feaee60

Browse files
authored
Merge pull request #645 from tableau/jmoens/W-15923535
Add option to specify deployed fuctions as public
2 parents f6c7741 + fc80078 commit feaee60

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

tabpy/tabpy_server/handlers/management_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def _add_or_update_endpoint(self, action, name, version, request_data):
8484
target = request_data.get("target", None)
8585
schema = request_data.get("schema", None)
8686
src_path = request_data.get("src_path", None)
87+
is_public = request_data.get("is_public", None)
8788
target_path = get_query_object_path(
8889
self.settings[SettingsParameters.StateFilePath], name, version
8990
)
@@ -117,6 +118,7 @@ def _add_or_update_endpoint(self, action, name, version, request_data):
117118
dependencies=dependencies,
118119
target=target,
119120
schema=schema,
121+
is_public=is_public,
120122
)
121123
else:
122124
self.tabpy_state.update_endpoint(
@@ -129,6 +131,7 @@ def _add_or_update_endpoint(self, action, name, version, request_data):
129131
target=target,
130132
schema=schema,
131133
version=version,
134+
is_public=is_public,
132135
)
133136

134137
except Exception as e:

tabpy/tabpy_server/management/state.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ def _check_and_set_dependencies(self, dependencies, defaultValue):
187187

188188
return dependencies
189189

190+
def _check_and_set_is_public(self, is_public, defaultValue):
191+
if is_public is None:
192+
return defaultValue
193+
194+
return is_public
195+
190196
@state_lock
191197
def add_endpoint(
192198
self,
@@ -198,6 +204,7 @@ def add_endpoint(
198204
target=None,
199205
dependencies=None,
200206
schema=None,
207+
is_public=None,
201208
):
202209
"""
203210
Add a new endpoint to the TabPy.
@@ -231,6 +238,7 @@ def add_endpoint(
231238
docstring, "-- no docstring found in query function --")
232239
endpoint_type = self._check_and_set_endpoint_type(endpoint_type, None)
233240
dependencies = self._check_and_set_dependencies(dependencies, [])
241+
is_public = self._check_and_set_is_public(is_public, False)
234242

235243
self._check_target(target)
236244
if target and target not in endpoints:
@@ -246,6 +254,7 @@ def add_endpoint(
246254
"creation_time": int(time()),
247255
"last_modified_time": int(time()),
248256
"schema": schema,
257+
"is_public": is_public,
249258
}
250259

251260
endpoints[name] = endpoint_info
@@ -289,6 +298,7 @@ def update_endpoint(
289298
target=None,
290299
dependencies=None,
291300
schema=None,
301+
is_public=None,
292302
):
293303
"""
294304
Update an existing endpoint on the TabPy.
@@ -330,6 +340,7 @@ def update_endpoint(
330340
endpoint_type, endpoint_info["type"])
331341
dependencies = self._check_and_set_dependencies(
332342
dependencies, endpoint_info.get("dependencies", []))
343+
is_public = self._check_and_set_is_public(is_public, endpoint_info["is_public"])
333344

334345
self._check_target(target)
335346
if target and target not in endpoints:
@@ -352,6 +363,7 @@ def update_endpoint(
352363
"creation_time": endpoint_info["creation_time"],
353364
"last_modified_time": int(time()),
354365
"schema": schema,
366+
"is_public": is_public,
355367
}
356368

357369
endpoints[name] = endpoint_info

tabpy/tabpy_tools/client.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def get_endpoints(self, type=None):
173173
"dependencies": [],
174174
"last_modified_time": 1469511182,
175175
"type": "model",
176-
"target": null},
176+
"target": null,
177+
"is_public": True}
177178
"add": {
178179
"description": "",
179180
"docstring": "-- no docstring found in query function --",
@@ -182,7 +183,8 @@ def get_endpoints(self, type=None):
182183
"dependencies": [],
183184
"last_modified_time": 1469505967,
184185
"type": "model",
185-
"target": null}
186+
"target": null,
187+
"is_public": False}
186188
}
187189
"""
188190
return self._service.get_endpoints(type)
@@ -191,7 +193,7 @@ def _get_endpoint_upload_destination(self):
191193
"""Returns the endpoint upload destination."""
192194
return self._service.get_endpoint_upload_destination()["path"]
193195

194-
def deploy(self, name, obj, description="", schema=None, override=False):
196+
def deploy(self, name, obj, description="", schema=None, override=False, is_public=False):
195197
"""Deploys a Python function as an endpoint in the server.
196198
197199
Parameters
@@ -220,6 +222,12 @@ def deploy(self, name, obj, description="", schema=None, override=False):
220222
RuntimeError. If True and there is already an endpoint with that
221223
name, it will deploy a new version on top of it.
222224
225+
is_public : bool, optional
226+
Whether a function should be public for viewing from within tableau. If
227+
False, function will not appear in the custom functions explorer within
228+
Tableau. If True, function will be visible ta anyone on a site with this
229+
analytics extension configured
230+
223231
See Also
224232
--------
225233
remove, get_endpoints
@@ -236,7 +244,7 @@ def deploy(self, name, obj, description="", schema=None, override=False):
236244

237245
version = endpoint.version + 1
238246

239-
obj = self._gen_endpoint(name, obj, description, version, schema)
247+
obj = self._gen_endpoint(name, obj, description, version, schema, is_public)
240248

241249
self._upload_endpoint(obj)
242250

@@ -256,7 +264,7 @@ def remove(self, name):
256264
Endpoint name to remove'''
257265
self._service.remove_endpoint(name)
258266

259-
def _gen_endpoint(self, name, obj, description, version=1, schema=None):
267+
def _gen_endpoint(self, name, obj, description, version=1, schema=None, is_public=False):
260268
"""Generates an endpoint dict.
261269
262270
Parameters
@@ -274,6 +282,10 @@ def _gen_endpoint(self, name, obj, description, version=1, schema=None):
274282
version : int
275283
The version. Defaults to 1.
276284
285+
is_public : bool
286+
True if function should be visible in the custom functions explorer
287+
within Tableau
288+
277289
Returns
278290
-------
279291
dict
@@ -318,6 +330,7 @@ def _gen_endpoint(self, name, obj, description, version=1, schema=None):
318330
"required_files": [],
319331
"required_packages": [],
320332
"schema": copy.copy(schema),
333+
"is_public": is_public,
321334
}
322335

323336
def _upload_endpoint(self, obj):

tabpy/tabpy_tools/rest_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Endpoint(RESTObject):
4747
evaluator = RESTProperty(str)
4848
schema_version = RESTProperty(int)
4949
schema = RESTProperty(str)
50+
is_public = RESTProperty(bool)
5051

5152
def __new__(cls, **kwargs):
5253
"""Dispatch to the appropriate class."""
@@ -67,6 +68,7 @@ def __eq__(self, other):
6768
and self.evaluator == other.evaluator
6869
and self.schema_version == other.schema_version
6970
and self.schema == other.schema
71+
and self.is_public == other.is_public
7072
)
7173

7274

0 commit comments

Comments
 (0)