cowbird.handlers.impl.geoserver
Attributes
Exceptions
Generic Geoserver error used to break request chains, as RequestTask only retries for a specific exception |
Classes
Base class for protocol classes. |
|
Base class for protocol classes. |
|
Base class for protocol classes. |
|
Keep Geoserver internal representation in sync with the platform. |
Functions
Decorator for response and logging handling for the different Geoserver HTTP requests. |
|
|
|
|
|
|
|
|
|
|
|
|
Module Contents
- class cowbird.handlers.impl.geoserver.GeoserverFuncSupportsWorkspace[source]
Bases:
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: ...
- class cowbird.handlers.impl.geoserver.GeoserverFuncSupportsDatastore[source]
Bases:
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: ...
- class cowbird.handlers.impl.geoserver.GeoserverFuncSupportsShapefile[source]
Bases:
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: ...
- cowbird.handlers.impl.geoserver.SHAPEFILE_OPTIONAL_EXTENSIONS = ['.atx', '.sbx', '.qix', '.aih', '.ain', '.shp.xml', '.cpg'][source]
- cowbird.handlers.impl.geoserver.geoserver_response_handling(func: GeoserverFuncSupportsWorkspace) GeoserverFuncSupportsWorkspace [source]
- cowbird.handlers.impl.geoserver.geoserver_response_handling(func: GeoserverFuncSupportsDatastore) GeoserverFuncSupportsDatastore
- cowbird.handlers.impl.geoserver.geoserver_response_handling(func: GeoserverFuncSupportsShapefile) GeoserverFuncSupportsShapefile
Decorator for response and logging handling for the different Geoserver HTTP requests.
- Parameters:
func – Function executing a http request to Geoserver
- Returns:
Response object
- class cowbird.handlers.impl.geoserver.Geoserver(settings: cowbird.typedefs.SettingsType, name: str, admin_user: str | None = None, admin_password: str | None = None, **kwargs: Any)[source]
Bases:
cowbird.handlers.handler.Handler
,cowbird.monitoring.fsmonitor.FSMonitor
Keep Geoserver internal representation in sync with the platform.
Create the geoserver handler instance.
- Parameters:
settings – Cowbird settings for convenience
name – Handler name
admin_user – Geoserver admin username
admin_password – Geoserver admin password
- get_shapefile_list(workspace_name: str, shapefile_name: str) List[str] [source]
Generates the list of all files associated with a shapefile name.
- _update_resource_paths_permissions(resource_type: str, permission: cowbird.permissions_synchronizer.Permission, resource_id: int, workspace_name: str, layer_name: str | None = None) None [source]
Updates a single Magpie resource’s associated paths according to its permissions found on Magpie.
- _update_resource_paths_permissions_recursive(resource: cowbird.typedefs.JSON, permission: cowbird.permissions_synchronizer.Permission, workspace_name: str) None [source]
Recursive method to update all the path permissions of a resource and its children resources as found on Magpie.
- _update_permissions_on_filesystem(permission: cowbird.permissions_synchronizer.Permission) None [source]
Updates the permissions of dir/files on the file system, after receiving a permission webhook event from Magpie.
- permission_created(permission: cowbird.permissions_synchronizer.Permission) None [source]
Called when Magpie sends a permission created webhook event.
- permission_deleted(permission: cowbird.permissions_synchronizer.Permission) None [source]
Called when Magpie sends a permission deleted webhook event.
- static get_instance() Geoserver | None [source]
Return the Geoserver singleton instance from the class name used to retrieve the FSMonitor from the DB.
- static publish_shapefile_task_chain(workspace_name: str, shapefile_name: str) None [source]
Applies the chain of tasks required to publish a new file to Geoserver.
- on_created(path: str) None [source]
Call when a new path is found.
- Parameters:
path – Absolute path of a new file/directory
- static remove_shapefile_task(workspace_name: str, shapefile_name: str) None [source]
Applies the celery task required to remove a shapefile from Geoserver.
- on_deleted(path: str) None [source]
Called when a path is deleted.
- Parameters:
path – Absolute path of a new file/directory
- on_modified(path: str) None [source]
Called when a path is updated.
- Parameters:
path – Absolute path of a new file/directory
- static _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 [source]
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.
- static _update_magpie_permissions(user_name: str, res_id: int, perm_scope: str, is_readable: bool, is_writable: bool) None [source]
Updates permissions on a Magpie resource (workspace/layer).
- _update_magpie_workspace_permissions(workspace_name: str) None [source]
Updates the permissions of a workspace resource on Magpie to the current permissions found on the corresponding datastore folder.
- _update_magpie_layer_permissions(workspace_name: str, layer_name: str) None [source]
Updates the permissions of a layer resource on Magpie to the current permissions found on the corresponding shapefile.
- create_workspace(name: str) None [source]
Create a new Geoserver workspace.
- Parameters:
name – Workspace name
- remove_workspace(name: str) None [source]
Removes a workspace from geoserver. Will also remove all datastores associated with the workspace.
- Parameters:
name – Workspace name
- create_datastore(workspace_name: str) None [source]
Create a new Geoserver workspace.
- Parameters:
self – Geoserver instance
workspace_name – Workspace name where the datastore must be created
- publish_shapefile(workspace_name: str, shapefile_name: str) None [source]
Publish a shapefile in the specified workspace.
- Parameters:
workspace_name – Name of the workspace from which the shapefile will be published
shapefile_name – The shapefile’s name, without file extension
- validate_shapefile(workspace_name: str, shapefile_name: str) None [source]
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.
- Parameters:
workspace_name – Name of the workspace from which the shapefile will be published
shapefile_name – The shapefile’s name, without file extension
- _get_shapefile_permissions(workspace_name: str, shapefile_name: str) Tuple[bool, bool] [source]
Resolves the shapefile permissions on the file system, by checking the shapefile’s main file permissions.
- _normalize_shapefile_permissions(workspace_name: str, shapefile_name: str, is_readable: bool, is_writable: bool) None [source]
Makes sure all files associated with a shapefile is owned by the default user/group and have the same permissions.
- remove_shapefile(workspace_name: str, filename: str) None [source]
Remove a shapefile from the specified workspace.
- Parameters:
workspace_name – Name of the workspace from which the shapefile will be removed
filename – The shapefile’s name, without file extension
- static _get_shapefile_info(filename: str) Tuple[str, str] [source]
- Parameters:
filename – Relative filename of a new file
- Returns:
Workspace name (str) where file is located and shapefile name (str)
- static _get_datastore_name(workspace_name: str) str [source]
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.
- _shapefile_folder_dir(workspace_name: str) str [source]
Returns the path to the user’s shapefile datastore inside the file system.
- static _geoserver_user_datastore_dir(user_name: str) str [source]
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.
- _create_workspace_request(*, workspace_name: str) requests.Response [source]
Request to create a new workspace.
- Parameters:
workspace_name – Name of workspace to be created
- Returns:
Response object
- _remove_workspace_request(*, workspace_name: str) requests.Response [source]
Request to remove workspace and all associated datastores and layers.
- Parameters:
workspace_name – Name of workspace to remove
- Returns:
Response object
- _create_datastore_request(*, workspace_name: str, datastore_name: str) requests.Response [source]
Initial creation of the datastore with no connection parameters.
- Parameters:
workspace_name – Name of the workspace in which the datastore is created
datastore_name – Name of the datastore that will be created
- Returns:
Response object
- _configure_datastore_request(*, workspace_name: str, datastore_name: str, datastore_path: str) requests.Response [source]
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.
- Parameters:
workspace_name – Name of the workspace in which the datastore is created
datastore_name – Name of the datastore that will be created
- Returns:
Response object
- _publish_shapefile_request(*, workspace_name: str, datastore_name: str, filename: str) requests.Response [source]
Request to publish a shapefile in Geoserver. Does so by creating a Feature type in Geoserver.
- Parameters:
workspace_name – Workspace where file will be published
datastore_name – Datastore where file will be published
filename – Name of the shapefile (with no extensions)
- Returns:
Response object
- _remove_shapefile_request(*, workspace_name: str, datastore_name: str, filename: str) requests.Response [source]
Request to remove specified Geoserver Feature type and corresponding layer.
- Parameters:
workspace_name – Workspace where file is published
datastore_name – Datastore where file is published
filename – Name of the shapefile (with no extensions)
- Returns:
Response object
- cowbird.handlers.impl.geoserver.create_workspace(_task: celery.Task[[str], None], user_name: str) None [source]
- cowbird.handlers.impl.geoserver.create_datastore(_task: celery.Task[[str], None], datastore_name: str) None [source]
- cowbird.handlers.impl.geoserver.remove_workspace(_task: celery.Task[[str], None], workspace_name: str) None [source]
- cowbird.handlers.impl.geoserver.validate_shapefile(_task: celery.Task[[Any, Any], None], workspace_name: str, shapefile_name: str) None [source]
- cowbird.handlers.impl.geoserver.publish_shapefile(_task: celery.Task[[Any, Any], None], workspace_name: str, shapefile_name: str) None [source]