-
Notifications
You must be signed in to change notification settings - Fork 249
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
Make VariablesFactor
non-generic
#2688
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to hide this field behind a e.g.
add_provider
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll make this change in a follow up.