utils package
Submodules
utils.authentication module
Module containing a custom OAuth2 authentication class.
- class utils.authentication.GPFOAuth2Authentication[source]
Bases:
OAuth2AuthenticationProvide custom OAuth2 authentication.
This authentication class that will return a 401 error in the case that an invalid OAuth token has been provided. We need this behaviour as we have routes which will allow unauthenticated requests, which in turn prevents distinguishing requests with expired tokens from those that bear no authentication headers.
- class utils.authentication.ReadOnlyDBAuthentication[source]
Bases:
BaseAuthenticationAuthentication class intended to be used as a safeguard when we want the database to be read-only.
This is designed to be used when we want to migrate the production instance soon, and want to ensure that the database state is frozen, so that no new data can be missed during the migration.
- class utils.authentication.SessionAuthenticationWithUnauthenticatedCSRF[source]
Bases:
SessionAuthenticationSession authentication with unauthenticated CSRF.
utils.cached_response module
In-process memoization of pre-rendered JSON responses.
GET endpoints that serialize large, instance-static payloads (e.g.
the genomic scores registry with all of its histograms) are expensive
to re-render on every request even though the result only changes when
the GPF instance is reloaded.
This module memoizes the rendered JSON bytes keyed by the instance id
and the instance-load timestamp, so the serialization runs once per
instance load. The helper is designed to compose under the existing
etag(get_instance_timestamp_etag) decorator: that decorator handles
conditional 304 short-circuiting before the view body runs, so the
build function here only ever executes for a 200.
- utils.cached_response.cached_json_response(instance_id: str, build: Callable[[], Any], *extra: Any) HttpResponse[source]
Return a cached
application/jsonresponse.The rendered body is memoized in-process keyed by
(instance_id, get_instance_timestamp(), extra). Includinginstance_idprevents cross-fixture leakage in tests;extracarries any view-varying parameter (e.g. an optional path segment).The response carries
Cache-Control: public, max-age=3600.
utils.datasets module
utils.email_regex module
utils.expand_gene_set module
utils.gene_sets module
utils.logger module
- utils.logger.log_filter(request: Request | WSGIRequest, message: str, *args: Any) str[source]
Filter request info for logging.
utils.pagination module
utils.password_requirements module
utils.query_params module
utils.streaming_response_util module
utils.testing module
- utils.testing.setup_t4c8_instance(root_path: Path) GPFInstance[source]