Skip to content
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

Stellate viceroy changes to enable rich integration tests #354

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
[workspace]
members = [
"cli",
"lib",
]
members = ["cli", "lib"]
resolver = "2"

# Exclude our integration test fixtures, which need to be compiled to wasm
# (managed by the Makefile)
exclude = [
"test-fixtures",
]
exclude = ["test-fixtures"]

# Specify `cli` as the default workspace member to operate on. This means that
# commands like `cargo run` will run the CLI binary by default.
# See: https://doc.rust-lang.org/cargo/reference/workspaces.html#package-selection
default-members = [ "cli" ]
default-members = ["cli"]

[profile.dev]
# Since some of the integration tests involve compiling Wasm, a little optimization goes a long way
Expand All @@ -36,6 +31,7 @@ tracing = "0.1.37"
tracing-futures = "0.2.5"
futures = "0.3.24"
url = "2.3.1"
async-trait = "0.1.74"

# Wasmtime dependencies
wasi-common = "13.0.0"
Expand Down
19 changes: 12 additions & 7 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ categories = [
"development-tools",
"network-programming",
"simulation",
"wasm"
"wasm",
]
include = [
"../README.md",
"../CHANGELOG.md",
"../SECURITY.md",
"../doc/logo.png",
"src/**/*"
"../README.md",
"../CHANGELOG.md",
"../SECURITY.md",
"../doc/logo.png",
"src/**/*",
]

[[bin]]
Expand All @@ -38,7 +38,12 @@ serde_json = { workspace = true }
clap = { workspace = true }
rustls = { workspace = true }
rustls-pemfile = { workspace = true }
tls-listener = { version = "^0.7.0", features = ["rustls", "hyper-h1", "tokio-net", "rt"] }
tls-listener = { version = "^0.7.0", features = [
"rustls",
"hyper-h1",
"tokio-net",
"rt",
] }
tokio = { workspace = true }
tokio-rustls = { workspace = true }
tracing = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/integration/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ impl Test {
.await
.map(|result| {
match result {
(resp, None) => resp,
(_, Some(err)) => {
(resp, None, _) => resp,
(_, Some(err), _) => {
// Splat the string representation of the runtime error into a synthetic
// 500. This is a bit of a hack, but good enough to check for expected error
// strings.
Expand Down
1 change: 1 addition & 0 deletions cli/tests/integration/common/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl TestBackends {
use_sni: backend.use_sni,
grpc: false,
client_cert: None,
handler: None,
};
backends.insert(name.to_string(), Arc::new(backend_config));
}
Expand Down
8 changes: 2 additions & 6 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ documentation = "https://docs.rs/viceroy-lib"
homepage = "https://github.com/fastly/Viceroy"
repository = "https://github.com/fastly/Viceroy"
keywords = ["wasm", "fastly"]
categories = [
"development-tools",
"network-programming",
"simulation",
"wasm"
]
categories = ["development-tools", "network-programming", "simulation", "wasm"]
include = [
"../CHANGELOG.md",
"../SECURITY.md",
Expand Down Expand Up @@ -57,6 +52,7 @@ wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }
wasmtime-wasi-nn = { workspace = true }
wiggle = { workspace = true }
async-trait.workspace = true

[dev-dependencies]
tempfile = "3.6.0"
Expand Down
7 changes: 5 additions & 2 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ pub type Dictionaries = HashMap<DictionaryName, Dictionary>;
/// Types and deserializers for backend configuration settings.
mod backends;

pub use self::backends::{Backend, ClientCertError, ClientCertInfo};
pub use self::backends::{
Backend, ClientCertError, ClientCertInfo, DynamicBackendRegistrationInterceptor, Handler,
InMemoryBackendHandler,
};

pub type Backends = HashMap<String, Arc<Backend>>;

Expand All @@ -46,7 +49,7 @@ pub use self::geolocation::Geolocation;
/// Types and deserializers for object store configuration settings.
mod object_store;

pub use crate::object_store::ObjectStores;
pub use crate::object_store::{ObjectKey, ObjectStoreKey, ObjectStores};

/// Types and deserializers for secret store configuration settings.
mod secret_store;
Expand Down
45 changes: 45 additions & 0 deletions lib/src/config/backends.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod client_cert_info;

use async_trait::async_trait;
use http::{Request, Response};
use hyper::Body;
use {
hyper::{header::HeaderValue, Uri},
std::{collections::HashMap, sync::Arc},
Expand All @@ -16,6 +19,47 @@ pub struct Backend {
pub use_sni: bool,
pub grpc: bool,
pub client_cert: Option<ClientCertInfo>,

/// Handler that will be called instead of making an HTTP call.
pub handler: Option<Handler>,
}

#[derive(Clone)]
pub struct Handler {
handler: Arc<Box<dyn InMemoryBackendHandler>>,
}

impl Handler {
pub fn new(handler: Box<dyn InMemoryBackendHandler>) -> Self {
Self {
handler: Arc::new(handler),
}
}
}

impl std::ops::Deref for Handler {
type Target = dyn InMemoryBackendHandler;

fn deref(&self) -> &Self::Target {
&**self.handler
}
}

impl std::fmt::Debug for Handler {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Handler")
.field("handler", &"opaque handler function".to_string())
.finish()
}
}

#[async_trait]
pub trait InMemoryBackendHandler: Send + Sync + 'static {
async fn handle(&self, req: Request<crate::body::Body>) -> Response<Body>;
}

pub trait DynamicBackendRegistrationInterceptor: Send + Sync + 'static {
fn register(&self, backend: Backend) -> Backend;
}

/// A map of [`Backend`] definitions, keyed by their name.
Expand Down Expand Up @@ -149,6 +193,7 @@ mod deserialization {
grpc,
// NOTE: Update when we support client certs in static backends
client_cert: None,
handler: None,
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ pub enum HandleError {
#[error("Invalid body handle: {0}")]
InvalidBodyHandle(crate::wiggle_abi::types::BodyHandle),

/// A cache handle was not valid.
#[error("Invalid cache handle: {0}")]
InvalidCacheHandle(crate::wiggle_abi::types::CacheHandle),

/// A logging endpoint handle was not valid.
#[error("Invalid endpoint handle: {0}")]
InvalidEndpointHandle(crate::wiggle_abi::types::EndpointHandle),
Expand Down
Loading