diff --git a/tabpy/tabpy_server/handlers/management_handler.py b/tabpy/tabpy_server/handlers/management_handler.py index f0cb6321..b2775655 100644 --- a/tabpy/tabpy_server/handlers/management_handler.py +++ b/tabpy/tabpy_server/handlers/management_handler.py @@ -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 ) @@ -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( @@ -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: diff --git a/tabpy/tabpy_server/management/state.py b/tabpy/tabpy_server/management/state.py index 12a5052b..19df5af9 100644 --- a/tabpy/tabpy_server/management/state.py +++ b/tabpy/tabpy_server/management/state.py @@ -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, @@ -198,6 +204,7 @@ def add_endpoint( target=None, dependencies=None, schema=None, + isPublic=None, ): """ Add a new endpoint to the TabPy. @@ -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: @@ -246,6 +254,7 @@ def add_endpoint( "creation_time": int(time()), "last_modified_time": int(time()), "schema": schema, + "isPublic": isPublic, } endpoints[name] = endpoint_info @@ -289,6 +298,7 @@ def update_endpoint( target=None, dependencies=None, schema=None, + isPublic=None, ): """ Update an existing endpoint on the TabPy. @@ -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: @@ -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 diff --git a/tabpy/tabpy_tools/client.py b/tabpy/tabpy_tools/client.py index f9e90023..6ee87003 100644 --- a/tabpy/tabpy_tools/client.py +++ b/tabpy/tabpy_tools/client.py @@ -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 --", @@ -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) @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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): diff --git a/tabpy/tabpy_tools/rest_client.py b/tabpy/tabpy_tools/rest_client.py index 71fa05db..6da6273b 100644 --- a/tabpy/tabpy_tools/rest_client.py +++ b/tabpy/tabpy_tools/rest_client.py @@ -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.""" @@ -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 )