Skip to content

Commit 07aa943

Browse files
authored
Add config store read path and split storage module (PR3) (#548)
* Rename crates to trusted-server-core and trusted-server-adapter-fastly Rename crates/common → crates/trusted-server-core and crates/fastly → crates/trusted-server-adapter-fastly following the EdgeZero naming convention. Add EdgeZero workspace dependencies pinned to rev 170b74b. Update all references across docs, CI workflows, scripts, agent files, and configuration. * Add platform abstraction layer with traits and RuntimeServices Introduces trusted-server-core::platform with PlatformConfigStore, PlatformSecretStore, PlatformKvStore, PlatformBackend, PlatformHttpClient, and PlatformGeo traits alongside ClientInfo, PlatformError, and RuntimeServices. Wires the Fastly adapter implementations and threads RuntimeServices into route_request. Moves GeoInfo to platform/types as platform-neutral data and adds geo_from_fastly for field mapping. - Defer KV store opening: replace early error return with a local UnavailableKvStore fallback so routes that do not need synthetic ID access succeed when the KV store is missing or temporarily unavailable - Use ConfigStore::try_open + try_get and SecretStore::try_get throughout FastlyPlatformConfigStore and FastlyPlatformSecretStore to honour the Result contract instead of panicking on open/lookup failure - Encapsulate RuntimeServices service fields as pub(crate) with public getter methods (config_store, secret_store, backend, http_client, geo) and a pub new() constructor; adapter updated to use new() - Reference #487 in FastlyPlatformHttpClient stub (PR 6 implements it) - Remove unused KvPage re-export from platform/mod.rs - Use super::KvHandle shorthand in RuntimeServices::kv_handle() * Reject host strings containing control characters in BackendConfig * Validate scheme and host for control characters in BackendConfig * Add config store read path and storage module split - Split fastly_storage.rs into storage/{config_store,secret_store,api_client,mod}.rs - Add PlatformConfigStore read path via FastlyPlatformConfigStore::get using ConfigStore::try_open/try_get - Add PlatformError::NotImplemented variant; stub write methods on FastlyPlatformConfigStore and FastlyPlatformSecretStore - Add StoreName/StoreId newtypes with From<String>, From<&str>, AsRef<str> - Add UnavailableKvStore to core platform module - Add RuntimeServicesBuilder replacing 7-arg constructor - Migrate get_active_jwks and handle_trusted_server_discovery to use &RuntimeServices - Update call sites in signing.rs, rotation.rs, main.rs - Add success-path test for handle_trusted_server_discovery using StubJwksConfigStore - Fix test_parse_cookies_to_jar_empty typo (was emtpy) * Harden legacy config-store reads and align Fastly adapter stubs - Make StoreName and StoreId inner fields private; From/AsRef provide all needed construction and access - Add #[deprecated] to GeoInfo::from_request with #[allow(deprecated)] at the three legacy call sites to track migration progress - Enumerate the six platform traits in the platform module doc comment - Extract backend_config_from_spec helper to remove duplicate BackendConfig construction in predict_name and ensure - Replace .into_iter().collect() with .to_vec() on secret plaintext bytes - Remove unused bytes dependency from trusted-server-adapter-fastly - Add comment on SecretStore::open clarifying it already returns Result (unlike ConfigStore::open which panics) * Make client_info field pub(crate) and add a client_info() accessor
1 parent e26d203 commit 07aa943

15 files changed

Lines changed: 993 additions & 635 deletions

File tree

crates/trusted-server-adapter-fastly/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async fn route_request(
111111
// already captured in RuntimeServices at the entry point.
112112
let geo_info = runtime_services
113113
.geo()
114-
.lookup(runtime_services.client_info.client_ip)
114+
.lookup(runtime_services.client_info().client_ip)
115115
.unwrap_or_else(|e| {
116116
log::warn!("geo lookup failed: {e}");
117117
None
@@ -147,7 +147,7 @@ async fn route_request(
147147

148148
// Discovery endpoint for trusted-server capabilities and JWKS
149149
(Method::GET, "/.well-known/trusted-server.json") => {
150-
handle_trusted_server_discovery(settings, req)
150+
handle_trusted_server_discovery(settings, runtime_services, req)
151151
}
152152

153153
// Signature verification endpoint

crates/trusted-server-adapter-fastly/src/platform.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ use fastly::geo::geo_lookup;
1515
use fastly::{ConfigStore, Request, SecretStore};
1616

1717
use trusted_server_core::backend::BackendConfig;
18-
use trusted_server_core::fastly_storage::FastlyApiClient;
1918
use trusted_server_core::geo::geo_from_fastly;
2019
use trusted_server_core::platform::{
2120
ClientInfo, GeoInfo, PlatformBackend, PlatformBackendSpec, PlatformConfigStore, PlatformError,
2221
PlatformGeo, PlatformHttpClient, PlatformHttpRequest, PlatformKvStore, PlatformPendingRequest,
2322
PlatformResponse, PlatformSecretStore, PlatformSelectResult, RuntimeServices, StoreId,
2423
StoreName,
2524
};
25+
use trusted_server_core::storage::FastlyApiClient;
2626

2727
pub(crate) use trusted_server_core::platform::UnavailableKvStore;
2828

@@ -34,7 +34,7 @@ pub(crate) use trusted_server_core::platform::UnavailableKvStore;
3434
///
3535
/// Stateless — the store name is supplied per call, matching the trait
3636
/// signature. This replaces the store-name-at-construction pattern of
37-
/// [`trusted_server_core::fastly_storage::FastlyConfigStore`].
37+
/// [`trusted_server_core::storage::FastlyConfigStore`].
3838
///
3939
/// # Write cost
4040
///
@@ -91,7 +91,7 @@ impl PlatformConfigStore for FastlyPlatformConfigStore {
9191
///
9292
/// Stateless — the store name is supplied per call. This replaces the
9393
/// store-name-at-construction pattern of
94-
/// [`trusted_server_core::fastly_storage::FastlySecretStore`].
94+
/// [`trusted_server_core::storage::FastlySecretStore`].
9595
///
9696
/// # Write cost
9797
///
@@ -256,7 +256,7 @@ impl PlatformGeo for FastlyPlatformGeo {
256256
/// Call this once at the entry point before dispatching to handlers.
257257
/// `client_info` is populated from TLS and IP metadata available on the
258258
/// request; geo lookup is deferred to handler time via
259-
/// `services.geo.lookup(services.client_info.client_ip)`.
259+
/// `services.geo().lookup(services.client_info().client_ip)`.
260260
///
261261
/// `kv_store` is an [`Arc<dyn PlatformKvStore>`] opened by the caller for
262262
/// the primary KV store. Use [`open_kv_store`] to construct it.
@@ -396,11 +396,11 @@ mod tests {
396396
let services = build_runtime_services(&req, noop_kv_store());
397397

398398
assert!(
399-
services.client_info.tls_protocol.is_none(),
399+
services.client_info().tls_protocol.is_none(),
400400
"should have no tls_protocol on plain test request"
401401
);
402402
assert!(
403-
services.client_info.tls_cipher.is_none(),
403+
services.client_info().tls_cipher.is_none(),
404404
"should have no tls_cipher on plain test request"
405405
);
406406
}
@@ -412,7 +412,8 @@ mod tests {
412412
let cloned = services.clone();
413413

414414
assert_eq!(
415-
services.client_info.client_ip, cloned.client_info.client_ip,
415+
services.client_info().client_ip,
416+
cloned.client_info().client_ip,
416417
"should preserve client_ip through clone"
417418
);
418419
}

0 commit comments

Comments
 (0)