-
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.
Merge pull request #2688 from fermyon/ungeneric-variables
Make `VariablesFactor` non-generic
- Loading branch information
Showing
14 changed files
with
154 additions
and
209 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
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
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,46 @@ | ||
use spin_factors::anyhow; | ||
use spin_world::{async_trait, v1, v2::variables}; | ||
|
||
use crate::InstanceState; | ||
|
||
#[async_trait] | ||
impl variables::Host for InstanceState { | ||
async fn get(&mut self, key: String) -> Result<String, variables::Error> { | ||
let key = spin_expressions::Key::new(&key).map_err(expressions_to_variables_err)?; | ||
self.expression_resolver | ||
.resolve(&self.component_id, key) | ||
.await | ||
.map_err(expressions_to_variables_err) | ||
} | ||
|
||
fn convert_error(&mut self, error: variables::Error) -> anyhow::Result<variables::Error> { | ||
Ok(error) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl v1::config::Host for InstanceState { | ||
async fn get_config(&mut self, key: String) -> Result<String, v1::config::Error> { | ||
<Self as variables::Host>::get(self, key) | ||
.await | ||
.map_err(|err| match err { | ||
variables::Error::InvalidName(msg) => v1::config::Error::InvalidKey(msg), | ||
variables::Error::Undefined(msg) => v1::config::Error::Provider(msg), | ||
other => v1::config::Error::Other(format!("{other}")), | ||
}) | ||
} | ||
|
||
fn convert_error(&mut self, err: v1::config::Error) -> anyhow::Result<v1::config::Error> { | ||
Ok(err) | ||
} | ||
} | ||
|
||
fn expressions_to_variables_err(err: spin_expressions::Error) -> variables::Error { | ||
use spin_expressions::Error; | ||
match err { | ||
Error::InvalidName(msg) => variables::Error::InvalidName(msg), | ||
Error::Undefined(msg) => variables::Error::Undefined(msg), | ||
Error::Provider(err) => variables::Error::Provider(err.to_string()), | ||
other => variables::Error::Other(format!("{other}")), | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
use spin_expressions::Provider; | ||
|
||
/// The runtime configuration for the variables factor. | ||
#[derive(Default)] | ||
pub struct RuntimeConfig { | ||
pub providers: Vec<Box<dyn Provider>>, | ||
} | ||
|
||
impl IntoIterator for RuntimeConfig { | ||
type Item = Box<dyn Provider>; | ||
type IntoIter = std::vec::IntoIter<Box<dyn Provider>>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
self.providers.into_iter() | ||
} | ||
} |
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
Oops, something went wrong.