galaxy.webapps.base package

Submodules

galaxy.webapps.base.api module

class galaxy.webapps.base.api.GalaxyFileResponse(path: str | os.PathLike[str], status_code: int = 200, headers: Mapping[str, str] | None = None, media_type: str | None = None, background: BackgroundTask | None = None, filename: str | None = None, stat_result: stat_result | None = None, method: str | None = None, content_disposition_type: str = 'attachment')[source]

Bases: FileResponse

Augments starlette FileResponse with x-accel-redirect/x-sendfile and byte-range handling.

nginx_x_accel_redirect_base: str | None = None
apache_xsendfile: bool | None = None
__init__(path: str | os.PathLike[str], status_code: int = 200, headers: Mapping[str, str] | None = None, media_type: str | None = None, background: BackgroundTask | None = None, filename: str | None = None, stat_result: stat_result | None = None, method: str | None = None, content_disposition_type: str = 'attachment') None[source]
galaxy.webapps.base.api.add_sentry_middleware(app: FastAPI) None[source]
galaxy.webapps.base.api.get_error_response_for_request(request: Request, exc: MessageException) JSONResponse[source]
galaxy.webapps.base.api.add_exception_handler(app: FastAPI) None[source]
class galaxy.webapps.base.api.AccessLoggingMiddleware[source]

Bases: Plugin

key: str = 'access_line'
async process_request(request)[source]

Runs always on request.

Extracts value from header by default.

async enrich_response(response) None[source]

Runs always on response.

Does nothing by default.

galaxy.webapps.base.api.add_raw_context_middlewares(app: FastAPI)[source]
galaxy.webapps.base.api.add_request_id_middleware(app: FastAPI)[source]
galaxy.webapps.base.api.include_all_package_routers(app: FastAPI, package_name: str)[source]

galaxy.webapps.base.controller module

Contains functionality needed in every web interface

exception galaxy.webapps.base.controller.HTTPBadRequest(detail=None, headers=None, comment=None, body_template=None, json_formatter=None, **kw)[source]

Bases: HTTPClientError, HTTPBadRequest

explanation = 'The server could not comply with the request since it is either malformed or otherwise incorrect.'
class galaxy.webapps.base.controller.SharableMixin[source]

Bases: object

Mixin for a controller that manages an item that can be shared.

manager: Any = None
serializer: Any = None
slug_builder = <galaxy.managers.sharable.SlugBuilder object>
set_slug_async(trans, id, new_slug)[source]
share(trans, id=None, email='', **kwd)[source]

Handle sharing an item with a particular user.

display_by_username_and_slug(trans, username, slug, **kwargs)[source]

Display item by username and slug.

get_item(trans, id)[source]

Return item based on id.

galaxy.webapps.base.controller.sort_by_attr(seq, attr)[source]

Sort the sequence of objects by object’s attribute Arguments: seq - the list or any sequence (including immutable one) of objects to sort. attr - the name of attribute to sort by

galaxy.webapps.base.controller.url_for(*args, **kwargs) str

Tries to resolve the URL using the routes module.

This only works in a WSGI app so a deprecation message is returned when running an ASGI app.

class galaxy.webapps.base.controller.UsesExtendedMetadataMixin[source]

Bases: SharableItemSecurityMixin

Mixin for getting and setting item extended metadata.

get_item_extended_metadata_obj(trans, item)[source]

Given an item object (such as a LibraryDatasetDatasetAssociation), find the object of the associated extended metadata

set_item_extended_metadata_obj(trans, item, extmeta_obj, check_writable=False)[source]
unset_item_extended_metadata_obj(trans, item, check_writable=False)[source]
create_extended_metadata(trans, extmeta)[source]

Create/index an extended metadata object. The returned object is not associated with any items

delete_extended_metadata(trans, item)[source]
class galaxy.webapps.base.controller.UsesFormDefinitionsMixin[source]

Bases: object

Mixin for controllers that use Galaxy form objects.

get_all_forms(trans, all_versions=False, filter=None, form_type='All')[source]

Return all the latest forms from the form_definition_current table if all_versions is set to True. Otherwise return all the versions of all the forms from the form_definition table.

save_widget_field(trans, field_obj, widget_name, **kwd)[source]
get_form_values(trans, user, form_definition, **kwd)[source]

Returns the name:value dictionary containing all the form values

class galaxy.webapps.base.controller.UsesTagsMixin[source]

Bases: SharableItemSecurityMixin

set_tags_from_list(trans, item, new_tags_list, user=None)[source]
get_user_tags_used(trans, user=None)[source]

Return a list of distinct ‘user_tname:user_value’ strings that the given user has used.

user defaults to trans.user. Returns an empty list if no user is given and trans.user is anonymous.

galaxy.webapps.base.webapp module

class galaxy.webapps.base.webapp.WebApplication(galaxy_app: MinimalApp, session_cookie: str = 'galaxysession', name: str | None = None)[source]

Bases: WebApplication

Base WSGI application instantiated for all Galaxy webapps.

A web application that:

  • adds API and UI controllers by scanning given directories and importing all modules found there.

  • has a security object.

  • builds mako template lookups.

  • generates GalaxyWebTransactions.

injection_aware: bool = False
__init__(galaxy_app: MinimalApp, session_cookie: str = 'galaxysession', name: str | None = None) None[source]

Create a new web application object. To actually connect some controllers use add_controller and add_route. Call finalize_config when all controllers and routes have been added and __call__ to handle a request (WSGI style).

build_apispec()[source]

Traverse all route paths starting with “api” and create an APISpec instance.

create_mako_template_lookup(galaxy_app, name)[source]
handle_controller_exception(e, trans, method, **kwargs)[source]

Allow handling of exceptions raised in controller methods.

make_body_iterable(trans, body)[source]
transaction_chooser(environ, galaxy_app: BasicSharedApp, session_cookie: str)[source]
add_ui_controllers(package_name, app)[source]

Search for UI controllers in package_name and add them to the webapp.

add_api_controllers(package_name, app)[source]

Search for UI controllers in package_name and add them to the webapp.

galaxy.webapps.base.webapp.config_allows_origin(origin_raw, config)[source]
galaxy.webapps.base.webapp.url_builder(*args, **kwargs) str[source]

Wrapper around the WSGI version of the function for reversing URLs.

class galaxy.webapps.base.webapp.GalaxyWebTransaction(environ: Dict[str, Any], app: BasicSharedApp, webapp: WebApplication, session_cookie: str | None = None)[source]

Bases: DefaultWebTransaction, ProvidesHistoryContext

Encapsulates web transaction specific state for the Galaxy application (specifically the user’s “cookie” session and history)

__init__(environ: Dict[str, Any], app: BasicSharedApp, webapp: WebApplication, session_cookie: str | None = None) None[source]
property app

Provide access to the Galaxy app object.

property url_builder

Provide access to Galaxy URLs (if available).

Parameters:

qualified (bool) – if True, the fully qualified URL is returned, else a relative URL is returned (default False).

set_cors_allow(name=None, value=None)[source]
set_cors_origin(origin=None)[source]
set_cors_headers()[source]

Allow CORS requests if configured to do so by echoing back the request’s ‘Origin’ header (if any) as the response header ‘Access-Control-Allow-Origin’

Preflight OPTIONS requests to the API work by routing all OPTIONS requests to a single method in the authenticate API (options method), setting CORS headers, and responding OK.

NOTE: raising some errors (such as httpexceptions), will remove the header (e.g. client will get both CORS error and 404 inside that)

get_user()[source]

Return the current user if logged in or None.

set_user(user)[source]

Set the current user.

property user

Return the current user if logged in or None.

Convenience method for getting a session cookie

property cookie_path
check_user_library_import_dir(user)[source]
user_checks(user)[source]

This could contain more checks around a user upon login

handle_user_login(user)[source]
Login a new user (possibly newly created)
  • do some ‘system’ checks (if any) for this user

  • create a new session

  • associate new session with user

  • if old session had a history and it was not associated with a user, associate it with the new session, otherwise associate the current session’s history with the user

  • add the disk usage of the current session to the user’s total disk usage

handle_user_logout(logout_all=False)[source]
Logout the current user:
  • invalidate the current session

  • create a new session with no user associated

get_galaxy_session()[source]

Return the current galaxy session

get_history(create=False, most_recent=False)[source]

Load the current history.

  • If that isn’t available, we find the most recently updated history.

  • If that isn’t available, we get or create the default history.

Transactions will not always have an active history (API requests), so None is a valid response.

set_history(history)[source]
property history

Provide access to the user’s current history model object.

Return type:

Optional[galaxy.model.History]

get_or_create_default_history()[source]

Gets or creates a default history and associates it with the current session.

get_most_recent_history()[source]

Gets the most recently updated history.

new_history(name=None)[source]

Create a new history and associate it with the current session and its associated user (if set).

template_context

Property that replaces itself with a calculated value the first time it is used.

set_message(message, type=None)[source]

Convenience method for setting the ‘message’ and ‘message_type’ element of the template context.

get_message()[source]

Convenience method for getting the ‘message’ element of the template context.

show_message(message, type='info', refresh_frames=None, cont=None, use_panels=False, active_view='')[source]

Convenience method for displaying a simple page with a single message.

type: one of “error”, “warning”, “info”, or “done”; determines the

type of dialog box and icon displayed with the message

refresh_frames: names of frames in the interface that should be

refreshed when the message is displayed

show_error_message(message, refresh_frames=None, use_panels=False, active_view='')[source]

Convenience method for displaying an error message. See show_message.

show_ok_message(message, refresh_frames=None, use_panels=False, active_view='')[source]

Convenience method for displaying an ok message. See show_message.

show_warn_message(message, refresh_frames=None, use_panels=False, active_view='')[source]

Convenience method for displaying an warn message. See show_message.

property session_csrf_token
check_csrf_token(payload)[source]
fill_template(filename, **kwargs)[source]

Fill in a template, putting any keyword arguments on the context.

fill_template_mako(filename, template_lookup=None, **kwargs)[source]
qualified_url_for_path(path)[source]
galaxy.webapps.base.webapp.create_new_session(trans, prev_galaxy_session=None, user_for_new_session=None)[source]

Create a new GalaxySession for this request, possibly with a connection to a previous session (in prev_galaxy_session) and an existing user (in user_for_new_session).

Caller is responsible for flushing the returned session.

galaxy.webapps.base.webapp.default_url_path(path)[source]
galaxy.webapps.base.webapp.build_url_map(app, global_conf, **local_conf)[source]