2020
2121//! This module implements Agama's HTTP API.
2222
23- use crate :: {
24- supervisor:: { self , message, ConfigScope , Scope , Service , SystemInfo } ,
25- web:: EventsSender ,
26- } ;
27- use agama_lib:: { error:: ServiceError , install_settings:: InstallSettings } ;
23+ use agama_lib:: { error:: ServiceError , http, install_settings:: InstallSettings } ;
24+ use agama_manager:: { self as manager, message, ConfigScope , Scope , SystemInfo } ;
2825use agama_utils:: actor:: Handler ;
2926use anyhow;
3027use axum:: {
@@ -44,7 +41,7 @@ pub enum Error {
4441 #[ error( "The given configuration does not belong to the '{0}' scope." ) ]
4542 Scope ( Scope ) ,
4643 #[ error( transparent) ]
47- Supervisor ( #[ from] supervisor :: service:: Error ) ,
44+ Manager ( #[ from] manager :: service:: Error ) ,
4845}
4946
5047impl IntoResponse for Error {
@@ -66,7 +63,7 @@ fn to_option_response<T: Serialize>(value: Option<T>) -> Response {
6663
6764#[ derive( Clone ) ]
6865pub struct ServerState {
69- supervisor : Handler < Service > ,
66+ manager : Handler < manager :: Service > ,
7067}
7168
7269type ServerResult < T > = Result < T , Error > ;
@@ -77,14 +74,14 @@ type ServerResult<T> = Result<T, Error>;
7774/// * `dbus`: connection to Agama's D-Bus server. If it is not given, those features
7875/// that require to connect to the Agama's D-Bus server won't work.
7976pub async fn server_service (
80- events : EventsSender ,
77+ events : http :: event :: Sender ,
8178 dbus : Option < zbus:: Connection > ,
8279) -> Result < Router , ServiceError > {
83- let supervisor = supervisor :: start ( events, dbus)
80+ let manager = manager :: start ( events, dbus)
8481 . await
8582 . map_err ( |e| anyhow:: Error :: new ( e) ) ?;
8683
87- let state = ServerState { supervisor } ;
84+ let state = ServerState { manager } ;
8885
8986 Ok ( Router :: new ( )
9087 . route ( "/status" , get ( get_status) )
@@ -118,7 +115,7 @@ pub async fn server_service(
118115 )
119116) ]
120117async fn get_status ( State ( state) : State < ServerState > ) -> ServerResult < Json < message:: Status > > {
121- let status = state. supervisor . call ( message:: GetStatus ) . await ?;
118+ let status = state. manager . call ( message:: GetStatus ) . await ?;
122119 Ok ( Json ( status) )
123120}
124121
@@ -133,7 +130,7 @@ async fn get_status(State(state): State<ServerState>) -> ServerResult<Json<messa
133130 )
134131) ]
135132async fn get_system ( State ( state) : State < ServerState > ) -> ServerResult < Json < SystemInfo > > {
136- let system = state. supervisor . call ( message:: GetSystem ) . await ?;
133+ let system = state. manager . call ( message:: GetSystem ) . await ?;
137134 Ok ( Json ( system) )
138135}
139136
@@ -150,7 +147,7 @@ async fn get_system(State(state): State<ServerState>) -> ServerResult<Json<Syste
150147async fn get_extended_config (
151148 State ( state) : State < ServerState > ,
152149) -> ServerResult < Json < InstallSettings > > {
153- let config = state. supervisor . call ( message:: GetExtendedConfig ) . await ?;
150+ let config = state. manager . call ( message:: GetExtendedConfig ) . await ?;
154151 Ok ( Json ( config) )
155152}
156153
@@ -172,7 +169,7 @@ async fn get_extended_config_scope(
172169 Path ( scope) : Path < Scope > ,
173170) -> ServerResult < Response > {
174171 let config = state
175- . supervisor
172+ . manager
176173 . call ( message:: GetExtendedConfigScope :: new ( scope) )
177174 . await ?;
178175 Ok ( to_option_response ( config) )
@@ -189,7 +186,7 @@ async fn get_extended_config_scope(
189186 )
190187) ]
191188async fn get_config ( State ( state) : State < ServerState > ) -> ServerResult < Json < InstallSettings > > {
192- let config = state. supervisor . call ( message:: GetConfig ) . await ?;
189+ let config = state. manager . call ( message:: GetConfig ) . await ?;
193190 Ok ( Json ( config) )
194191}
195192
@@ -211,7 +208,7 @@ async fn get_config_scope(
211208 Path ( scope) : Path < Scope > ,
212209) -> ServerResult < Response > {
213210 let config = state
214- . supervisor
211+ . manager
215212 . call ( message:: GetConfigScope :: new ( scope) )
216213 . await ?;
217214 Ok ( to_option_response ( config) )
@@ -236,10 +233,7 @@ async fn put_config(
236233 State ( state) : State < ServerState > ,
237234 Json ( config) : Json < InstallSettings > ,
238235) -> ServerResult < ( ) > {
239- state
240- . supervisor
241- . call ( message:: SetConfig :: new ( config) )
242- . await ?;
236+ state. manager . call ( message:: SetConfig :: new ( config) ) . await ?;
243237 Ok ( ( ) )
244238}
245239
@@ -263,7 +257,7 @@ async fn patch_config(
263257 Json ( config) : Json < InstallSettings > ,
264258) -> ServerResult < ( ) > {
265259 state
266- . supervisor
260+ . manager
267261 . call ( message:: UpdateConfig :: new ( config) )
268262 . await ?;
269263 Ok ( ( ) )
@@ -295,7 +289,7 @@ async fn put_config_scope(
295289 }
296290
297291 state
298- . supervisor
292+ . manager
299293 . call ( message:: SetConfigScope :: new ( config_scope) )
300294 . await ?;
301295 Ok ( ( ) )
@@ -327,7 +321,7 @@ async fn patch_config_scope(
327321 }
328322
329323 state
330- . supervisor
324+ . manager
331325 . call ( message:: UpdateConfigScope :: new ( config_scope) )
332326 . await ?;
333327 Ok ( ( ) )
@@ -344,7 +338,7 @@ async fn patch_config_scope(
344338 )
345339) ]
346340async fn get_proposal ( State ( state) : State < ServerState > ) -> ServerResult < Response > {
347- let proposal = state. supervisor . call ( message:: GetProposal ) . await ?;
341+ let proposal = state. manager . call ( message:: GetProposal ) . await ?;
348342 Ok ( to_option_response ( proposal) )
349343}
350344
@@ -359,7 +353,7 @@ async fn get_proposal(State(state): State<ServerState>) -> ServerResult<Response
359353 )
360354) ]
361355async fn get_issues ( State ( state) : State < ServerState > ) -> ServerResult < Json < IssuesMap > > {
362- let issues = state. supervisor . call ( message:: GetIssues ) . await ?;
356+ let issues = state. manager . call ( message:: GetIssues ) . await ?;
363357 let issues_map: IssuesMap = issues. into ( ) ;
364358 Ok ( Json ( issues_map) )
365359}
@@ -380,9 +374,6 @@ async fn run_action(
380374 State ( state) : State < ServerState > ,
381375 Json ( action) : Json < message:: Action > ,
382376) -> ServerResult < ( ) > {
383- state
384- . supervisor
385- . call ( message:: RunAction :: new ( action) )
386- . await ?;
377+ state. manager . call ( message:: RunAction :: new ( action) ) . await ?;
387378 Ok ( ( ) )
388379}
0 commit comments