magpie.services¶
Attributes¶
Classes¶
Initialize the service. |
|
Generic request-to-permission interpretation method of various |
|
Service that represents a |
|
Service that represents basic capabilities of a |
|
Service that represents a |
|
Provides basic configuration parameters and functionalities shared by Geoserver implementations. |
|
Service that represents a Web Map Service endpoint with functionalities specific to Geoserver. |
|
Initialize the service. |
|
Service that provides resources per individual request path segments. |
|
Service that represents a Web Feature Service endpoint. |
|
Service that represents a Web Feature Service endpoint with functionalities specific to Geoserver. |
|
Service that represents a THREDDS Data Server endpoint. |
|
Service that represents a Web Processing Service under a Geoserver instance. |
|
Service that represents a generic REST API under a Geoserver instance. |
|
Service that encapsulates the multiple OWS endpoints from Geoserver services. |
Functions¶
|
Retrieve the specific service class from the provided database service entry. |
|
Verifies if the specified resource allows nesting children resources under it considering its specific type. |
|
Invalidates any caching reference to the specified service name. |
Module Contents¶
- class magpie.services.ServiceMeta[source]¶
Bases:
type- property resource_types: List[Type[magpie.models.Resource]][source]¶
Allowed resources type classes under the service.
- property resource_type_names: List[magpie.typedefs.Str][source]¶
Allowed resources type names under the service.
- property child_resource_allowed: bool[source]¶
Lists all resources allowed somewhere within its resource hierarchy under the service.
Note
Resources are not necessarily all allowed directly under the service. This depends on whether
ServiceInterface.child_structure_allowedis defined or not. If not defined, resources are applicable anywhere. Otherwise, they must respect the explicit structure definitions.See also
Use
ServiceInterface.nested_resource_allowed()to obtain only scoped types allowed under a given resource considering allowed path structures.
- class magpie.services.ServiceInterface(service: magpie.models.Service, request: pyramid.request.Request | None)[source]¶
Bases:
objectInitialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- property service_type: magpie.typedefs.Str | None[source]¶
- Abstractmethod:
Service type identifier (required, unique across implementation).
- permissions: List[magpie.permissions.Permission] = [][source]¶
Permission allowed directly on the service as top-level resource.
- resource_types_permissions: magpie.typedefs.ResourceTypePermissions[source]¶
Mapping of resource types to lists of permissions defining allowed children resource permissions under the service.
- child_structure_allowed: Dict[Type[magpie.typedefs.ServiceOrResourceType], List[Type[magpie.models.Resource]]][source]¶
Control mapping of resource types limiting the allowed structure of nested children resources.
When not defined, any nested resource type combination is allowed if they themselves allow children resources. Otherwise, nested child resource under the service can only be created at specific positions within the hierarchy that matches exactly one of the defined control conditions.
For example, the below definition allows only resources typed
routedirectly under the service. The following nested resource under that first-levelroutecan then be either anotherroutefollowed by a childprocessor directly aprocess. Becauseprocesstype doesn’t allow any children resource (seemodels.Process.child_resource_allowed), those are the only allowed combinations (cannot further nest resources under the finalprocessresource).child_structure_allowed = { models.Service: [models.Route], models.Route: [models.Route, models.Process], models.Process: [], }
See also
Validation of allowed nested children resource insertion of a given type under a parent resource is provided by
ServiceInterface.validate_nested_resource_type()that employschild_structure_allowed.Listing of allowed resource types scoped under a given child resource within the hierarchy is provided by
ServiceInterface.nested_resource_allowed().
- service: magpie.models.Service[source]¶
- _flag_acl_cached: Dict[Tuple[magpie.typedefs.Str, magpie.typedefs.Str, magpie.typedefs.Str, int | None], bool][source]¶
- abstract permission_requested() magpie.typedefs.PermissionRequested[source]¶
Defines how to interpret the incoming request into
Permissiondefinitions for the given service.Each service must implement its own definition. The method must specifically define how to convert generic request path, query, etc. elements into permissions that match the service and its children resources.
If
Noneis returned, the ACL will effectively be resolved to denied access. Otherwise, one or more returnedPermissionwill indicate which permissions should be looked for to resolve the ACL of the authenticated user and its groups.If the request cannot be parsed for any reason to retrieve needed parameters (e.g.: Bad Request), the :exception:`HTTPBadRequest` can be raised to indicate specifically the cause, which will help
magpie.adapter.magpieowssecurity.MagpieOWSSecuritycreate a better response with the relevant error details.
- abstract resource_requested() magpie.typedefs.MultiResourceRequested[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- property __acl__: magpie.typedefs.AccessControlListType[source]¶
Access Control List (ACL) formed of ACE defining combinations rules to grant or refuse access.
Each ACE is defined as
(outcome, user/group, permission)tuples. Called by the configured Pyramidpyramid.authorization.ACLAuthorizationPolicy.Caching is automatically handled according to configured application settings and whether the specific ACL combination being requested was already processed recently.
- _get_acl_cached(service_name: magpie.typedefs.Str, request_method: magpie.typedefs.Str, request_path: magpie.typedefs.Str, user_id: int | None) magpie.typedefs.AccessControlListType[source]¶
Cache this method with
beakerbased on the provided caching key parameters.If the cache is not hit (expired timeout or new key entry), calls
ServiceInterface.get_acl()to retrieve effective permissions of the requested resource and specific permission for the applicable service and user executing the request.Note
Function arguments are required to generate caching keys by which cached elements will be retrieved. Actual arguments are not needed as we employ stored objects in the instance.
Warning
Anything within this method or any underlying calls that can potentially retrieve database contents, whether for direct object or dynamically generated relationships (eg:
user.groups) must attempt to reestablish any detached or invalid session/transaction due to the potentially desynchronized references between objects before/after both incomingserviceand thisaclcache regions.
- _get_acl(user: magpie.models.User, resources: magpie.typedefs.MultiResourceRequested, permissions: Collection[magpie.permissions.Permission]) magpie.typedefs.AccessControlListType[source]¶
Resolves resource-tree and user/group inherited permissions into simplified ACL of requested resources.
Contrary to
effective_permissions()that can be resolved only for individual Resource, ACL is involved during actual request access, which could refer to multiple Resource references or distinct Permission names if the identified parent Service supports it.When more than one item is specified for validation (any combination of Resource or Permission), ALL of them must be granted access to resolve as
Access.ALLOW. Any denied access blocks the whole set of requested elements.See also
Core Permission resolution rules of a single Resource using
effective_permissions().Support of multi-Resource references defined by returned values of
resource_requested()for individualServiceInterfaceimplementations.
- _get_connected_object(obj: magpie.typedefs.ServiceOrResourceType | magpie.models.User) magpie.typedefs.ServiceOrResourceType | None[source]¶
Retrieve the object with an active session and attached state by refreshing connection with request session.
This operation is required mostly in cases of mismatching references between cached and active objects obtained according to timing of requests and whether caching took placed between them, and for different caching region levels (service, ACL or both). It also attempts to correct and encountered problems due to concurrent requests.
- _get_request_path_parts() List[magpie.typedefs.Str] | None[source]¶
Obtain the
requestpath parts stripped of anything prior to the referencedservicename.
- get_config() magpie.typedefs.ServiceConfiguration[source]¶
Obtains the custom configuration of the registered service.
- classmethod get_resource_permissions(resource_type_name: magpie.typedefs.Str) List[magpie.permissions.Permission][source]¶
Obtains the allowed permissions of the service’s child resource fetched by resource type name.
- classmethod validate_nested_resource_type(parent_resource: magpie.typedefs.ServiceOrResourceType, child_resource_type: magpie.typedefs.Str) bool[source]¶
Validate whether a new child resource type is allowed under the parent resource under the service.
- Parameters:
parent_resource – Parent under which the new resource must be validated. This can be the service itself.
child_resource_type – Type to validate at the position defined under the parent resource.
- Returns:
status indicating if insertion is allowed for this type and at this parent position.
- classmethod nested_resource_allowed(parent_resource: magpie.typedefs.ServiceOrResourceType) List[Type[magpie.models.Resource]][source]¶
Obtain the nested resource types allowed as children resource within structure definitions.
- allowed_permissions(resource: magpie.typedefs.ServiceOrResourceType) List[magpie.permissions.Permission][source]¶
Obtains the allowed permissions for or under the service according to provided service or resource.
- effective_permissions(user: magpie.models.User, resource: magpie.typedefs.ServiceOrResourceType, permissions: Collection[magpie.permissions.Permission] | None = None, allow_match: bool = True) List[magpie.permissions.PermissionSet][source]¶
Obtains the Effective Resolution of permissions the user has over the specified resource.
Recursively rewinds the resource tree from the specified resource up to the top-most parent service the resource resides under (or directly if the resource is the service) and retrieve permissions along the way that should be applied to children when using scoped-resource inheritance. Rewinding of the tree can terminate earlier when permissions can be immediately resolved such as when more restrictive conditions enforce denied access.
Both user and group permission inheritance is resolved simultaneously to tree hierarchy with corresponding allow and deny conditions. User Direct Permissions have priority over all its groups Inherited Permissions, and denied permissions have priority over allowed access ones.
All applicable permissions on the resource (as defined by
allowed_permissions()) will have their resolution (Allow/Deny) provided as output, unless a specific subset of permissions is requested usingpermissions. Other permissions are ignored in this case to only resolve requested ones. For example, this parameter can be used to request only ACL resolution from specific permissions applicable for a given request, as obtained bypermission_requested().Permissions scoped as match can be ignored using
allow_match, such as when the targeted resource does not exist.- Parameters:
user – User for which to perform Effective Resolution.
resource – Resource onto which access must be resolved.
permissions – List of Permission for which to perform the resolution.
allow_match – Indicate if the specific Resource was matched to allow
Scope.MATCHhandling.
- Returns:
Resolved set Effective Permission for specified parameter combinations.
- class magpie.services.ServiceOWS(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceInterfaceGeneric request-to-permission interpretation method of various
OGC Web Service(OWS) implementations.Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- params_expected: List[magpie.typedefs.Str] = [][source]¶
Request query parameters that are expected and should be preprocessed by parsing the submitted request.
- abstract resource_requested() magpie.typedefs.MultiResourceRequested[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- permission_requested() magpie.typedefs.PermissionRequested[source]¶
Defines how to interpret the incoming request into
Permissiondefinitions for the given service.Each service must implement its own definition. The method must specifically define how to convert generic request path, query, etc. elements into permissions that match the service and its children resources.
If
Noneis returned, the ACL will effectively be resolved to denied access. Otherwise, one or more returnedPermissionwill indicate which permissions should be looked for to resolve the ACL of the authenticated user and its groups.If the request cannot be parsed for any reason to retrieve needed parameters (e.g.: Bad Request), the :exception:`HTTPBadRequest` can be raised to indicate specifically the cause, which will help
magpie.adapter.magpieowssecurity.MagpieOWSSecuritycreate a better response with the relevant error details.
- class magpie.services.ServiceWPS(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceOWSService that represents a
Web Processing Serviceendpoint.Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- params_expected = ['service', 'request', 'version', 'identifier'][source]¶
Request query parameters that are expected and should be preprocessed by parsing the submitted request.
- resource_types_permissions[source]¶
Mapping of resource types to lists of permissions defining allowed children resource permissions under the service.
- resource_requested() Tuple[magpie.typedefs.ServiceOrResourceType, bool] | None[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- class magpie.services.ServiceBaseWMS(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceOWSService that represents basic capabilities of a
Web Map Serviceendpoint.See also
https://www.ogc.org/standards/wms (OpenGIS WMS 1.3.0 implementation)
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- abstract resource_requested()[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- class magpie.services.ServiceNCWMS2(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceBaseWMSService that represents a
Web Map Serviceendpoint with functionalities specific toncWMS2.Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- resource_types_permissions[source]¶
Mapping of resource types to lists of permissions defining allowed children resource permissions under the service.
- resource_requested() Tuple[magpie.typedefs.ServiceOrResourceType, bool] | None[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- class magpie.services.ServiceGeoserverBase(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceOWSProvides basic configuration parameters and functionalities shared by Geoserver implementations.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- property service_base: magpie.typedefs.Str[source]¶
- Abstractmethod:
Name of the base OWS functionality serviced by Geoserver.
- property resource_scoped: bool[source]¶
- Classmethod:
- Abstractmethod:
Indicates if the Service is allowed to employ scoped
models.Workspacenaming.When allowed, the
models.Workspacecan be inferred from the request parameter defined byresource_paramto retrieve scoped name as<WORKSPACE>:<RESOURCE>. When not allowed, the resource name is left untouched and Magpie will not attempt to infer anymodels.Workspacefrom it. In that case,models.Workspacecan only be specified in the request path for isolated Resource references.Note
When this parameter is
Falsefor a given Service implementation, children Resources can still be named in a similar<namespace>:<element>fashion. The only distinction is that the full Resource should include this complete definition instead of nesting<namespace>and<element>into two distinct Resources.
- property resource_multi: bool[source]¶
- Abstractmethod:
Indicates if the Service supports multiple simultaneous Resource references.
When supported, the value retrieved from
resource_paramcan be comma-separated to represent multiple Resource of the same nature, which can all be retrieved with the same request. Otherwise, single value only is considered by default.Note
Permission modifier
Access.ALLOWwill have to be resolved for all those Resource references for the request to be granted access.
- property resource_param: magpie.typedefs.Str | List[magpie.typedefs.Str][source]¶
- Abstractmethod:
Name of the request query parameter(s) to access requested leaf children resource.
If a single string is defined, the parameter must be equal to this value (case insensitive). When using a list, any specified name combination will be resolved as the same parameter.
Note
The resulting parameter(s) are automatically added to
params_expected()to ensure they are always retrieved in theparserfrom the request query parameters.See also
resource_param_requested()to obtain the resolved parameter considering any applicable combination.
- property resource_types_permissions: magpie.typedefs.ResourceTypePermissions[source]¶
- Abstractmethod:
Explicit permissions provided for resources for a given OWS implementation.
- property params_expected: List[magpie.typedefs.Str][source]¶
Specify typical Geoserver request query parameters expected for any sub-service implementation.
The
resource_paramis also added to ensure it is always parsed based on the derived implementation.
- class magpie.services.ServiceGeoserverWMS(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceGeoserverBase,ServiceBaseWMSService that represents a Web Map Service endpoint with functionalities specific to Geoserver.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- service_type = 'geoserverwms'[source]¶
Service type identifier (required, unique across implementation).
- resource_scoped = True[source]¶
Indicates if the Service is allowed to employ scoped
models.Workspacenaming.When allowed, the
models.Workspacecan be inferred from the request parameter defined byresource_paramto retrieve scoped name as<WORKSPACE>:<RESOURCE>. When not allowed, the resource name is left untouched and Magpie will not attempt to infer anymodels.Workspacefrom it. In that case,models.Workspacecan only be specified in the request path for isolated Resource references.Note
When this parameter is
Falsefor a given Service implementation, children Resources can still be named in a similar<namespace>:<element>fashion. The only distinction is that the full Resource should include this complete definition instead of nesting<namespace>and<element>into two distinct Resources.
- resource_multi = True[source]¶
Indicates if the Service supports multiple simultaneous Resource references.
When supported, the value retrieved from
resource_paramcan be comma-separated to represent multiple Resource of the same nature, which can all be retrieved with the same request. Otherwise, single value only is considered by default.Note
Permission modifier
Access.ALLOWwill have to be resolved for all those Resource references for the request to be granted access.
- resource_param = 'layers'[source]¶
Name of the request query parameter(s) to access requested leaf children resource.
If a single string is defined, the parameter must be equal to this value (case insensitive). When using a list, any specified name combination will be resolved as the same parameter.
Note
The resulting parameter(s) are automatically added to
params_expected()to ensure they are always retrieved in theparserfrom the request query parameters.See also
resource_param_requested()to obtain the resolved parameter considering any applicable combination.
- child_structure_allowed[source]¶
Control mapping of resource types limiting the allowed structure of nested children resources.
When not defined, any nested resource type combination is allowed if they themselves allow children resources. Otherwise, nested child resource under the service can only be created at specific positions within the hierarchy that matches exactly one of the defined control conditions.
For example, the below definition allows only resources typed
routedirectly under the service. The following nested resource under that first-levelroutecan then be either anotherroutefollowed by a childprocessor directly aprocess. Becauseprocesstype doesn’t allow any children resource (seemodels.Process.child_resource_allowed), those are the only allowed combinations (cannot further nest resources under the finalprocessresource).child_structure_allowed = { models.Service: [models.Route], models.Route: [models.Route, models.Process], models.Process: [], }
See also
Validation of allowed nested children resource insertion of a given type under a parent resource is provided by
ServiceInterface.validate_nested_resource_type()that employschild_structure_allowed.Listing of allowed resource types scoped under a given child resource within the hierarchy is provided by
ServiceInterface.nested_resource_allowed().
- class magpie.services.ServiceAccess(service: magpie.models.Service, request: pyramid.request.Request | None)[source]¶
Bases:
ServiceInterfaceInitialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- resource_types_permissions[source]¶
Mapping of resource types to lists of permissions defining allowed children resource permissions under the service.
- resource_requested() magpie.typedefs.TargetResourceRequested[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- permission_requested() magpie.typedefs.PermissionRequested[source]¶
Defines how to interpret the incoming request into
Permissiondefinitions for the given service.Each service must implement its own definition. The method must specifically define how to convert generic request path, query, etc. elements into permissions that match the service and its children resources.
If
Noneis returned, the ACL will effectively be resolved to denied access. Otherwise, one or more returnedPermissionwill indicate which permissions should be looked for to resolve the ACL of the authenticated user and its groups.If the request cannot be parsed for any reason to retrieve needed parameters (e.g.: Bad Request), the :exception:`HTTPBadRequest` can be raised to indicate specifically the cause, which will help
magpie.adapter.magpieowssecurity.MagpieOWSSecuritycreate a better response with the relevant error details.
- class magpie.services.ServiceAPI(service: magpie.models.Service, request: pyramid.request.Request | None)[source]¶
Bases:
ServiceInterfaceService that provides resources per individual request path segments.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- resource_types_permissions[source]¶
Mapping of resource types to lists of permissions defining allowed children resource permissions under the service.
- child_structure_allowed[source]¶
Control mapping of resource types limiting the allowed structure of nested children resources.
When not defined, any nested resource type combination is allowed if they themselves allow children resources. Otherwise, nested child resource under the service can only be created at specific positions within the hierarchy that matches exactly one of the defined control conditions.
For example, the below definition allows only resources typed
routedirectly under the service. The following nested resource under that first-levelroutecan then be either anotherroutefollowed by a childprocessor directly aprocess. Becauseprocesstype doesn’t allow any children resource (seemodels.Process.child_resource_allowed), those are the only allowed combinations (cannot further nest resources under the finalprocessresource).child_structure_allowed = { models.Service: [models.Route], models.Route: [models.Route, models.Process], models.Process: [], }
See also
Validation of allowed nested children resource insertion of a given type under a parent resource is provided by
ServiceInterface.validate_nested_resource_type()that employschild_structure_allowed.Listing of allowed resource types scoped under a given child resource within the hierarchy is provided by
ServiceInterface.nested_resource_allowed().
- resource_requested() magpie.typedefs.TargetResourceRequested[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- permission_requested() magpie.typedefs.PermissionRequested[source]¶
Defines how to interpret the incoming request into
Permissiondefinitions for the given service.Each service must implement its own definition. The method must specifically define how to convert generic request path, query, etc. elements into permissions that match the service and its children resources.
If
Noneis returned, the ACL will effectively be resolved to denied access. Otherwise, one or more returnedPermissionwill indicate which permissions should be looked for to resolve the ACL of the authenticated user and its groups.If the request cannot be parsed for any reason to retrieve needed parameters (e.g.: Bad Request), the :exception:`HTTPBadRequest` can be raised to indicate specifically the cause, which will help
magpie.adapter.magpieowssecurity.MagpieOWSSecuritycreate a better response with the relevant error details.
- class magpie.services.ServiceWFS(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceOWSService that represents a Web Feature Service endpoint.
See also
https://www.ogc.org/standards/wfs (OpenGIS WFS 2.0.0 implementation)
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- params_expected = ['service', 'request', 'version', 'typenames'][source]¶
Request query parameters that are expected and should be preprocessed by parsing the submitted request.
- resource_types_permissions[source]¶
Mapping of resource types to lists of permissions defining allowed children resource permissions under the service.
- resource_requested() magpie.typedefs.TargetResourceRequested[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- class magpie.services.ServiceGeoserverWFS(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceGeoserverBase,ServiceWFSService that represents a Web Feature Service endpoint with functionalities specific to Geoserver.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- service_type = 'geoserverwfs'[source]¶
Service type identifier (required, unique across implementation).
- resource_scoped = True[source]¶
Indicates if the Service is allowed to employ scoped
models.Workspacenaming.When allowed, the
models.Workspacecan be inferred from the request parameter defined byresource_paramto retrieve scoped name as<WORKSPACE>:<RESOURCE>. When not allowed, the resource name is left untouched and Magpie will not attempt to infer anymodels.Workspacefrom it. In that case,models.Workspacecan only be specified in the request path for isolated Resource references.Note
When this parameter is
Falsefor a given Service implementation, children Resources can still be named in a similar<namespace>:<element>fashion. The only distinction is that the full Resource should include this complete definition instead of nesting<namespace>and<element>into two distinct Resources.
- resource_multi = True[source]¶
Indicates if the Service supports multiple simultaneous Resource references.
When supported, the value retrieved from
resource_paramcan be comma-separated to represent multiple Resource of the same nature, which can all be retrieved with the same request. Otherwise, single value only is considered by default.Note
Permission modifier
Access.ALLOWwill have to be resolved for all those Resource references for the request to be granted access.
- resource_param = ['typenames', 'typename'][source]¶
Name of the request query parameter(s) to access requested leaf children resource.
If a single string is defined, the parameter must be equal to this value (case insensitive). When using a list, any specified name combination will be resolved as the same parameter.
Note
The resulting parameter(s) are automatically added to
params_expected()to ensure they are always retrieved in theparserfrom the request query parameters.See also
resource_param_requested()to obtain the resolved parameter considering any applicable combination.
- resource_types_permissions[source]¶
Explicit permissions provided for resources for a given OWS implementation.
- child_structure_allowed[source]¶
Control mapping of resource types limiting the allowed structure of nested children resources.
When not defined, any nested resource type combination is allowed if they themselves allow children resources. Otherwise, nested child resource under the service can only be created at specific positions within the hierarchy that matches exactly one of the defined control conditions.
For example, the below definition allows only resources typed
routedirectly under the service. The following nested resource under that first-levelroutecan then be either anotherroutefollowed by a childprocessor directly aprocess. Becauseprocesstype doesn’t allow any children resource (seemodels.Process.child_resource_allowed), those are the only allowed combinations (cannot further nest resources under the finalprocessresource).child_structure_allowed = { models.Service: [models.Route], models.Route: [models.Route, models.Process], models.Process: [], }
See also
Validation of allowed nested children resource insertion of a given type under a parent resource is provided by
ServiceInterface.validate_nested_resource_type()that employschild_structure_allowed.Listing of allowed resource types scoped under a given child resource within the hierarchy is provided by
ServiceInterface.nested_resource_allowed().
- class magpie.services.ServiceTHREDDS(service: magpie.models.Service, request: pyramid.request.Request | None)[source]¶
Bases:
ServiceInterfaceService that represents a THREDDS Data Server endpoint.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- resource_types_permissions[source]¶
Mapping of resource types to lists of permissions defining allowed children resource permissions under the service.
- child_structure_allowed[source]¶
Control mapping of resource types limiting the allowed structure of nested children resources.
When not defined, any nested resource type combination is allowed if they themselves allow children resources. Otherwise, nested child resource under the service can only be created at specific positions within the hierarchy that matches exactly one of the defined control conditions.
For example, the below definition allows only resources typed
routedirectly under the service. The following nested resource under that first-levelroutecan then be either anotherroutefollowed by a childprocessor directly aprocess. Becauseprocesstype doesn’t allow any children resource (seemodels.Process.child_resource_allowed), those are the only allowed combinations (cannot further nest resources under the finalprocessresource).child_structure_allowed = { models.Service: [models.Route], models.Route: [models.Route, models.Process], models.Process: [], }
See also
Validation of allowed nested children resource insertion of a given type under a parent resource is provided by
ServiceInterface.validate_nested_resource_type()that employschild_structure_allowed.Listing of allowed resource types scoped under a given child resource within the hierarchy is provided by
ServiceInterface.nested_resource_allowed().
- get_config() magpie.typedefs.ServiceConfiguration[source]¶
Obtains the custom configuration of the registered service.
- _get_path_prefix_permission(path_parts: List[str]) Tuple[magpie.typedefs.Str | None, magpie.typedefs.PermissionRequested][source]¶
- static is_match(value: magpie.typedefs.Str, pattern: magpie.typedefs.Str) magpie.typedefs.Str | None[source]¶
- resource_requested() magpie.typedefs.TargetResourceRequested[source]¶
Defines how to interpret the incoming request into the targeted
model.Resourcefor the given service.Each service must implement its own definition.
The expected return value must be either of the following:
- List<(target-resource, target?)> When multiple resources need validation ('target?' as below for each). - (target-resource, True) when the exact resource is found according to request parsing. - (parent-resource, False) when any parent of the resource is found according to request parsing. - None when invalid request or not found resource.The
parent-resourceshould indicate the closest higher-level resource in the hierarchy that would nest the otherwise desiredtarget-resource. The idea behind this is that Magpie will be able to resolve the effective recursive scoped permission even if not all corresponding resources were explicitly defined in the database.For example, if the request would be interpreted with the following hierarchy after service-specific resolution:
ServiceA Resource1 <== closest *existing* parent resource [Resource2] <== target (according to service/request resolution), but not existing in database
A permission defined as Allow/Recursive on
Resource1should normally allow access toResource2. IfResource2is not present in the database though, it cannot be looked for, and the corresponding ACL cannot be generated. Because the (real) protected service using Magpie can have a large and dynamic hierarchy, it is not convenient to enforce perpetual sync between it and its resource representation in Magpie. Using(parent-resource, False)will allow resolution of permission from the closest available parent.Note
In case of
parent-resourcereturned, only recursive-scoped permissions will be considered, since the missingtarget-resourceis the only one that should be checked for match-scoped permissions. For this reason, the service-specific implementation should preferably return the explicit target resource whenever possible.If the returned resource is
None, the ACL will effectively be resolved to denied access. This can be used to indicate failure to retrieve the expected resource or that corresponding resource does not exist. Otherwise, this method implementation should convert any request path, query parameters, etc. into an existing resource.If a list of
(target-resource, target?)is returned, all of those resources should individually perform Effective Resolution and should ALL simultaneously be granted access to let the request through. This can be used to resolve ambiguous or equivalent parameter combinations from parsing the request, or to validate access to parameters that allow multi-resource references using some kind of list value representation.See also
_get_acl()for Effective Resolution of over multiple Resource references.effective_permissions()for Effective Resolution of a single Resource.
- Returns:
One or many tuple of reference resource (target/parent), and explicit match status of the corresponding resource (True/False)
- permission_requested() magpie.typedefs.PermissionRequested[source]¶
Defines how to interpret the incoming request into
Permissiondefinitions for the given service.Each service must implement its own definition. The method must specifically define how to convert generic request path, query, etc. elements into permissions that match the service and its children resources.
If
Noneis returned, the ACL will effectively be resolved to denied access. Otherwise, one or more returnedPermissionwill indicate which permissions should be looked for to resolve the ACL of the authenticated user and its groups.If the request cannot be parsed for any reason to retrieve needed parameters (e.g.: Bad Request), the :exception:`HTTPBadRequest` can be raised to indicate specifically the cause, which will help
magpie.adapter.magpieowssecurity.MagpieOWSSecuritycreate a better response with the relevant error details.
- class magpie.services.ServiceGeoserverWPS(service: magpie.models.Service, request: pyramid.request.Request)[source]¶
Bases:
ServiceGeoserverBase,ServiceWPSService that represents a Web Processing Service under a Geoserver instance.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- service_type = 'geoserverwps'[source]¶
Service type identifier (required, unique across implementation).
- resource_scoped = False[source]¶
Indicates if the Service is allowed to employ scoped
models.Workspacenaming.When allowed, the
models.Workspacecan be inferred from the request parameter defined byresource_paramto retrieve scoped name as<WORKSPACE>:<RESOURCE>. When not allowed, the resource name is left untouched and Magpie will not attempt to infer anymodels.Workspacefrom it. In that case,models.Workspacecan only be specified in the request path for isolated Resource references.Note
When this parameter is
Falsefor a given Service implementation, children Resources can still be named in a similar<namespace>:<element>fashion. The only distinction is that the full Resource should include this complete definition instead of nesting<namespace>and<element>into two distinct Resources.
- resource_multi = True[source]¶
Indicates if the Service supports multiple simultaneous Resource references.
When supported, the value retrieved from
resource_paramcan be comma-separated to represent multiple Resource of the same nature, which can all be retrieved with the same request. Otherwise, single value only is considered by default.Note
Permission modifier
Access.ALLOWwill have to be resolved for all those Resource references for the request to be granted access.
- resource_param = 'identifier'[source]¶
Name of the request query parameter(s) to access requested leaf children resource.
If a single string is defined, the parameter must be equal to this value (case insensitive). When using a list, any specified name combination will be resolved as the same parameter.
Note
The resulting parameter(s) are automatically added to
params_expected()to ensure they are always retrieved in theparserfrom the request query parameters.See also
resource_param_requested()to obtain the resolved parameter considering any applicable combination.
- resource_types_permissions[source]¶
Explicit permissions provided for resources for a given OWS implementation.
- child_structure_allowed[source]¶
Control mapping of resource types limiting the allowed structure of nested children resources.
When not defined, any nested resource type combination is allowed if they themselves allow children resources. Otherwise, nested child resource under the service can only be created at specific positions within the hierarchy that matches exactly one of the defined control conditions.
For example, the below definition allows only resources typed
routedirectly under the service. The following nested resource under that first-levelroutecan then be either anotherroutefollowed by a childprocessor directly aprocess. Becauseprocesstype doesn’t allow any children resource (seemodels.Process.child_resource_allowed), those are the only allowed combinations (cannot further nest resources under the finalprocessresource).child_structure_allowed = { models.Service: [models.Route], models.Route: [models.Route, models.Process], models.Process: [], }
See also
Validation of allowed nested children resource insertion of a given type under a parent resource is provided by
ServiceInterface.validate_nested_resource_type()that employschild_structure_allowed.Listing of allowed resource types scoped under a given child resource within the hierarchy is provided by
ServiceInterface.nested_resource_allowed().
- class magpie.services.ServiceGeoserverAPI(service: magpie.models.Service, request: pyramid.request.Request | None)[source]¶
Bases:
ServiceAPI,ServiceGeoserverBaseService that represents a generic REST API under a Geoserver instance.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- service_type = 'geoserverapi'[source]¶
Service type identifier (required, unique across implementation).
- resource_scoped = False[source]¶
Indicates if the Service is allowed to employ scoped
models.Workspacenaming.When allowed, the
models.Workspacecan be inferred from the request parameter defined byresource_paramto retrieve scoped name as<WORKSPACE>:<RESOURCE>. When not allowed, the resource name is left untouched and Magpie will not attempt to infer anymodels.Workspacefrom it. In that case,models.Workspacecan only be specified in the request path for isolated Resource references.Note
When this parameter is
Falsefor a given Service implementation, children Resources can still be named in a similar<namespace>:<element>fashion. The only distinction is that the full Resource should include this complete definition instead of nesting<namespace>and<element>into two distinct Resources.
- resource_multi = False[source]¶
Indicates if the Service supports multiple simultaneous Resource references.
When supported, the value retrieved from
resource_paramcan be comma-separated to represent multiple Resource of the same nature, which can all be retrieved with the same request. Otherwise, single value only is considered by default.Note
Permission modifier
Access.ALLOWwill have to be resolved for all those Resource references for the request to be granted access.
- resource_param = None[source]¶
Name of the request query parameter(s) to access requested leaf children resource.
If a single string is defined, the parameter must be equal to this value (case insensitive). When using a list, any specified name combination will be resolved as the same parameter.
Note
The resulting parameter(s) are automatically added to
params_expected()to ensure they are always retrieved in theparserfrom the request query parameters.See also
resource_param_requested()to obtain the resolved parameter considering any applicable combination.
- class magpie.services.ServiceGeoserver(service: magpie.models.Service, request: pyramid.request.Request | None)[source]¶
Bases:
ServiceGeoserverBaseService that encapsulates the multiple OWS endpoints from Geoserver services.
Initialize the service.
- Parameters:
service – Base service resource that must be handled by this service implementation.
request – Active request to handle requested resources, permissions and effective access. The request can be omitted if basic service definition details are to be retrieved. It is mandatory for any
requestedoreffectivecomponent that should be resolved.
- service_type = 'geoserver'[source]¶
Service type identifier (required, unique across implementation).
- property service_supported: Set[Type[ServiceGeoserverBase]][source]¶
- child_structure_allowed[source]¶
Allowed children resource structure for Geoserver.
Note
In the context of Geoserver, WPS are applied on available resources (WFS, WMS, etc.). For this reason, the
models.Processalso needs to be scoped undermodels.Workspacein order to grant access to those resources to work on them, but themodels.Workspacename MUST be in the path (i.e.:identifier=<WORKSPACE>:<PROCESS_ID>request parameter does not work). Without themodels.Workspacescope in the path,identifierparameter fails to be resolved by Geoserver, as if it was unspecified. AttributeServiceGeoserverWPS.resource_scopedcontrols the behaviour of splitting the definedresource_paramintomodels.Workspaceand child components.Note
The
models.Routeis allowed at the root of the service and for any nestedmodels.Routeresource to support various endpoints such as the/webuser interface, or the REST interface for the new generation of OGC API services typically on/ogc/{features|maps|processes}endpoints. No special logic is applied for the different services nested under those endpoints. All of them are handled as typical RESTful APIs, for which permissions and appropriate sub-paths should be defined accordingly with their respective specifications and schema.
- get_config() magpie.typedefs.ServiceConfiguration[source]¶
Obtain the configuration defining which OWS services are enabled under this instance.
Should provide a mapping of all OWS service type names to enabled boolean status.
- property params_expected: List[magpie.typedefs.Str][source]¶
Specify typical Geoserver request query parameters expected for any sub-service implementation.
The
resource_paramis also added to ensure it is always parsed based on the derived implementation.
- property permissions: List[magpie.permissions.Permission][source]¶
Permission allowed directly on the service as top-level resource.
- property resource_types_permissions: magpie.typedefs.ResourceTypePermissions[source]¶
Explicit permissions provided for resources for a given OWS implementation.
- service_requested() Type[ServiceGeoserverBase] | None[source]¶
Obtain the applicable OWS implementation according to parsed request parameters.
- property resource_scoped: bool[source]¶
Indicates if the Service is allowed to employ scoped
models.Workspacenaming.When allowed, the
models.Workspacecan be inferred from the request parameter defined byresource_paramto retrieve scoped name as<WORKSPACE>:<RESOURCE>. When not allowed, the resource name is left untouched and Magpie will not attempt to infer anymodels.Workspacefrom it. In that case,models.Workspacecan only be specified in the request path for isolated Resource references.Note
When this parameter is
Falsefor a given Service implementation, children Resources can still be named in a similar<namespace>:<element>fashion. The only distinction is that the full Resource should include this complete definition instead of nesting<namespace>and<element>into two distinct Resources.
- property resource_multi: bool[source]¶
Indicates if the Service supports multiple simultaneous Resource references.
When supported, the value retrieved from
resource_paramcan be comma-separated to represent multiple Resource of the same nature, which can all be retrieved with the same request. Otherwise, single value only is considered by default.Note
Permission modifier
Access.ALLOWwill have to be resolved for all those Resource references for the request to be granted access.
- property resource_param: magpie.typedefs.Str | List[magpie.typedefs.Str][source]¶
Name of the request query parameter(s) to access requested leaf children resource.
If a single string is defined, the parameter must be equal to this value (case insensitive). When using a list, any specified name combination will be resolved as the same parameter.
Note
The resulting parameter(s) are automatically added to
params_expected()to ensure they are always retrieved in theparserfrom the request query parameters.See also
resource_param_requested()to obtain the resolved parameter considering any applicable combination.
- resource_requested() magpie.typedefs.MultiResourceRequested[source]¶
Parse the requested resource down to the applicable
models.Workspace.Note
Further child resource processing must be accomplished by the derived implementation as needed.
- permission_requested() magpie.typedefs.PermissionRequested[source]¶
Defines how to interpret the incoming request into
Permissiondefinitions for the given service.Each service must implement its own definition. The method must specifically define how to convert generic request path, query, etc. elements into permissions that match the service and its children resources.
If
Noneis returned, the ACL will effectively be resolved to denied access. Otherwise, one or more returnedPermissionwill indicate which permissions should be looked for to resolve the ACL of the authenticated user and its groups.If the request cannot be parsed for any reason to retrieve needed parameters (e.g.: Bad Request), the :exception:`HTTPBadRequest` can be raised to indicate specifically the cause, which will help
magpie.adapter.magpieowssecurity.MagpieOWSSecuritycreate a better response with the relevant error details.
- magpie.services.service_factory(service: magpie.models.Service, request: pyramid.request.Request) ServiceInterface[source]¶
Retrieve the specific service class from the provided database service entry.
- magpie.services.get_resource_child_allowed(resource: magpie.typedefs.ServiceOrResourceType) bool[source]¶
Verifies if the specified resource allows nesting children resources under it considering its specific type.
Makes sure to obtain the specific
ServiceorResourceimplementation to verify children support. If this is not accomplished, the default attribute of baseServiceorResourcewould erroneously indicate that children are allowed.- Parameters:
resource – Item for which to verify if children resources are allowed.
- Returns:
Whether the resource can nest more resources or not.