Skip to content

feat: sync the served environment set from the proxy config - #25

Merged
gagantrivedi merged 1 commit into
mainfrom
feat/proxy-config-sync
Sep 19, 2026
Merged

gagantrivedi merged 1 commit into
mainfrom
feat/proxy-config-sync

Conversation

@gagantrivedi

Copy link
Copy Markdown
Member

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to Flagsmith/edge-proxy#128

Re-lands #18, already reviewed and approved there: it merged into the #17 branch 36 seconds after #17 had merged into main, so its code never reached main. This is the same squash commit cherry-picked onto main, applied cleanly with no changes.

With a proxy_key configured, the proxy keeps its served environments in sync with the proxy config endpoint (GET /api/v1/proxy/config/, X-Proxy-Key header): a newly created environment is served within one poll interval, rotations and removals propagate automatically, and per-environment configuration is no longer needed.

  • New proxy_key setting (a single key — organisation-level grants make one key multi-org).
  • models/proxy_config.rs: serde DTOs declaring only the fields acted on; everything else the endpoint sends is ignored.
  • EnvironmentIndex::sync_to(desired): inserts new/changed environments, removes absent ones — statically configured environments (the index remembers their keys) are never overridden, removed, or key-hijacked by the config.
  • Sync runs at the top of each poll pass, so new environments get their documents in the same tick. An environment is removed only when a successful fetch no longer lists it — an outage or a rejected proxy key never removes anything.
  • Environments with no usable server key (e.g. freshly created, keys not minted yet) are skipped rather than failing the poll, and a deactivated or expired server key stops authenticating on the next request.

How did you test this code?

cargo test: 70 green on top of main — reconcile unit tests plus tests/test_proxy_config_discovery.rs, wiremock against the frozen contract shape: environment added / dropped / key-rotated, static-never-removed, and fetch-failure-removes-nothing. Clippy and fmt clean.

With a proxy_key configured, the proxy keeps its served environments in
sync with GET /api/v1/proxy/config/: new environments are served within
one poll interval, rotations and removals propagate, and per-environment
configuration is no longer needed.

- proxy_key setting (one key; organisation-level grants make it multi-org)
- models/proxy_config.rs: serde DTOs for the fields acted on
- EnvironmentIndex::sync_to(desired): insert new/changed, remove absent;
  statically configured environments are never overridden or removed
- sync runs at the top of each poll pass; a failed fetch removes nothing
- environments with no usable server key are skipped, and a deactivated
  or expired server key stops authenticating on the next request

Re-lands #18, which merged into the #17 branch after #17 had already
merged into main.
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 16e00afe-ef2f-4546-a0ef-25c4d54f22d9


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gagantrivedi
gagantrivedi merged commit 92272cf into main Sep 19, 2026
5 checks passed
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.

2 participants