Skip to content

feat(plugins): add typed backend lists #493

Closed

Description

@uniqueg

Problem

proTES configures backends in two places (custom.tes.service_list,
custom.tes.discovery with one registry) and merges them with set(),
losing the order. proWES has a hard-coded backend. The default router
needs one ordered, typed list, and the registry trust rules should be
shared by all gateways.

Proposal

foca.plugins.backends:

  • Pydantic models for an ordered list of typed entries:
    ga4gh-tes (url, url_schemes default ["https"] so dev/test
    setups can allow http, id, auth, basic env var names, labels,
    location) and
    ga4gh-service-registry (url https only, id, refresh_interval
    300, timeout 10, versions as prefixes, environments, auth for
    discovered backends, allow_private_addresses false); ga4gh-wes
    follows with proWES. Unique IDs; URLs normalised (foca.utils.urls),
    no user info. Apps put the list under their own key (proTES:
    custom.tes.backends).
  • Registry discovery (moved from proTES, generic by API type): verified
    entries only (GET /verifications), type/version/environment filters,
    https, public addresses (via foca.utils.http), no redirects, no
    token; cache per entry and process with last-good fallback, retry
    ≤ 30 s, fork-safe lock.
  • expand(entries, api, public_url): entries in order → Backend
    candidates (source, group), own public URL and everything below
    it excluded
    (Q22), de-duplicated by Backend.id at the first
    position, configured entry's auth/labels/location winning over
    discovered ones; Backend.auth set from the entry (registry entries
    give theirs to discovered backends). Registries and discovered
    backends stay https only. Snapshot times per registry for provenance.
  • entry_for(backend): the typed entry behind a candidate (credential
    type, basic env var names), so the app attaches credentials after
    the forward phase.
  • find(url, refresh=True): look a backend up by URL (normalised), with
    a rate-limited registry refresh if unknown, for the Celery tracker and
    cancel in other processes (replaces proTES's get_backend(url)).

Acceptance criteria

  • Ordered expansion, de-duplication, configured-wins, self-exclusion,
    several registries; discovery filters and trust rules; cache refresh,
    last-good list, no list yet → no candidates; url_schemes;
    entry_for, find with refresh rate limit; all without network
    (mocked HTTP).
  • Docs: backend list configuration for apps (with proTES's mapping from
    the old keys).
  • 100% coverage, mypy, ruff, mkdocs build --strict.

Surviving the Connexion 3 migration

Pydantic models plus the guarded HTTP client; no request context (the
public URL is passed in). Unchanged in rc1; an async refresh can be added
with P8.

Dependencies

Open questions

  • None.

Added (from the proTES API read): GatewayApp(backends=lambda conf: ...) names the app's backend list config; create_app() validates it and foca.plugins.runtime.get_backend_list() builds the BackendList with the API and server.public_url, so apps don't repeat that glue.

Added during pre-review: malformed /verifications items are skipped and logged; max_stale (default 3600 s, at least refresh_interval) bounds how long a stale registry list is used, after which the entry yields no candidates; registry_allow_private_addresses and registry url_schemes (default [https]) apply to the registry itself, separate from the flag for discovered backends; registry entries require server.public_url (startup error otherwise); the own-URL check compares host, port and path regardless of scheme; foca.plugins.backends is a package (config, registry, lists) with unchanged public imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: highstatus: blockedtype: featuretype: securityworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions