2020
2121//! Implements a client to access Agama's storage service.
2222
23- use crate :: config:: Config ;
24- use agama_utils:: api:: Issue ;
25- use serde_json:: { value:: RawValue , Value } ;
23+ use agama_utils:: api:: { storage:: Config , Issue } ;
24+ use serde_json:: Value ;
2625use zbus:: { names:: BusName , zvariant:: OwnedObjectPath , Connection , Message } ;
2726
2827const SERVICE_NAME : & str = "org.opensuse.Agama.Storage1" ;
@@ -72,7 +71,7 @@ impl Client {
7271 Ok ( ( ) )
7372 }
7473
75- pub async fn get_system ( & self ) -> Result < Option < Box < RawValue > > , Error > {
74+ pub async fn get_system ( & self ) -> Result < Option < Value > , Error > {
7675 let message = self . call ( "GetSystem" , & ( ) ) . await ?;
7776 try_from_message ( message)
7877 }
@@ -82,12 +81,12 @@ impl Client {
8281 try_from_message ( message)
8382 }
8483
85- pub async fn get_config_model ( & self ) -> Result < Option < Box < RawValue > > , Error > {
84+ pub async fn get_config_model ( & self ) -> Result < Option < Value > , Error > {
8685 let message = self . call ( "GetConfigModel" , & ( ) ) . await ?;
8786 try_from_message ( message)
8887 }
8988
90- pub async fn get_proposal ( & self ) -> Result < Option < Box < RawValue > > , Error > {
89+ pub async fn get_proposal ( & self ) -> Result < Option < Value > , Error > {
9190 let message = self . call ( "GetProposal" , & ( ) ) . await ?;
9291 try_from_message ( message)
9392 }
@@ -104,21 +103,18 @@ impl Client {
104103 }
105104
106105 pub async fn set_config ( & self , config : Option < Config > ) -> Result < ( ) , Error > {
107- let config = config. filter ( |c| c. is_some ( ) ) ;
106+ let config = config. filter ( |c| c. has_value ( ) ) ;
108107 let json = serde_json:: to_string ( & config) ?;
109108 self . call ( "SetConfig" , & ( json) ) . await ?;
110109 Ok ( ( ) )
111110 }
112111
113- pub async fn set_config_model ( & self , model : Box < RawValue > ) -> Result < ( ) , Error > {
112+ pub async fn set_config_model ( & self , model : Value ) -> Result < ( ) , Error > {
114113 self . call ( "SetConfigModel" , & ( model. to_string ( ) ) ) . await ?;
115114 Ok ( ( ) )
116115 }
117116
118- pub async fn solve_config_model (
119- & self ,
120- model : Box < RawValue > ,
121- ) -> Result < Option < Box < RawValue > > , Error > {
117+ pub async fn solve_config_model ( & self , model : Value ) -> Result < Option < Value > , Error > {
122118 let message = self . call ( "SolveConfigModel" , & ( model. to_string ( ) ) ) . await ?;
123119 try_from_message ( message)
124120 }
@@ -145,19 +141,11 @@ impl Client {
145141fn try_from_message < T : serde:: de:: DeserializeOwned + Default > (
146142 message : Message ,
147143) -> Result < T , Error > {
148- let json: String = message. body ( ) . deserialize ( ) ?;
149- if is_json_null ( & json) {
144+ let raw_json: String = message. body ( ) . deserialize ( ) ?;
145+ let json: Value = serde_json:: from_str ( & raw_json) ?;
146+ if json. is_null ( ) {
150147 return Ok ( T :: default ( ) ) ;
151148 }
152- let value = serde_json:: from_str ( & json) ?;
149+ let value = serde_json:: from_value ( json) ?;
153150 Ok ( value)
154151}
155-
156- fn is_json_null ( value : & str ) -> bool {
157- let value = serde_json:: from_str :: < Value > ( value) ;
158- match value {
159- Ok ( Value :: Null ) => true ,
160- Ok ( _) => false ,
161- Err ( _) => false ,
162- }
163- }
0 commit comments