Skip to content
Closed
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
67 changes: 40 additions & 27 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ lazy_static = "1.5"
path-absolutize = "3"
quote = "1"
rand = "0.9"
redis = "0.32.5"
redis = "0.29"
regex = "1"
reqwest = { version = "0.12", features = ["stream", "blocking"] }
rusqlite = "0.34"
Expand Down
33 changes: 0 additions & 33 deletions crates/common/src/assert.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// - Code should have at least 2 dependents

pub mod arg_parser;
pub mod assert;
pub mod data_dir;
pub mod paths;
pub mod sha256;
Expand Down
1 change: 1 addition & 0 deletions crates/expressions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
futures = { workspace = true }
serde = { workspace = true }
spin-locked-app = { path = "../locked-app" }
thiserror = { workspace = true }

Expand Down
32 changes: 32 additions & 0 deletions crates/expressions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub use provider::Provider;
use template::Part;
pub use template::Template;

use crate::provider::ProviderVariableKind;

/// A [`ProviderResolver`] that can be shared.
pub type SharedPreparedResolver =
std::sync::Arc<std::sync::OnceLock<std::sync::Arc<PreparedResolver>>>;
Expand Down Expand Up @@ -90,6 +92,30 @@ impl ProviderResolver {
Ok(PreparedResolver { variables })
}

/// Prepares the resolver by attempting to resolve all variables, printing warnings for any
/// that cannot be resolved.
pub async fn pre_runtime_prepare(&self) -> Result<()> {
for name in self.internal.variables.keys() {
self.check_variable_existence(name).await?;
}
Ok(())
}

async fn check_variable_existence(&self, key: &str) -> Result<()> {
for provider in &self.providers {
if provider.kind() == &ProviderVariableKind::Dynamic {
continue;
}

match provider.get(&Key(key)).await {
Ok(Some(_)) => return Ok(()),
Err(_) | Ok(None) => return self.internal.resolve_variable(key).map(|_| ()),
}
}

Ok(())
}

async fn resolve_variable(&self, key: &str) -> Result<String> {
for provider in &self.providers {
if let Some(value) = provider.get(&Key(key)).await.map_err(Error::Provider)? {
Expand Down Expand Up @@ -309,6 +335,8 @@ pub enum Error {
mod tests {
use async_trait::async_trait;

use crate::provider::ProviderVariableKind;

use super::*;

#[derive(Debug)]
Expand All @@ -323,6 +351,10 @@ mod tests {
_ => Ok(None),
}
}

fn kind(&self) -> &ProviderVariableKind {
&ProviderVariableKind::Static
}
}

async fn test_resolve(template: &str) -> Result<String> {
Expand Down
12 changes: 12 additions & 0 deletions crates/expressions/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Debug;

use async_trait::async_trait;
use serde::Deserialize;

use crate::Key;

Expand All @@ -9,4 +10,15 @@ use crate::Key;
pub trait Provider: Debug + Send + Sync {
/// Returns the value at the given config path, if it exists.
async fn get(&self, key: &Key) -> anyhow::Result<Option<String>>;
fn kind(&self) -> &ProviderVariableKind;
}

/// The dynamism of a Provider.
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
pub enum ProviderVariableKind {
/// Variable must be declared on start
#[default]
Static,
/// Variable can be made available at runtime
Dynamic,
}
1 change: 0 additions & 1 deletion crates/factor-outbound-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ wasmtime-wasi = { workspace = true }
wasmtime-wasi-http = { workspace = true }

[dev-dependencies]
spin-common = { path = "../common" }
spin-factor-variables = { path = "../factor-variables" }
spin-factors-test = { path = "../factors-test" }

Expand Down
Loading
Loading