Skip to content

Commit

Permalink
update to use isPublic in deployed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoens committed Sep 5, 2024
1 parent f6c7741 commit 627e727
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions tabpy/tabpy_server/handlers/management_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def _add_or_update_endpoint(self, action, name, version, request_data):
target = request_data.get("target", None)
schema = request_data.get("schema", None)
src_path = request_data.get("src_path", None)
isPublic = request_data.get("isPublic", None)
target_path = get_query_object_path(
self.settings[SettingsParameters.StateFilePath], name, version
)
Expand Down Expand Up @@ -117,6 +118,7 @@ def _add_or_update_endpoint(self, action, name, version, request_data):
dependencies=dependencies,
target=target,
schema=schema,
isPublic = isPublic,
)
else:
self.tabpy_state.update_endpoint(
Expand All @@ -129,6 +131,7 @@ def _add_or_update_endpoint(self, action, name, version, request_data):
target=target,
schema=schema,
version=version,
isPublic = isPublic,
)

except Exception as e:
Expand Down
12 changes: 12 additions & 0 deletions tabpy/tabpy_server/management/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def _check_and_set_dependencies(self, dependencies, defaultValue):

return dependencies

def _check_and_set_is_public(self, isPublic, defaultValue):
if not isPublic:
return defaultValue

return isPublic

@state_lock
def add_endpoint(
self,
Expand All @@ -198,6 +204,7 @@ def add_endpoint(
target=None,
dependencies=None,
schema=None,
isPublic=None,
):
"""
Add a new endpoint to the TabPy.
Expand Down Expand Up @@ -231,6 +238,7 @@ def add_endpoint(
docstring, "-- no docstring found in query function --")
endpoint_type = self._check_and_set_endpoint_type(endpoint_type, None)
dependencies = self._check_and_set_dependencies(dependencies, [])
isPublic = self._check_and_set_is_public(isPublic, False)

self._check_target(target)
if target and target not in endpoints:
Expand All @@ -246,6 +254,7 @@ def add_endpoint(
"creation_time": int(time()),
"last_modified_time": int(time()),
"schema": schema,
"isPublic": isPublic,
}

endpoints[name] = endpoint_info
Expand Down Expand Up @@ -289,6 +298,7 @@ def update_endpoint(
target=None,
dependencies=None,
schema=None,
isPublic=None,
):
"""
Update an existing endpoint on the TabPy.
Expand Down Expand Up @@ -330,6 +340,7 @@ def update_endpoint(
endpoint_type, endpoint_info["type"])
dependencies = self._check_and_set_dependencies(
dependencies, endpoint_info.get("dependencies", []))
isPublic = self._check_and_set_is_public(isPublic, endpoint_info["isPublic"])

self._check_target(target)
if target and target not in endpoints:
Expand All @@ -352,6 +363,7 @@ def update_endpoint(
"creation_time": endpoint_info["creation_time"],
"last_modified_time": int(time()),
"schema": schema,
"isPublic": isPublic,
}

endpoints[name] = endpoint_info
Expand Down
23 changes: 18 additions & 5 deletions tabpy/tabpy_tools/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def get_endpoints(self, type=None):
"dependencies": [],
"last_modified_time": 1469511182,
"type": "model",
"target": null},
"target": null,
"isPublic": True}
"add": {
"description": "",
"docstring": "-- no docstring found in query function --",
Expand All @@ -182,7 +183,8 @@ def get_endpoints(self, type=None):
"dependencies": [],
"last_modified_time": 1469505967,
"type": "model",
"target": null}
"target": null,
"isPublic": False}
}
"""
return self._service.get_endpoints(type)
Expand All @@ -191,7 +193,7 @@ def _get_endpoint_upload_destination(self):
"""Returns the endpoint upload destination."""
return self._service.get_endpoint_upload_destination()["path"]

def deploy(self, name, obj, description="", schema=None, override=False):
def deploy(self, name, obj, description="", schema=None, override=False, isPublic=False):
"""Deploys a Python function as an endpoint in the server.
Parameters
Expand Down Expand Up @@ -220,6 +222,12 @@ def deploy(self, name, obj, description="", schema=None, override=False):
RuntimeError. If True and there is already an endpoint with that
name, it will deploy a new version on top of it.
isPublic : bool, optional
Whether a function should be public for viewing from within tableau. If
False, function will not appear in the custom functions explorer within
Tableau. If True, function will be visible ta anyone on a site with this
analytics extension configured
See Also
--------
remove, get_endpoints
Expand All @@ -236,7 +244,7 @@ def deploy(self, name, obj, description="", schema=None, override=False):

version = endpoint.version + 1

obj = self._gen_endpoint(name, obj, description, version, schema)
obj = self._gen_endpoint(name, obj, description, version, schema, isPublic)

self._upload_endpoint(obj)

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

def _gen_endpoint(self, name, obj, description, version=1, schema=None):
def _gen_endpoint(self, name, obj, description, version=1, schema=None, isPublic=False):
"""Generates an endpoint dict.
Parameters
Expand All @@ -274,6 +282,10 @@ def _gen_endpoint(self, name, obj, description, version=1, schema=None):
version : int
The version. Defaults to 1.
isPublic : bool
True if function should be visible in the custom functions explorer
within Tableau
Returns
-------
dict
Expand Down Expand Up @@ -318,6 +330,7 @@ def _gen_endpoint(self, name, obj, description, version=1, schema=None):
"required_files": [],
"required_packages": [],
"schema": copy.copy(schema),
"isPublic": isPublic,
}

def _upload_endpoint(self, obj):
Expand Down
2 changes: 2 additions & 0 deletions tabpy/tabpy_tools/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Endpoint(RESTObject):
evaluator = RESTProperty(str)
schema_version = RESTProperty(int)
schema = RESTProperty(str)
isPublic = RESTProperty(bool)

def __new__(cls, **kwargs):
"""Dispatch to the appropriate class."""
Expand All @@ -67,6 +68,7 @@ def __eq__(self, other):
and self.evaluator == other.evaluator
and self.schema_version == other.schema_version
and self.schema == other.schema
and self.isPublic == other.isPublic
)


Expand Down

0 comments on commit 627e727

Please sign in to comment.