-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ryan Levick <[email protected]>
- Loading branch information
Showing
3 changed files
with
61 additions
and
57 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
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 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