-
Notifications
You must be signed in to change notification settings - Fork 8
Add platform abstraction layer with traits and RuntimeServices #545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
180471e
f63e5b2
020e88c
37c8fbf
7495d96
2c40d58
46e3360
2f40b4c
8210a85
99d7bee
a2597e5
d7a35a1
591b9b3
eec34fb
d6be0b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ use trusted_server_core::error::TrustedServerError; | |
| use trusted_server_core::geo::GeoInfo; | ||
| use trusted_server_core::http_util::sanitize_forwarded_headers; | ||
| use trusted_server_core::integrations::IntegrationRegistry; | ||
| use trusted_server_core::platform::RuntimeServices; | ||
| use trusted_server_core::proxy::{ | ||
| handle_first_party_click, handle_first_party_proxy, handle_first_party_proxy_rebuild, | ||
| handle_first_party_proxy_sign, | ||
|
|
@@ -27,7 +28,10 @@ use trusted_server_core::settings::Settings; | |
| use trusted_server_core::settings_data::get_settings; | ||
|
|
||
| mod error; | ||
| mod platform; | ||
|
|
||
| use crate::error::to_error_response; | ||
| use crate::platform::{build_runtime_services, open_kv_store, UnavailableKvStore}; | ||
|
|
||
| #[fastly::main] | ||
| fn main(req: Request) -> Result<Response, Error> { | ||
|
|
@@ -59,10 +63,28 @@ fn main(req: Request) -> Result<Response, Error> { | |
| } | ||
| }; | ||
|
|
||
| let kv_store = match open_kv_store(&settings.synthetic.opid_store) { | ||
| Ok(s) => s, | ||
| Err(e) => { | ||
| // Degrade gracefully: routes that do not touch synthetic IDs | ||
| // (e.g. /.well-known/, /verify-signature, /admin/keys/*) must | ||
| // still succeed even when the KV store is unavailable. | ||
| // Handlers that call kv_handle() will receive KvError::Unavailable. | ||
| log::warn!( | ||
| "KV store '{}' unavailable, synthetic ID routes will return errors: {e}", | ||
| settings.synthetic.opid_store | ||
| ); | ||
| std::sync::Arc::new(UnavailableKvStore) | ||
| as std::sync::Arc<dyn trusted_server_core::platform::PlatformKvStore> | ||
| } | ||
| }; | ||
| let runtime_services = build_runtime_services(&req, kv_store); | ||
|
|
||
| futures::executor::block_on(route_request( | ||
| &settings, | ||
| &orchestrator, | ||
| &integration_registry, | ||
| &runtime_services, | ||
| req, | ||
| )) | ||
| } | ||
|
|
@@ -71,15 +93,23 @@ async fn route_request( | |
| settings: &Settings, | ||
| orchestrator: &AuctionOrchestrator, | ||
| integration_registry: &IntegrationRegistry, | ||
| runtime_services: &RuntimeServices, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we create a tracking issue for threading |
||
| mut req: Request, | ||
| ) -> Result<Response, Error> { | ||
| // Strip client-spoofable forwarded headers at the edge. | ||
| // On Fastly this service IS the first proxy — these headers from | ||
| // clients are untrusted and can hijack URL rewriting (see #409). | ||
| sanitize_forwarded_headers(&mut req); | ||
|
|
||
| // Extract geo info before auth check or routing consumes the request | ||
| let geo_info = GeoInfo::from_request(&req); | ||
| // Look up geo info via the platform abstraction using the client IP | ||
| // already captured in RuntimeServices at the entry point. | ||
| let geo_info = runtime_services | ||
| .geo() | ||
| .lookup(runtime_services.client_info.client_ip) | ||
| .unwrap_or_else(|e| { | ||
| log::warn!("geo lookup failed: {e}"); | ||
| None | ||
| }); | ||
|
|
||
| if let Some(mut response) = enforce_basic_auth(settings, &req) { | ||
| finalize_response(settings, geo_info.as_ref(), &mut response); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.