@@ -37,6 +37,61 @@ impl v1::config::Host for InstanceState {
3737 }
3838}
3939
40+ #[ async_trait]
41+ impl spin_world:: wasi:: config:: store:: Host for InstanceState {
42+ async fn get (
43+ & mut self ,
44+ key : String ,
45+ ) -> Result < Option < String > , spin_world:: wasi:: config:: store:: Error > {
46+ match <Self as variables:: Host >:: get ( self , key) . await {
47+ Ok ( value) => Ok ( Some ( value) ) ,
48+ // Err(e) if matches!(e, variables::Error::Undefined(_)) => Ok(Ok(None)),
49+ Err ( e) => {
50+ match e {
51+ variables:: Error :: Undefined ( _) => Ok ( None ) ,
52+ variables:: Error :: InvalidName ( msg) => {
53+ Err ( spin_world:: wasi:: config:: store:: Error :: Io ( msg) )
54+ } // TODO: this doesn't feel ideal, but wasi-config only allows two error cases
55+ variables:: Error :: Provider ( msg) => {
56+ Err ( spin_world:: wasi:: config:: store:: Error :: Upstream ( msg) )
57+ }
58+ variables:: Error :: Other ( msg) => {
59+ Err ( spin_world:: wasi:: config:: store:: Error :: Io ( msg) )
60+ } // TODO: again, hard to know how to map this (and the original expressions::Error is not more helpful)
61+ }
62+ }
63+ }
64+ }
65+
66+ async fn get_all (
67+ & mut self ,
68+ ) -> Result < Vec < ( String , String ) > , spin_world:: wasi:: config:: store:: Error > {
69+ let all = self
70+ . expression_resolver
71+ . resolve_all ( & self . component_id )
72+ . await ;
73+ all. map_err ( |e| {
74+ match expressions_to_variables_err ( e) {
75+ variables:: Error :: Undefined ( msg) => spin_world:: wasi:: config:: store:: Error :: Io ( msg) , // TODO: this should presumably not occur here
76+ variables:: Error :: InvalidName ( msg) => {
77+ spin_world:: wasi:: config:: store:: Error :: Io ( msg)
78+ } // TODO: this doesn't feel ideal, but wasi-config only allows two error cases
79+ variables:: Error :: Provider ( msg) => {
80+ spin_world:: wasi:: config:: store:: Error :: Upstream ( msg)
81+ }
82+ variables:: Error :: Other ( msg) => spin_world:: wasi:: config:: store:: Error :: Io ( msg) , // TODO: again, hard to know how to map this (and the original expressions::Error is not more helpful)
83+ }
84+ } )
85+ }
86+
87+ fn convert_error (
88+ & mut self ,
89+ err : spin_world:: wasi:: config:: store:: Error ,
90+ ) -> anyhow:: Result < spin_world:: wasi:: config:: store:: Error > {
91+ Ok ( err)
92+ }
93+ }
94+
4095fn expressions_to_variables_err ( err : spin_expressions:: Error ) -> variables:: Error {
4196 use spin_expressions:: Error ;
4297 match err {
0 commit comments