Skip to content

Commit 3416240

Browse files
committed
update to allow users to update functions without redefining them locally
1 parent 3e03f1c commit 3416240

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

tabpy/tabpy_server/handlers/management_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _add_or_update_endpoint(self, action, name, version, request_data):
4747
"""
4848
Add or update an endpoint
4949
"""
50-
self.logger.log(logging.DEBUG, f"Adding/updating model {name}...")
50+
self.logger.log(logging.INFO, f"Adding/updating model {name}...")
5151

5252
if not isinstance(name, str):
5353
msg = "Endpoint name must be a string"

tabpy/tabpy_server/management/state.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -428,36 +428,6 @@ def delete_endpoint(self, name):
428428
logger.error(f"Unable to delete endpoint {e}")
429429
raise ValueError(f"Unable to delete endpoint: {e}")
430430

431-
432-
@state_lock
433-
def make_endpoint_public(self, name):
434-
"""
435-
Updates an existing endpoint on the TabPy Server to be public
436-
437-
Parameters
438-
----------
439-
name : str
440-
The name of the endpoint to be updated.
441-
442-
Returns
443-
-------
444-
updated endpoint object
445-
446-
"""
447-
if not name or name == "":
448-
raise ValueError("Name of the endpoint must be a valid string.")
449-
endpoints = self.get_endpoints()
450-
if name not in endpoints:
451-
raise ValueError(f"Endpoint {name} does not exist.")
452-
453-
endpoint_to_update = endpoints[name]
454-
455-
456-
self.update_endpoint(
457-
name,
458-
is_public=True
459-
)
460-
461431
@property
462432
def name(self):
463433
"""

tabpy/tabpy_tools/client.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,55 @@ def remove(self, name):
264264
Endpoint name to remove'''
265265
self._service.remove_endpoint(name)
266266

267-
def make_public(self, name):
268-
'''Makes an existing endpoint public.
267+
def update(self, name, description=None, schema=None, is_public=None):
268+
'''Updates description, schema, or is public for an existing endpoint
269269
270270
Parameters
271271
----------
272272
name : str
273-
Endpoint name to make public'''
273+
Endpoint name to make public
274+
275+
description : str, optional
276+
The description for the endpoint. This string will be returned by
277+
the ``endpoints`` API.
278+
279+
schema : dict, optional
280+
The schema of the function, containing information about input and
281+
output parameters, and respective examples. Providing a schema for
282+
a deployed function lets other users of the service discover how to
283+
use it. Refer to schema.generate_schema for more information on
284+
how to generate the schema.
285+
286+
is_public : bool, optional
287+
Whether a function should be public for viewing from within tableau. If
288+
False, function will not appear in the custom functions explorer within
289+
Tableau. If True, function will be visible ta anyone on a site with this
290+
analytics extension configured
291+
'''
274292

275293
endpoint = self.get_endpoints().get(name)
276-
self._service.make_public(endpoint)
294+
295+
if not endpoint:
296+
raise RuntimeError(
297+
f"No endpoint with that name ({name}) exists"
298+
" Please select an existing endpoint to update"
299+
)
300+
301+
if description is not None:
302+
endpoint.description = description
303+
if schema is not None:
304+
endpoint.schema = schema
305+
if is_public is not None:
306+
endpoint.is_public = is_public
307+
308+
dest_path = self._get_endpoint_upload_destination()
309+
310+
# Upload the endpoint
311+
endpoint.src_path = os.path.join(
312+
dest_path, "endpoints", endpoint.name, str(endpoint.version)
313+
)
314+
315+
self._service.set_endpoint(endpoint)
277316

278317
def _gen_endpoint(self, name, obj, description, version=1, schema=None, is_public=False):
279318
"""Generates an endpoint dict.

0 commit comments

Comments
 (0)