cowbird.handlers.impl.geoserver

Module Contents

Classes

Geoserver

Keep Geoserver internal representation in sync with the platform.

Functions

geoserver_response_handling(func)

Decorator for response and logging handling for the different Geoserver HTTP requests.

create_workspace(_task, user_name)

create_datastore(_task, datastore_name)

remove_workspace(_task, workspace_name)

validate_shapefile(_task, workspace_name, shapefile_name)

publish_shapefile(_task, workspace_name, shapefile_name)

remove_shapefile(_task, workspace_name, shapefile_name)

Attributes

HANDLER_ADMIN_USER

HANDLER_ADMIN_PASSWORD

SHAPEFILE_MAIN_EXTENSION

SHAPEFILE_REQUIRED_EXTENSIONS

SHAPEFILE_OPTIONAL_EXTENSIONS

SHAPEFILE_ALL_EXTENSIONS

DEFAULT_DATASTORE_DIR_NAME

LOGGER

cowbird.handlers.impl.geoserver.HANDLER_ADMIN_USER = admin_user[source]
cowbird.handlers.impl.geoserver.HANDLER_ADMIN_PASSWORD = admin_password[source]
cowbird.handlers.impl.geoserver.SHAPEFILE_MAIN_EXTENSION = .shp[source]
cowbird.handlers.impl.geoserver.SHAPEFILE_REQUIRED_EXTENSIONS[source]
cowbird.handlers.impl.geoserver.SHAPEFILE_OPTIONAL_EXTENSIONS = ['.atx', '.sbx', '.qix', '.aih', '.ain', '.shp.xml', '.cpg'][source]
cowbird.handlers.impl.geoserver.SHAPEFILE_ALL_EXTENSIONS[source]
cowbird.handlers.impl.geoserver.DEFAULT_DATASTORE_DIR_NAME = shapefile_datastore[source]
cowbird.handlers.impl.geoserver.LOGGER[source]
cowbird.handlers.impl.geoserver.geoserver_response_handling(func)[source]

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, **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

required_params[source]
abstract get_resource_id(resource_full_name: str)str[source]

Each handler must provide this implementation required by the permission synchronizer.

The function needs to find the resource id in Magpie from the resource full name using its knowledge of the service. If the resource doesn’t already exist, the function needs to create it, again using its knowledge of resource type and parent resource type if required.

user_created(user_name)[source]
user_deleted(user_name)[source]
get_shapefile_list(workspace_name: str, shapefile_name: str)List[str][source]

Generates the list of all files associated with a shapefile name.

static _apply_new_path_permissions(path: str, is_readable: bool, is_writable: bool, is_executable: bool)None[source]

Applies new permissions to a path, if required.

static _apply_default_path_ownership(path: str)None[source]

Applies default ownership to a path, if required.

_update_resource_paths_permissions(resource_type: str, permission: cowbird.permissions_synchronizer.Permission, resource_id: int, workspace_name: str, layer_name: Optional[str] = None)None[source]

Updates a single Magpie resource’s associated paths according to its permissions found on Magpie.

_update_resource_paths_permissions_recursive(resource: Dict[str, 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)[source]

Called when Magpie sends a permission created webhook event.

permission_deleted(permission)[source]

Called when Magpie sends a permission deleted webhook event.

static get_instance()Geoserver[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)[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)[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[Dict[str, str]], 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)[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: Geoserver)None[source]

Create a new Geoserver workspace.

Parameters

name – Workspace name

remove_workspace(name: Geoserver)None[source]

Removes a workspace from geoserver. Will also remove all datastores associated with the workspace.

Parameters

name – Workspace name

create_datastore(workspace_name: Geoserver)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: Geoserver, 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, shapefile_name)[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)[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: Geoserver, 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: Geoserver)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: Geoserver)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_dir(workspace_name: str)None[source]
_create_datastore_request(workspace_name: Geoserver, 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: Geoserver, 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: Geoserver, 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: Geoserver, 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, user_name)[source]
cowbird.handlers.impl.geoserver.create_datastore(_task, datastore_name)[source]
cowbird.handlers.impl.geoserver.remove_workspace(_task, workspace_name)[source]
cowbird.handlers.impl.geoserver.validate_shapefile(_task, workspace_name, shapefile_name)[source]
cowbird.handlers.impl.geoserver.publish_shapefile(_task, workspace_name, shapefile_name)[source]
cowbird.handlers.impl.geoserver.remove_shapefile(_task, workspace_name, shapefile_name)[source]
exception cowbird.handlers.impl.geoserver.GeoserverError[source]

Bases: 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.