cowbird.handlers.impl.geoserver =============================== .. py:module:: cowbird.handlers.impl.geoserver Attributes ---------- .. autoapisummary:: cowbird.handlers.impl.geoserver.GeoserverType cowbird.handlers.impl.geoserver.GeoserverFunc cowbird.handlers.impl.geoserver.SHAPEFILE_MAIN_EXTENSION cowbird.handlers.impl.geoserver.SHAPEFILE_REQUIRED_EXTENSIONS cowbird.handlers.impl.geoserver.SHAPEFILE_OPTIONAL_EXTENSIONS cowbird.handlers.impl.geoserver.SHAPEFILE_ALL_EXTENSIONS cowbird.handlers.impl.geoserver.DEFAULT_DATASTORE_DIR_NAME cowbird.handlers.impl.geoserver.LOGGER Exceptions ---------- .. autoapisummary:: cowbird.handlers.impl.geoserver.GeoserverError Classes ------- .. autoapisummary:: cowbird.handlers.impl.geoserver.GeoserverFuncSupportsWorkspace cowbird.handlers.impl.geoserver.GeoserverFuncSupportsDatastore cowbird.handlers.impl.geoserver.GeoserverFuncSupportsShapefile cowbird.handlers.impl.geoserver.Geoserver Functions --------- .. autoapisummary:: cowbird.handlers.impl.geoserver.geoserver_response_handling cowbird.handlers.impl.geoserver.create_workspace cowbird.handlers.impl.geoserver.create_datastore cowbird.handlers.impl.geoserver.remove_workspace cowbird.handlers.impl.geoserver.validate_shapefile cowbird.handlers.impl.geoserver.publish_shapefile cowbird.handlers.impl.geoserver.remove_shapefile Module Contents --------------- .. py:type:: GeoserverType :canonical: 'Geoserver' .. py:class:: GeoserverFuncSupportsWorkspace Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... .. py:method:: __call__(*, workspace_name: str) -> requests.Response .. py:class:: GeoserverFuncSupportsDatastore Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... .. py:method:: __call__(*, workspace_name: str, datastore_name: str, datastore_path: str = None) -> requests.Response .. py:class:: GeoserverFuncSupportsShapefile Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... .. py:method:: __call__(*, workspace_name: str, datastore_name: str, filename: str) -> requests.Response .. py:data:: GeoserverFunc .. py:data:: SHAPEFILE_MAIN_EXTENSION :value: '.shp' .. py:data:: SHAPEFILE_REQUIRED_EXTENSIONS .. py:data:: SHAPEFILE_OPTIONAL_EXTENSIONS :value: ['.atx', '.sbx', '.qix', '.aih', '.ain', '.shp.xml', '.cpg'] .. py:data:: SHAPEFILE_ALL_EXTENSIONS :value: ['.atx', '.sbx', '.qix', '.aih', '.ain', '.shp.xml', '.cpg', '.shp', '.prj', '.dbf', '.shx'] .. py:data:: DEFAULT_DATASTORE_DIR_NAME :value: 'shapefile_datastore' .. py:data:: LOGGER .. py:function:: geoserver_response_handling(func: GeoserverFuncSupportsWorkspace) -> GeoserverFuncSupportsWorkspace geoserver_response_handling(func: GeoserverFuncSupportsDatastore) -> GeoserverFuncSupportsDatastore geoserver_response_handling(func: GeoserverFuncSupportsShapefile) -> GeoserverFuncSupportsShapefile Decorator for response and logging handling for the different Geoserver HTTP requests. :param func: Function executing a http request to Geoserver :returns: Response object .. py:class:: Geoserver(settings: cowbird.typedefs.SettingsType, name: str, admin_user: Optional[str] = None, admin_password: Optional[str] = None, **kwargs: Any) Bases: :py:obj:`cowbird.handlers.handler.Handler`, :py:obj:`cowbird.monitoring.fsmonitor.FSMonitor` Keep Geoserver internal representation in sync with the platform. Create the geoserver handler instance. :param settings: Cowbird settings for convenience :param name: Handler name :param admin_user: Geoserver admin username :param admin_password: Geoserver admin password .. py:attribute:: required_params .. py:attribute:: api_url .. py:attribute:: headers .. py:attribute:: admin_user :value: None .. py:attribute:: admin_password :value: None .. py:attribute:: auth .. py:attribute:: datastore_regex .. py:method:: user_created(user_name: str) -> None .. py:method:: user_deleted(user_name: str) -> None .. py:method:: get_shapefile_list(workspace_name: str, shapefile_name: str) -> List[str] Generates the list of all files associated with a shapefile name. .. py:method:: _update_resource_paths_permissions(resource_type: str, permission: cowbird.permissions_synchronizer.Permission, resource_id: int, workspace_name: str, layer_name: Optional[str] = None) -> None Updates a single Magpie resource's associated paths according to its permissions found on Magpie. .. py:method:: _update_resource_paths_permissions_recursive(resource: cowbird.typedefs.JSON, permission: cowbird.permissions_synchronizer.Permission, workspace_name: str) -> None Recursive method to update all the path permissions of a resource and its children resources as found on Magpie. .. py:method:: _update_permissions_on_filesystem(permission: cowbird.permissions_synchronizer.Permission) -> None Updates the permissions of dir/files on the file system, after receiving a permission webhook event from Magpie. .. py:method:: permission_created(permission: cowbird.permissions_synchronizer.Permission) -> None Called when Magpie sends a permission created webhook event. .. py:method:: permission_deleted(permission: cowbird.permissions_synchronizer.Permission) -> None Called when Magpie sends a permission deleted webhook event. .. py:method:: get_instance() -> Optional[Geoserver] :staticmethod: Return the Geoserver singleton instance from the class name used to retrieve the FSMonitor from the DB. .. py:method:: publish_shapefile_task_chain(workspace_name: str, shapefile_name: str) -> None :staticmethod: Applies the chain of tasks required to publish a new file to Geoserver. .. py:method:: on_created(path: str) -> None Call when a new path is found. :param path: Absolute path of a new file/directory .. py:method:: remove_shapefile_task(workspace_name: str, shapefile_name: str) -> None :staticmethod: Applies the celery task required to remove a shapefile from Geoserver. .. py:method:: on_deleted(path: str) -> None Called when a path is deleted. :param path: Absolute path of a new file/directory .. py:method:: on_modified(path: str) -> None Called when a path is updated. :param path: Absolute path of a new file/directory .. py:method:: resync() -> None .. py:method:: _is_permission_update_required(effective_permissions: List[cowbird.typedefs.JSON], user_name: str, res_id: int, perm_name: str, perm_access: str, perm_scope: str, delete_if_required: bool = False) -> bool :staticmethod: Checks if the required permission already exists on the resource, else returns true if an update is required. Also, deletes the permission if the associated input argument is activated. .. py:method:: _update_magpie_permissions(user_name: str, res_id: int, perm_scope: str, is_readable: bool, is_writable: bool) -> None :staticmethod: Updates permissions on a Magpie resource (workspace/layer). .. py:method:: _update_magpie_workspace_permissions(workspace_name: str) -> None Updates the permissions of a `workspace` resource on Magpie to the current permissions found on the corresponding datastore folder. .. py:method:: _update_magpie_layer_permissions(workspace_name: str, layer_name: str) -> None Updates the permissions of a `layer` resource on Magpie to the current permissions found on the corresponding shapefile. .. py:method:: create_workspace(name: str) -> None Create a new Geoserver workspace. :param name: Workspace name .. py:method:: remove_workspace(name: str) -> None Removes a workspace from geoserver. Will also remove all datastores associated with the workspace. :param name: Workspace name .. py:method:: create_datastore(workspace_name: str) -> None Create a new Geoserver workspace. :param self: Geoserver instance :param workspace_name: Workspace name where the datastore must be created .. py:method:: publish_shapefile(workspace_name: str, shapefile_name: str) -> None Publish a shapefile in the specified workspace. :param workspace_name: Name of the workspace from which the shapefile will be published :param shapefile_name: The shapefile's name, without file extension .. py:method:: validate_shapefile(workspace_name: str, shapefile_name: str) -> None Validate shapefile. Will look for the three other files necessary for Geoserver publishing (.prj, .dbf, .shx) and raise a FileNotFoundError exception if one is missing. :param workspace_name: Name of the workspace from which the shapefile will be published :param shapefile_name: The shapefile's name, without file extension .. py:method:: _get_shapefile_permissions(workspace_name: str, shapefile_name: str) -> Tuple[bool, bool] Resolves the shapefile permissions on the file system, by checking the shapefile's main file permissions. .. py:method:: _normalize_shapefile_permissions(workspace_name: str, shapefile_name: str, is_readable: bool, is_writable: bool) -> None Makes sure all files associated with a shapefile is owned by the default user/group and have the same permissions. .. py:method:: remove_shapefile(workspace_name: str, filename: str) -> None Remove a shapefile from the specified workspace. :param workspace_name: Name of the workspace from which the shapefile will be removed :param filename: The shapefile's name, without file extension .. py:method:: _get_shapefile_info(filename: str) -> Tuple[str, str] :staticmethod: :param filename: Relative filename of a new file :returns: Workspace name (str) where file is located and shapefile name (str) .. py:method:: _get_datastore_name(workspace_name: str) -> str :staticmethod: Return datastore name used to represent the datastore inside Geoserver. To be used in the HTTP requests sent to Geoserver. This name does not exist on the file system. .. py:method:: _shapefile_folder_dir(workspace_name: str) -> str Returns the path to the user's shapefile datastore inside the file system. .. py:method:: _geoserver_user_datastore_dir(user_name: str) -> str :staticmethod: Returns the path to the user's shapefile datastore inside the Geoserver instance container. Uses the ``WORKSPACE_DIR`` env variable mapped in the Geoserver container. .. py:method:: _create_workspace_request(*, workspace_name: str) -> requests.Response Request to create a new workspace. :param workspace_name: Name of workspace to be created :returns: Response object .. py:method:: _remove_workspace_request(*, workspace_name: str) -> requests.Response Request to remove workspace and all associated datastores and layers. :param workspace_name: Name of workspace to remove :returns: Response object .. py:method:: _create_datastore_dir(workspace_name: str) -> None .. py:method:: _create_datastore_request(*, workspace_name: str, datastore_name: str) -> requests.Response Initial creation of the datastore with no connection parameters. :param workspace_name: Name of the workspace in which the datastore is created :param datastore_name: Name of the datastore that will be created :returns: Response object .. py:method:: _configure_datastore_request(*, workspace_name: str, datastore_name: str, datastore_path: str) -> requests.Response Configures the connection parameters of the datastore. This is done as a secondary step because Geoserver tends to create the wrong type of datastore (shapefile instead of directory of shapefiles) when setting them at creation. :param workspace_name: Name of the workspace in which the datastore is created :param datastore_name: Name of the datastore that will be created :returns: Response object .. py:method:: _publish_shapefile_request(*, workspace_name: str, datastore_name: str, filename: str) -> requests.Response Request to publish a shapefile in Geoserver. Does so by creating a `Feature type` in Geoserver. :param workspace_name: Workspace where file will be published :param datastore_name: Datastore where file will be published :param filename: Name of the shapefile (with no extensions) :returns: Response object .. py:method:: _remove_shapefile_request(*, workspace_name: str, datastore_name: str, filename: str) -> requests.Response Request to remove specified Geoserver `Feature type` and corresponding layer. :param workspace_name: Workspace where file is published :param datastore_name: Datastore where file is published :param filename: Name of the shapefile (with no extensions) :returns: Response object .. py:function:: create_workspace(_task: celery.Task[[str], None], user_name: str) -> None .. py:function:: create_datastore(_task: celery.Task[[str], None], datastore_name: str) -> None .. py:function:: remove_workspace(_task: celery.Task[[str], None], workspace_name: str) -> None .. py:function:: validate_shapefile(_task: celery.Task[[Any, Any], None], workspace_name: str, shapefile_name: str) -> None .. py:function:: publish_shapefile(_task: celery.Task[[Any, Any], None], workspace_name: str, shapefile_name: str) -> None .. py:function:: remove_shapefile(_task: celery.Task[[Any, Any], None], workspace_name: str, shapefile_name: str) -> None .. py:exception:: GeoserverError Bases: :py:obj:`Exception` Generic Geoserver error used to break request chains, as RequestTask only retries for a specific exception (RequestException). Initialize self. See help(type(self)) for accurate signature.