File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ fn snapshot_digest(
57
57
mod handlers {
58
58
use crate :: http_server:: routes:: reply;
59
59
use crate :: http_server:: SERVER_BASE_PATH ;
60
- use crate :: message_adapters:: ToSnapshotMessageAdapter ;
60
+ use crate :: message_adapters:: { ToSnapshotListMessageAdapter , ToSnapshotMessageAdapter } ;
61
61
use crate :: { Configuration , SnapshotStore } ;
62
62
use slog_scope:: { debug, warn} ;
63
63
use std:: convert:: Infallible ;
@@ -72,7 +72,10 @@ mod handlers {
72
72
debug ! ( "⇄ HTTP SERVER: snapshots" ) ;
73
73
74
74
match snapshot_store. list_snapshots ( ) . await {
75
- Ok ( snapshots) => Ok ( reply:: json ( & snapshots, StatusCode :: OK ) ) ,
75
+ Ok ( snapshots) => Ok ( reply:: json (
76
+ & ToSnapshotListMessageAdapter :: adapt ( snapshots) ,
77
+ StatusCode :: OK ,
78
+ ) ) ,
76
79
Err ( err) => {
77
80
warn ! ( "snapshots::error" ; "error" => ?err) ;
78
81
Ok ( reply:: internal_server_error ( err. to_string ( ) ) )
Original file line number Diff line number Diff line change @@ -3,11 +3,13 @@ mod from_register_signer;
3
3
mod to_certificate_message;
4
4
mod to_certificate_pending_message;
5
5
mod to_epoch_settings_message;
6
+ mod to_snapshot_list_message;
6
7
mod to_snasphot_message;
7
8
8
9
pub use from_register_signature:: FromRegisterSingleSignatureAdapter ;
9
10
pub use from_register_signer:: FromRegisterSignerAdapter ;
10
11
pub use to_certificate_message:: ToCertificateMessageAdapter ;
11
12
pub use to_certificate_pending_message:: ToCertificatePendingMessageAdapter ;
12
13
pub use to_epoch_settings_message:: ToEpochSettingsMessageAdapter ;
14
+ pub use to_snapshot_list_message:: ToSnapshotListMessageAdapter ;
13
15
pub use to_snasphot_message:: ToSnapshotMessageAdapter ;
Original file line number Diff line number Diff line change
1
+ use mithril_common:: entities:: Snapshot ;
2
+ use mithril_common:: messages:: { SnapshotListItemMessage , SnapshotListMessage } ;
3
+
4
+ /// Adapter to convert a list of [Snapshot] to [SnapshotListMessage] instances
5
+ pub struct ToSnapshotListMessageAdapter ;
6
+
7
+ impl ToSnapshotListMessageAdapter {
8
+ /// Method to trigger the conversion
9
+ pub fn adapt ( snapshots : Vec < Snapshot > ) -> SnapshotListMessage {
10
+ snapshots
11
+ . into_iter ( )
12
+ . map ( |snapshot| SnapshotListItemMessage {
13
+ digest : snapshot. digest ,
14
+ beacon : snapshot. beacon ,
15
+ certificate_hash : snapshot. certificate_hash ,
16
+ size : snapshot. size ,
17
+ created_at : snapshot. created_at ,
18
+ locations : snapshot. locations ,
19
+ } )
20
+ . collect ( )
21
+ }
22
+ }
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use mithril_common:: test_utils:: fake_data;
27
+
28
+ use super :: * ;
29
+
30
+ #[ test]
31
+ fn adapt_ok ( ) {
32
+ let mut snapshot = fake_data:: snapshots ( 1 ) [ 0 ] . to_owned ( ) ;
33
+ snapshot. digest = "digest123" . to_string ( ) ;
34
+ let snapshot_list_message = ToSnapshotListMessageAdapter :: adapt ( vec ! [ snapshot] ) ;
35
+
36
+ assert_eq ! ( "digest123" . to_string( ) , snapshot_list_message[ 0 ] . digest) ;
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments