Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crates/trusted-server-adapter-fastly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use trusted_server_core::constants::{
};
use trusted_server_core::ec::admin::handle_register_partner;
use trusted_server_core::ec::finalize::ec_finalize_response;
use trusted_server_core::ec::identify::{cors_preflight_identify, handle_identify};
use trusted_server_core::ec::kv::KvIdentityGraph;
use trusted_server_core::ec::partner::PartnerStore;
use trusted_server_core::ec::sync_pixel::handle_sync;
use trusted_server_core::ec::EcContext;
use trusted_server_core::error::TrustedServerError;
use trusted_server_core::geo::GeoInfo;
Expand Down Expand Up @@ -137,6 +139,18 @@ async fn route_request(
require_partner_store(settings).and_then(|store| handle_register_partner(&store, req))
}

(Method::GET, "/sync") => require_identity_graph(settings).and_then(|kv| {
require_partner_store(settings).and_then(|partner_store| {
handle_sync(settings, &kv, &partner_store, &req, &mut ec_context)
})
}),
(Method::GET, "/identify") => require_identity_graph(settings).and_then(|kv| {
require_partner_store(settings).and_then(|partner_store| {
handle_identify(settings, &kv, &partner_store, &req, &ec_context)
})
}),
(Method::OPTIONS, "/identify") => cors_preflight_identify(settings, &req),

// Unified auction endpoint (returns creative HTML inline)
(Method::POST, "/auction") => {
handle_auction(settings, orchestrator, kv_graph.as_ref(), &ec_context, req).await
Expand Down Expand Up @@ -268,3 +282,17 @@ fn require_partner_store(settings: &Settings) -> Result<PartnerStore, Report<Tru
})?;
Ok(PartnerStore::new(store_name))
}

/// Constructs a `KvIdentityGraph` from settings, or returns 503 if the
/// `ec_store` config is not set.
fn require_identity_graph(
settings: &Settings,
) -> Result<KvIdentityGraph, Report<TrustedServerError>> {
let store_name = settings.ec.ec_store.as_deref().ok_or_else(|| {
Report::new(TrustedServerError::KvStore {
store_name: "ec.ec_store".to_owned(),
message: "ec.ec_store is not configured".to_owned(),
})
})?;
Ok(KvIdentityGraph::new(store_name))
}
6 changes: 6 additions & 0 deletions crates/trusted-server-core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pub const COOKIE_TS_EC: &str = "ts-ec";

pub const HEADER_X_PUB_USER_ID: HeaderName = HeaderName::from_static("x-pub-user-id");
pub const HEADER_X_TS_EC: HeaderName = HeaderName::from_static("x-ts-ec");
pub const HEADER_X_TS_EIDS: HeaderName = HeaderName::from_static("x-ts-eids");
pub const HEADER_X_TS_EC_CONSENT: HeaderName = HeaderName::from_static("x-ts-ec-consent");
pub const HEADER_X_TS_EIDS_TRUNCATED: HeaderName = HeaderName::from_static("x-ts-eids-truncated");
pub const HEADER_X_CONSENT_ADVERTISING: HeaderName =
HeaderName::from_static("x-consent-advertising");
pub const HEADER_X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for");
Expand Down Expand Up @@ -44,6 +47,9 @@ pub const HEADER_REFERER: HeaderName = HeaderName::from_static("referer");
/// in `const` context.
pub const INTERNAL_HEADERS: &[&str] = &[
"x-ts-ec",
"x-ts-eids",
"x-ts-ec-consent",
"x-ts-eids-truncated",
"x-pub-user-id",
"x-subject-id",
"x-consent-advertising",
Expand Down
Loading
Loading