magpie.adapter
¶
Package Contents¶
Classes¶
Registry for OWS services. |
|
Functions¶
|
Raises error HTTP with standardized information formatted with content type. |
|
Returns successful HTTP with standardized information formatted with content type. (see |
|
|
|
|
|
Get a |
|
Generates Magpie application configuration with all utilities required for security and access control. |
|
Logs debug information about request cookie. |
|
Obtains the authenticated user from the request (if any). |
|
Verifies that a valid user authentication on the pointed |
-
class
magpie.adapter.
MagpieOWSSecurity
(request)[source]¶ Bases:
twitcher.owssecurity.OWSSecurityInterface
-
check_request
(self, request)¶
Ensure login of the user and update the request cookies if Twitcher is in a special configuration.
Only update if MAGPIE_COOKIE_NAME is missing and is retrievable from access_token in Authorization header. Counter-validate the login procedure by calling Magpie’s /session which should indicated a logged user.
-
-
class
magpie.adapter.
MagpieServiceStore
(: Request, request)[source]¶ Bases:
twitcher.store.ServiceStoreInterface
Registry for OWS services.
Uses magpie to fetch service url and attributes.
-
abstract
save_service
(self, service, overwrite=True, request=None)¶ Magpie store is read-only, use magpie api to add services.
-
abstract
delete_service
(self, name, request=None)¶ Magpie store is read-only, use magpie api to delete services.
-
list_services
(self, request=None)¶ Lists all services registered in magpie.
-
fetch_by_name
(self, name, visibility=None, request=None)¶ Gets service for given
name
from magpie.
-
fetch_by_url
(self, url, request=None)¶ Gets service for given
url
from mongodb storage.
-
abstract
clear_services
(self, request=None)¶ Magpie store is read-only, use magpie api to delete services.
-
abstract
-
magpie.adapter.
raise_http
(http_error: Type[HTTPError] = HTTPInternalServerError, http_kwargs: Optional[ParamsType] = None, detail: Str = '', content: Optional[JSON] = None, content_type: Str = CONTENT_TYPE_JSON, nothrow: bool = False) → NoReturn[source]¶ Raises error HTTP with standardized information formatted with content type.
The content contains the corresponding http error code, the provided message as detail and optional specified additional json content (kwarg dict).
See also
valid_http()
for HTTP successful calls- Parameters
http_error – any derived class from base HTTPError (default: HTTPInternalServerError)
http_kwargs – additional keyword arguments to pass to http_error if called in case of HTTP exception
detail – additional message information (default: empty)
content – json formatted content to include
content_type – format in which to return the exception (one of magpie.common.SUPPORTED_ACCEPT_TYPES)
nothrow – returns the error response instead of raising it automatically, but still handles execution errors
- Raises
HTTPError – formatted raised exception with additional details and HTTP code
- Returns
HTTPError formatted exception with additional details and HTTP code only if nothrow is True
-
magpie.adapter.
valid_http
(http_success: Union[Type[HTTPSuccessful], Type[HTTPRedirection]] = HTTPOk, http_kwargs: Optional[ParamsType] = None, detail: Optional[Str] = '', content: Optional[JSON] = None, content_type: Optional[Str] = CONTENT_TYPE_JSON) → Union[HTTPSuccessful, HTTPRedirection][source]¶ Returns successful HTTP with standardized information formatted with content type. (see
raise_http()
for HTTP error calls)- Parameters
http_success – any derived class from valid HTTP codes (<400) (default: HTTPOk)
http_kwargs – additional keyword arguments to pass to http_success when called
detail – additional message information (default: empty)
content – json formatted content to include
content_type – format in which to return the exception (one of magpie.common.SUPPORTED_ACCEPT_TYPES)
- Returns
formatted successful response with additional details and HTTP code
-
magpie.adapter.
get_engine
(container: Optional[AnySettingsContainer] = None, prefix: Str = 'sqlalchemy.', **kwargs: Any) → Engine[source]¶
-
magpie.adapter.
get_tm_session
(session_factory, transaction_manager)[source]¶ Get a
sqlalchemy.orm.Session
instance backed by a transaction.This function will hook the session to the transaction manager which will take care of committing any changes.
When using pyramid_tm it will automatically be committed or aborted depending on whether an exception is raised.
When using scripts you should wrap the session in a manager yourself. For example:
import transaction engine = get_engine(settings) session_factory = get_session_factory(engine) with transaction.manager: db_session = get_tm_session(session_factory, transaction.manager)
-
magpie.adapter.
get_auth_config
(container: AnySettingsContainer) → Configurator[source]¶ Generates Magpie application configuration with all utilities required for security and access control.
Logs debug information about request cookie.
Warning
This function is intended for debugging purposes only. It reveals sensible configuration information.
Re-implements basic functionality of
pyramid.AuthTktAuthenticationPolicy.cookie.identify()
called viarequest.unauthenticated_userid()
withinget_user()
to provide additional logging.See also
pyramid.authentication.AuthTktCookieHelper
pyramid.authentication.AuthTktAuthenticationPolicy
-
magpie.adapter.
get_user
(request: Request) → Optional[User][source]¶ Obtains the authenticated user from the request (if any).
- Parameters
request – incoming HTTP request potentially containing authentication definitions.
- Returns
the authenticated user if parameters were valid (good credentials, not expired, etc.) or
None
.
-
magpie.adapter.
verify_user
(request: Request) → HTTPException[source]¶ Verifies that a valid user authentication on the pointed
Magpie
instance (via configuration) also results into a valid user authentication with the currentTwitcher
instance to ensure settings match between them.- Parameters
request – an HTTP request with valid authentication token/cookie credentials.
- Returns
appropriate HTTP success or error response with details about the result.