cowbird.handlers.impl.magpie

Attributes

HANDLER_URL_PARAM

JSON

PermissionActionType

PermissionConfigItemType

SettingsType

CONTENT_TYPE_JSON

LOGGER

COOKIES_TIMEOUT

WFS_READ_PERMISSIONS

WFS_WRITE_PERMISSIONS

WMS_READ_PERMISSIONS

WPS_READ_PERMISSIONS

WPS_WRITE_PERMISSIONS

GEOSERVER_READ_PERMISSIONS

GEOSERVER_WRITE_PERMISSIONS

Exceptions

ConfigError

Generic error during configuration loading.

MagpieHttpError

Exception related to http requests done by the Magpie handler.

Classes

Handler

Helper class that provides a standard way to create an ABC using

PermissionSynchronizer

Keep service-shared resources in sync when permissions are updated for one of them.

Magpie

Complete the Magpie's webhook call by calling Magpie temporary urls. Also keep service-shared resources in sync when

Functions

get_logger(→ logging.Logger)

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when

Module Contents

exception cowbird.handlers.impl.magpie.ConfigError[source]

Bases: RuntimeError

Generic error during configuration loading.

Initialize self. See help(type(self)) for accurate signature.

cowbird.handlers.impl.magpie.HANDLER_URL_PARAM: AnyHandlerParameter = 'url'[source]
class cowbird.handlers.impl.magpie.Handler(settings: cowbird.typedefs.SettingsType, name: str, **kwargs: Any)[source]

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:
  • settings – Cowbird settings for convenience

  • name – Handler name

  • kwargs – The base class handle, but doesn’t require the following variables:

  • url – Location of the web service represented by the cowbird handler

  • workspace_dir – Workspace directory

  • priority – Relative priority between handlers while handling events. Lower value has higher priority, default value is last.

__slots__

Handler interface used to notify implemented handlers of users/permissions changes.

Todo

At some point we will need a consistency function that goes through all Magpie users and make sure that handlers are up-to-date.

property required_params: List[AnyHandlerParameter]
Abstractmethod:

json() cowbird.typedefs.JSON[source]
_user_workspace_dir(user_name: str) str[source]
abstract user_created(user_name: str) None[source]
abstract user_deleted(user_name: str) None[source]
abstract permission_created(permission: cowbird.permissions_synchronizer.Permission) None[source]
abstract permission_deleted(permission: cowbird.permissions_synchronizer.Permission) None[source]
abstract resync() None[source]
class cowbird.handlers.impl.magpie.PermissionSynchronizer(magpie_inst: cowbird.handlers.impl.magpie.Magpie)[source]

Bases: object

Keep service-shared resources in sync when permissions are updated for one of them.

Todo

At some point we will need a consistency function that goes through all permissions of all services and make sure that linked services have the same permissions.

create_permission(permission: Permission) None[source]

Create the same permission on each service sharing the same resource.

delete_permission(permission: Permission) None[source]

Delete the same permission on each service sharing the same resource.

cowbird.handlers.impl.magpie.JSON[source]
cowbird.handlers.impl.magpie.PermissionActionType: typing_extensions.TypeAlias = 'PermissionAction'[source]
cowbird.handlers.impl.magpie.PermissionConfigItemType: typing_extensions.TypeAlias = 'PermissionConfigItem'[source]
cowbird.handlers.impl.magpie.SettingsType[source]
cowbird.handlers.impl.magpie.CONTENT_TYPE_JSON = 'application/json'[source]
cowbird.handlers.impl.magpie.get_logger(name: str, level: int | None = None, force_stdout: bool = None, message_format: str | None = None, datetime_format: str | None = None) logging.Logger[source]

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is logging.NOTSET.

cowbird.handlers.impl.magpie.LOGGER[source]
cowbird.handlers.impl.magpie.COOKIES_TIMEOUT = 60[source]
cowbird.handlers.impl.magpie.WFS_READ_PERMISSIONS[source]
cowbird.handlers.impl.magpie.WFS_WRITE_PERMISSIONS[source]
cowbird.handlers.impl.magpie.WMS_READ_PERMISSIONS[source]
cowbird.handlers.impl.magpie.WPS_READ_PERMISSIONS[source]
cowbird.handlers.impl.magpie.WPS_WRITE_PERMISSIONS[source]
cowbird.handlers.impl.magpie.GEOSERVER_READ_PERMISSIONS[source]
cowbird.handlers.impl.magpie.GEOSERVER_WRITE_PERMISSIONS[source]
class cowbird.handlers.impl.magpie.Magpie(settings: cowbird.typedefs.SettingsType, name: str, admin_user: str, admin_password: str, **kwargs: Any)[source]

Bases: cowbird.handlers.handler.Handler

Complete the Magpie’s webhook call by calling Magpie temporary urls. Also keep service-shared resources in sync when permissions are updated for one of them.

** Cowbird components diagram 1.2.0 needs to be updated since Magpie can handle permissions synchronisation directly on permission update events. No need to handle them explicitly in nginx, thredds and geoserver classes.

Create the magpie instance and instantiate the permission synchronizer that will handle the permission events.

Parameters:
  • settings – Cowbird settings for convenience

  • name – Handler name

  • admin_user – Magpie admin username used for login.

  • admin_password – Magpie admin password used for login.

required_params[source]
_send_request(method: str, url: str, params: Any | None = None, json: Any | None = None) requests.Response[source]

Wrapping function to send requests to Magpie, which also handles login and cookies.

get_service_types() List[str][source]

Returns the list of service types available on Magpie.

get_services_by_type(service_type: str) Dict[str, cowbird.typedefs.JSON][source]
get_service_info(service_name: str) Dict[str, cowbird.typedefs.JSON][source]
get_resources_by_service(service_name: str) Dict[str, cowbird.typedefs.JSON][source]
get_parents_resource_tree(resource_id: int) List[cowbird.typedefs.JSON][source]

Returns the associated Magpie Resource object and all its parents in a list ordered from parent to child.

get_resource(resource_id: int) Dict[str, cowbird.typedefs.JSON][source]

Returns the associated Magpie Resource object.

get_geoserver_workspace_res_id(workspace_name: str, create_if_missing: bool | None = False) int | None[source]

Finds the resource id of a workspace resource from the geoserver type services.

get_geoserver_layer_res_id(workspace_name: str, layer_name: str, create_if_missing: bool = False) int[source]

Tries to get the resource id of a specific layer, on geoserver type services, and if requested, creates the resource and workspace if they do not exist yet.

get_user_list() List[str][source]

Returns the list of all Magpie usernames.

get_user_id_from_user_name(user_name: str) int[source]

Finds the id of a user from his username.

get_user_name_from_user_id(user_id: int) str[source]

Finds the name of a user from his user id.

get_user_permissions(user: str) Dict[str, cowbird.typedefs.JSON][source]

Gets all user resource permissions.

get_user_permissions_by_res_id(user: str, res_id: int, effective: bool = False) Dict[str, cowbird.typedefs.JSON][source]
get_user_names_by_group_name(grp_name: str) List[str][source]

Returns the list of Magpie usernames from a group.

get_group_permissions(grp: str) Dict[str, cowbird.typedefs.JSON][source]

Gets all group resource permissions.

get_group_permissions_by_res_id(grp: str, res_id: int, effective: bool = False) Dict[str, cowbird.typedefs.JSON][source]
abstract user_created(user_name: str) None[source]
abstract user_deleted(user_name: str) None[source]
permission_created(permission: magpie.permissions.Permission) None[source]
permission_deleted(permission: magpie.permissions.Permission) None[source]
abstract resync() None[source]
create_permissions(permissions_data: List[cowbird.typedefs.PermissionConfigItemType]) None[source]

Make sure that the specified permissions exist on Magpie.

create_permission_by_res_id(res_id: int, perm_name: str, perm_access: str, perm_scope: str, user_name: str | None = '', grp_name: str | None = '') pyramid.response.Response | None[source]
create_permission_by_user_and_res_id(user_name: str, res_id: int, perm_name: str, perm_access: str, perm_scope: str) pyramid.response.Response | None[source]
create_permission_by_grp_and_res_id(grp_name: str, res_id: int, perm_name: str, perm_access: str, perm_scope: str) pyramid.response.Response | None[source]
delete_permission_by_user_and_res_id(user_name: str, res_id: int, permission_name: str) None[source]
delete_permission_by_grp_and_res_id(grp_name: str, res_id: int, permission_name: str) None[source]
delete_permission(permissions_data: List[Dict[str, str]]) None[source]

Remove the specified permission from Magpie if it exists.

create_resource(resource_name: str, resource_type: str, parent_id: int | None, resource_display_name: str | None = None) int[source]

Creates the specified resource in Magpie and returns the created resource id if successful.

delete_resource(resource_id: int) None[source]
login() requests.cookies.RequestsCookieJar[source]

Login to Magpie app using admin credentials.

exception cowbird.handlers.impl.magpie.MagpieHttpError[source]

Bases: Exception

Exception related to http requests done by the Magpie handler.

Initialize self. See help(type(self)) for accurate signature.