magpie.models¶
Attributes¶
Classes¶
Applicable Permission values (names) under certain Service and Resource. |
|
Utility |
|
Enum that allows more permissive name cases for lookup. |
|
Mixin for Group model |
|
Mixin for GroupPermission model |
|
Supported statuses of user-group relationships. |
|
Mixin for UserGroup model |
|
Mixin for GroupResourcePermission model |
|
Mixin for Resource model |
|
Mixin for UserPermission model |
|
Mixin for UserResourcePermission model |
|
Base mixin for User object representation. |
|
Temporary definition of a |
|
Values applicable to User statues. |
|
Extends the |
|
Mixin for External Identity model - it represents oAuth(or other) accounts |
|
Used to build base Access Control List (ACL) of the request user. |
|
Used to build base Access Control List (ACL) of the request user. |
|
Resource of service type. |
|
Resource that represents the leaf node in a file-system-like hierarchy. |
|
Resource that represents an intermediate directory node within a file-system-like hierarchy. |
|
Resource that defines multiple corresponding representations of a layer according to the OWS it lies under. |
|
Resource employed to contain a group of scoped |
|
Resource employed to represent a single request path fragment. |
|
Resource that represents a process under an OWS instance servicing a WPS endpoint. |
|
Basic class that all other classes inherit from that supplies some |
|
Basic class that all other classes inherit from that supplies some |
|
This is necessary, because ResourceTreeServicePostgresSQL.model is the Resource class. If we want to change it for a |
|
Supported operations by the temporary tokens. |
|
Model that defines a token for temporary URL completion of a given pending operation. |
Functions¶
|
Search in order for matched value of |
|
Decompose a |
|
Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when |
|
Obtains the configured Magpie URL entrypoint based on the various combinations of supported configuration settings. |
|
|
|
|
|
Module Contents¶
- magpie.models.get_constant(constant_name: magpie.typedefs.Str, settings_container: magpie.typedefs.AnySettingsContainer | None = None, settings_name: magpie.typedefs.Str | None = None, default_value: magpie.typedefs.SettingValue | None = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) magpie.typedefs.SettingValue[source]¶
- Search in order for matched value of
constant_name: search in
MAGPIE_CONSTANTSsearch in settings if specified
search alternative setting names (see below)
search in
magpie.constantsdefinitionssearch in environment variables
Parameter
constant_nameis expected to have the formatMAGPIE_[VARIABLE_NAME]although any value can be passed to retrieve generic settings from all above-mentioned search locations.If
settings_nameis provided as alternative name, it is used as is to search for results ifconstant_namewas not found. Otherwise,magpie.[variable_name]is used for additional search when the formatMAGPIE_[VARIABLE_NAME]was used forconstant_name(i.e.:MAGPIE_ADMIN_USERwill also search formagpie.admin_userand so on for corresponding constants).- Parameters:
constant_name – key to search for a value
settings_container – WSGI application settings container (if not provided, uses found one in current thread)
settings_name – alternative name for settings if specified
default_value – default value to be returned if not found anywhere, and exception raises are disabled.
raise_not_set – raise an exception if the found key is
None, search until last case if others areNoneraise_missing – raise exception if key is not found anywhere
print_missing – print message if key is not found anywhere, return
Noneempty_missing – consider an empty value for an existing key as if it was missing (i.e.: as if not set).
- Returns:
found value or default_value
- Raises:
ValueError – if resulting value is invalid based on options (by default raise missing/empty/
Nonevalue)LookupError – if no appropriate value could be found from all search locations (according to options)
- Search in order for matched value of
- class magpie.models.Permission[source]¶
Bases:
magpie.utils.ExtendedEnumApplicable Permission values (names) under certain Service and Resource.
- READ = 'read'¶
- WRITE = 'write'¶
- ACCESS = 'access'¶
- BROWSE = 'browse'¶
- GET_CAPABILITIES = 'getcapabilities'¶
- GET_MAP = 'getmap'¶
- GET_FEATURE_INFO = 'getfeatureinfo'¶
- GET_LEGEND_GRAPHIC = 'getlegendgraphic'¶
- GET_METADATA = 'getmetadata'¶
- GET_PROPERTY_VALUE = 'getpropertyvalue'¶
- GET_FEATURE = 'getfeature'¶
- GET_FEATURE_WITH_LOCK = 'getfeaturewithlock'¶
- GET_GML_OBJECT = 'getgmlobject'¶
- DESCRIBE_FEATURE_TYPE = 'describefeaturetype'¶
- DESCRIBE_LAYER = 'describelayer'¶
- DESCRIBE_PROCESS = 'describeprocess'¶
- EXECUTE = 'execute'¶
- LOCK_FEATURE = 'lockfeature'¶
- TRANSACTION = 'transaction'¶
- CREATE_STORED_QUERY = 'createstoredquery'¶
- DROP_STORED_QUERY = 'dropstoredquery'¶
- LIST_STORED_QUERIES = 'liststoredqueries'¶
- DESCRIBE_STORED_QUERIES = 'describestoredqueries'¶
- class magpie.models.ExtendedEnum[source]¶
Bases:
enum.EnumUtility
enum.Enummethods.Create an extended enum with these utilities as follows:
class CustomEnum(ExtendedEnum): ItemA = "A" ItemB = "B"
- classmethod names() List[magpie.typedefs.Str][source]¶
Returns the member names assigned to corresponding enum elements.
- classmethod values() List[magpie.typedefs.AnyKey][source]¶
Returns the literal values assigned to corresponding enum elements.
- classmethod get(key_or_value: magpie.typedefs.AnyKey, default: Any | None = None) _TC | None[source]¶
Finds an enum entry by defined name or its value.
Returns the entry directly if it is already a valid enum.
- classmethod titles() List[magpie.typedefs.Str][source]¶
Returns the title representation of all enum elements.
- property title: magpie.typedefs.Str¶
Returns the title representation of the enum element.
Title use the original enum element name with capitalization considering underscores for separate words.
- class magpie.models.FlexibleNameEnum[source]¶
Bases:
ExtendedEnumEnum that allows more permissive name cases for lookup.
- magpie.models.decompose_enum_flags(enum_flags: enum.Enum) List[enum.Enum][source]¶
Decompose a
Flag-enabledEnuminto its individual parts.The operation is agnostic of the
Enumimplementation, whether from stdlibenumoraenum.
- magpie.models.get_logger(name: magpie.typedefs.Str, level: int | None = None, force_stdout: bool = None, message_format: magpie.typedefs.Str | None = None, datetime_format: magpie.typedefs.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.
- magpie.models.get_magpie_url(container: magpie.typedefs.AnySettingsContainer | None = None) magpie.typedefs.Str[source]¶
Obtains the configured Magpie URL entrypoint based on the various combinations of supported configuration settings.
See also
Documentation section Application Settings for available setting combinations.
- Parameters:
container – container that provides access to application settings.
- Returns:
resolved Magpie URL
- magpie.models.get_session_callable(request: pyramid.request.Request) sqlalchemy.orm.session.Session[source]¶
- class magpie.models.Group[source]¶
Bases:
ziggurat_foundations.models.group.GroupMixin,BaseMixin for Group model
- class magpie.models.GroupPermission[source]¶
Bases:
ziggurat_foundations.models.group_permission.GroupPermissionMixin,BaseMixin for GroupPermission model
- class magpie.models.UserGroupStatus[source]¶
Bases:
magpie.utils.FlexibleNameEnumSupported statuses of user-group relationships.
- class magpie.models.UserGroup[source]¶
Bases:
ziggurat_foundations.models.user_group.UserGroupMixin,BaseMixin for UserGroup model
- class magpie.models.GroupResourcePermission[source]¶
Bases:
ziggurat_foundations.models.group_resource_permission.GroupResourcePermissionMixin,BaseMixin for GroupResourcePermission model
- class magpie.models.Resource[source]¶
Bases:
ziggurat_foundations.models.resource.ResourceMixin,BaseMixin for Resource model
- permissions: List[magpie.permissions.Permission] = [][source]¶
- class magpie.models.UserPermission[source]¶
Bases:
ziggurat_foundations.models.user_permission.UserPermissionMixin,BaseMixin for UserPermission model
- class magpie.models.UserResourcePermission[source]¶
Bases:
ziggurat_foundations.models.user_resource_permission.UserResourcePermissionMixin,BaseMixin for UserResourcePermission model
- class magpie.models.User[source]¶
Bases:
ziggurat_foundations.models.user.UserMixin,BaseBase mixin for User object representation. It supplies all the basic functionality from password hash generation and matching to utility methods used for querying database for users and their permissions or resources they have access to. It is meant to be extended with other application specific properties
- get_groups_by_status(status: UserGroupStatus, db_session: sqlalchemy.orm.session.Session = None) Set[magpie.typedefs.Str][source]¶
List all groups a user belongs to, filtered by UserGroup status type.
- class magpie.models.UserPending[source]¶
Bases:
BaseTemporary definition of a
Userpending for approval by an administrator.- property status[source]¶
- Pending user status is enforced.
Avoid error in case the corresponding attribute of
Userwas accessed.
- property groups[source]¶
- Pending user is not a member of any group.
Avoid error in case this field gets accessed when simultaneously handling
Userand :class`UserPending`.
- get_groups_by_status(status: UserGroupStatus, db_session: sqlalchemy.orm.session.Session = None) List[magpie.typedefs.Str][source]¶
Pending user is not a member of any group.
Avoid error in case this method gets accessed when simultaneously handling
Userand :class`UserPending`.
- upgrade(db_session: sqlalchemy.orm.session.Session | None = None) User[source]¶
Upgrades this :class`UserPending` instance to a complete and corresponding
Userdefinition.Automatically handles instance updates in the database. All relevant
Usermetadata is transferred from availableUserPendingdetails.All operations that should take place during normal
Usercreation will take effect, including minimalGroupmembership creation and Webhook triggers.This current
UserPendinginstance is finally removed and should not be accessed following upgrade.- Parameters:
db_session – Database connection to use, otherwise retrieved from the user pending object.
- Returns:
created user instance
- property passwordmanager[source]¶
- Employ the same password manager attached to :class:`User` instances from :class:`UserService`.
This allows all functionalities of password generation, encryption and comparison to be directly transferable between this pending user until it eventually gets upgraded to a full
Useronce validated.
- class magpie.models.UserStatuses[source]¶
Bases:
enum.IntFlag,magpie.utils.FlexibleNameEnumValues applicable to User statues.
Provides allowed values for the
statussearch query ofUserandUserPendingentries. Also, defines the possible values ofUser.statusfield, omittingUserStatuses.Pendingreserved for objects defined byUserPending.Initialize self. See help(type(self)) for accurate signature.
- classmethod _get_one(status: AnyUserStatus) UserStatuses | None[source]¶
- classmethod get(status: None | int | magpie.typedefs.Str | UserStatuses | Iterable[None, int, magpie.typedefs.Str, UserStatuses], default: UserStatuses | None = None) UserStatuses | None[source]¶
Obtains the combined flag
UserStatuses
- classmethod allowed() List[None | int | magpie.typedefs.Str][source]¶
Returns all supported representation values that can be mapped to a valid status for
UserSearchService.
- classmethod all() UserStatuses[source]¶
Representation of all flags combined.
- __or__(other: UserStatuses | int) UserStatuses[source]¶
Return self|value.
- __and__(other: UserStatuses | int) UserStatuses[source]¶
Return self&value.
- __xor__(other: UserStatuses | int) UserStatuses[source]¶
Return self^value.
- __iter__() Iterable[UserStatuses][source]¶
- class magpie.models.UserSearchService[source]¶
Bases:
ziggurat_foundations.models.services.user.UserServiceExtends the
ziggurat_foundationsUserServicewith additional features provided by Magpie.Note
For any search result where parameter
statusis equal to or containsUserStatuses.Pendingcombined with any otherUserStatusesmembers, or through the all representation, the returned iterable could be a mix of both User models or onlyUserPending. Therefore, only fields supported by both of those models should be accessed from the result.- classmethod by_status(status: UserStatuses | None = None, db_session: sqlalchemy.orm.session.Session | None = None) Iterable[AnyUser][source]¶
Search for appropriate
Userand/orUserPendingaccording to specifiedUserStatuses.When the
statusisNone, normal retrieval of all non-pendingUseris executed, as if directly using theUserServiceimplementation. Otherwise, a combination of appropriate search criterion is executed based on thestatusflags.
- classmethod by_user_name(user_name: magpie.typedefs.Str, status: UserStatuses | None = None, db_session: sqlalchemy.orm.session.Session | None = None) AnyUser | None[source]¶
Retrieves the user matching the given name.
Search is always accomplished against
Usertable unlessUserStatuses.Pendingis provided in thestatus. If more that one status is provided such that bothUserPendingandUsercould yield results, theUseris returned first, as there should not be any conflict between those two models.
- classmethod by_name_or_email(user_name: magpie.typedefs.Str, email: magpie.typedefs.Str, status: UserStatuses | None = None, db_session: sqlalchemy.orm.session.Session | None = None) AnyUser | None[source]¶
Retrieves the first matched user by either name or email, whichever comes first.
If the
statusis provided, search is executed against relevantUserand/or :class`UserPending` definitions. Theuser_nameis looked for first across both tables (as needed) and then byemailif not previously matched.See also
by_user_name()by_email()by_email_and_username()
- class magpie.models.ExternalIdentity[source]¶
Bases:
ziggurat_foundations.models.external_identity.ExternalIdentityMixin,BaseMixin for External Identity model - it represents oAuth(or other) accounts attached to your user object
- class magpie.models.RootFactory(request: pyramid.request.Request)[source]¶
Bases:
objectUsed to build base Access Control List (ACL) of the request user.
All API and UI routes will employ this set of effective principals to determine if the user is authorized to access the pyramid view according to the
permissionvalue it was configured with.Note
Keep in mind that Magpie is configured with default permission
magpie.constants.MAGPIE_ADMIN_PERMISSION. Views that require more permissive authorization must be overridden withpermissionargument.See also
set_default_permissionwithinmagpie.includeme()initialization steps
- class magpie.models.UserFactory(request: pyramid.request.Request)[source]¶
Bases:
RootFactoryUsed to build base Access Control List (ACL) of the request user.
All API and UI routes will employ this set of effective principals to determine if the user is authorized to access the pyramid view according to the
permissionvalue it was configured with.Note
Keep in mind that Magpie is configured with default permission
magpie.constants.MAGPIE_ADMIN_PERMISSION. Views that require more permissive authorization must be overridden withpermissionargument.See also
set_default_permissionwithinmagpie.includeme()initialization steps
- __getitem__(user_name: magpie.typedefs.Str) UserFactory[source]¶
- property __acl__: magpie.typedefs.AccessControlListType[source]¶
Grant access to Request User according to its relationship to Context User.
If it is the same user (either from explicit name or by
magpie.constants.MAGPIE_LOGGED_USERreserved keyword), allowmagpie.constants.MAGPIE_LOGGED_PERMISSIONfor itself to access corresponding views.If request user is unauthenticated (
None),magpie.constants.MAGPIE_LOGGED_USERor itself, also grantmagpie.constants.MAGPIE_CONTEXT_PERMISSIONto allow access to contextually-available details (e.g.: user can view his own information and public ones).All ACL permissions from
RootFactoryare applied on top of user-specific permissions added here.
- class magpie.models.Service[source]¶
Bases:
ResourceResource of service type.
- class magpie.models.File[source]¶
-
Resource that represents the leaf node in a file-system-like hierarchy.
In the context of THREDDS, this represents the corresponding files exposed by the service. This resource cannot have any children resource under it.
- class magpie.models.Directory[source]¶
-
Resource that represents an intermediate directory node within a file-system-like hierarchy.
In the context of THREDDS, this represents the corresponding directories exposed by the service. Any amount of
Directorycan be nested under itself to form the tree hierarchy.
- class magpie.models.Layer[source]¶
Bases:
ResourceResource that defines multiple corresponding representations of a layer according to the OWS it lies under.
In the context of WFS, this is the represented collection of features. In the context of WMS, this is the referenced features employed to generate the map.
- class magpie.models.Workspace[source]¶
Bases:
ResourceResource employed to contain a group of scoped
Layerwithin a Geoserver instance.
- class magpie.models.Route[source]¶
Bases:
ResourceResource employed to represent a single request path fragment.
- class magpie.models.Process[source]¶
Bases:
ResourceResource that represents a process under an OWS instance servicing a WPS endpoint.
- class magpie.models.RemoteResource[source]¶
Bases:
ziggurat_foundations.models.base.BaseModel,BaseBasic class that all other classes inherit from that supplies some basic methods useful for interaction with packages like: deform, colander or wtforms
- class magpie.models.RemoteResourcesSyncInfo[source]¶
Bases:
ziggurat_foundations.models.base.BaseModel,BaseBasic class that all other classes inherit from that supplies some basic methods useful for interaction with packages like: deform, colander or wtforms
- class magpie.models.RemoteResourceTreeService(service_cls)[source]¶
Bases:
ziggurat_foundations.models.services.resource_tree.ResourceTreeService
- class magpie.models.RemoteResourceTreeServicePostgresSQL(service_cls)[source]¶
Bases:
ziggurat_foundations.models.services.resource_tree_postgres.ResourceTreeServicePostgreSQLThis is necessary, because ResourceTreeServicePostgresSQL.model is the Resource class. If we want to change it for a RemoteResource, we need this class.
The ResourceTreeService.__init__ call sets the model.
- class magpie.models.TokenOperation[source]¶
Bases:
magpie.utils.ExtendedEnumSupported operations by the temporary tokens.
- GROUP_ACCEPT_TERMS = 'group-accept-terms'[source]¶
Temporary token associated to an URL endpoint called by a user that accepts the terms and conditions (T&C) to join a particular group.
- USER_PASSWORD_RESET = 'user-password-reset'[source]¶
Temporary token associated to an URL endpoint to request a user password reset.
- USER_REGISTRATION_CONFIRM_EMAIL = 'user-registration-confirm-email'[source]¶
Temporary token associated to a pending user registration that requires email validation by visiting the link.
- USER_REGISTRATION_ADMIN_APPROVE = 'user-registration-admin-approve'[source]¶
Temporary token associated to a pending user registration that will be approved by an administrator when visited.
- class magpie.models.TemporaryToken(*_, **__)[source]¶
Bases:
ziggurat_foundations.models.base.BaseModel,BaseModel that defines a token for temporary URL completion of a given pending operation.
- static by_token(token: magpie.typedefs.Str | sqlalchemy.dialects.postgresql.UUID, db_session: sqlalchemy.orm.session.Session | None = None) TemporaryToken | None[source]¶