-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove variables factor assumption of toml
Signed-off-by: Ryan Levick <[email protected]>
- Loading branch information
Showing
6 changed files
with
85 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,17 @@ | ||
mod env; | ||
mod statik; | ||
|
||
pub use env::EnvVariables; | ||
pub use statik::StaticVariables; | ||
|
||
use serde::de::DeserializeOwned; | ||
use spin_expressions::Provider; | ||
use spin_factors::anyhow; | ||
|
||
/// A trait for converting a runtime configuration into a variables provider. | ||
pub trait MakeVariablesProvider: 'static { | ||
const RUNTIME_CONFIG_TYPE: &'static str; | ||
|
||
/// Serialized configuration for the provider. | ||
type RuntimeConfig: DeserializeOwned; | ||
type Provider: Provider; | ||
|
||
fn make_provider(&self, runtime_config: Self::RuntimeConfig) -> anyhow::Result<Self::Provider>; | ||
} | ||
|
||
pub(crate) type ProviderFromToml = Box<dyn Fn(toml::Table) -> anyhow::Result<Box<dyn Provider>>>; | ||
|
||
pub(crate) fn provider_from_toml_fn<T: MakeVariablesProvider>( | ||
provider_type: T, | ||
) -> ProviderFromToml { | ||
Box::new(move |table| { | ||
let runtime_config: T::RuntimeConfig = table.try_into()?; | ||
let provider = provider_type.make_provider(runtime_config)?; | ||
Ok(Box::new(provider)) | ||
}) | ||
/// Create a variables provider from the given runtime configuration. | ||
/// | ||
/// Returns `Ok(None)` if the provider is not applicable to the given configuration. | ||
fn make_provider( | ||
&self, | ||
runtime_config: &Self::RuntimeConfig, | ||
) -> anyhow::Result<Option<Box<dyn Provider>>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//! The runtime configuration for the variables factor used in the Spin CLI. | ||
|
||
mod env; | ||
mod statik; | ||
|
||
pub use env::EnvVariables; | ||
pub use statik::StaticVariables; | ||
|
||
use serde::Deserialize; | ||
use statik::StaticVariablesProvider; | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "snake_case", tag = "type")] | ||
pub enum RuntimeConfig { | ||
Static(StaticVariablesProvider), | ||
Env(env::EnvVariablesConfig), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters