Skip to content

feat(gateway): add HostPattern::Env for self-hosted connector hosts - #374

Open
nbmorgan wants to merge 1 commit into
onecli:mainfrom
nbmorgan:feat/host-pattern-env
Open

feat(gateway): add HostPattern::Env for self-hosted connector hosts#374
nbmorgan wants to merge 1 commit into
onecli:mainfrom
nbmorgan:feat/host-pattern-env

Conversation

@nbmorgan

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Feature (gateway).

What is the current behavior?

The gateway matches incoming requests to providers using a compiled host-pattern table (HostPattern::Exact / HostPattern::Suffix), both of which require the hostname to be known at build time. There is no supported way to route a self-hosted service whose hostname is deployment-specific (e.g. affine.mycompany.com).

Closes #354.

What is the new behavior?

Adds a third variant, HostPattern::Env(&'static str), that matches a provider's host against the value of a named environment variable, read at match time:

  • Case-insensitive match.
  • Never matches when the variable is unset or empty (safe default).
  • The existing credential_host_field gate still applies on top as a per-connection security layer, so a token cannot leak to a different host even if the env var is repointed.
  • Unit test covers unset / empty / match / case-insensitive / other-host.
  • Documents the mechanism in docs/self-hosted-connectors.md.

This satisfies the acceptance criteria in #354.

Additional context

The variant carries #[allow(dead_code)] because it has no provider consumer in this PR. Its first consumer — the AFFiNE connector (#373) — lands in a follow-up PR stacked on this one, which removes the attribute.

Local checks pass: pnpm check (lint + types + format, including cargo fmt --check and cargo clippy -- -D warnings) and the gateway test suite.

Adds a third HostPattern variant that matches a provider's host against
the value of a named environment variable, read at match time. This lets
operators configure deployment-specific hostnames for self-hosted
services without a binary change.

- Case-insensitive match; never matches when the var is unset or empty.
- The existing credential_host_field gate still applies on top as a
  per-connection security layer.
- Unit test covers unset/empty/match/case-insensitive/other-host.
- Documents the mechanism in docs/self-hosted-connectors.md.

The variant carries #[allow(dead_code)] until its first consumer (the
AFFiNE connector) lands in a follow-up PR.

Closes onecli#354

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support self-hosted connectors with user-defined instance URLs

1 participant