@@ -37,7 +37,11 @@ use tokio::sync::RwLock;
37
37
use sos_backup_archive:: RestoreTargets ;
38
38
39
39
#[ cfg( feature = "audit" ) ]
40
- use { sos_audit:: AuditEvent , sos_backend:: audit:: append_audit_events} ;
40
+ use {
41
+ sos_audit:: { AuditData , AuditEvent } ,
42
+ sos_backend:: audit:: append_audit_events,
43
+ sos_core:: events:: EventKind ,
44
+ } ;
41
45
42
46
use sos_core:: {
43
47
device:: { DevicePublicKey , TrustedDevice } ,
@@ -1738,6 +1742,7 @@ impl ClientStorage {
1738
1742
& mut self ,
1739
1743
events : Vec < DeviceEvent > ,
1740
1744
) -> Result < ( ) > {
1745
+ // Update the event log
1741
1746
let mut event_log = self . device_log . write ( ) . await ;
1742
1747
event_log. apply ( events. iter ( ) . collect ( ) ) . await ?;
1743
1748
@@ -1746,6 +1751,25 @@ impl ClientStorage {
1746
1751
let devices = reducer. reduce ( ) . await ?;
1747
1752
self . devices = devices;
1748
1753
1754
+ #[ cfg( feature = "audit" ) ]
1755
+ {
1756
+ let audit_events = events
1757
+ . iter ( )
1758
+ . filter_map ( |event| match event {
1759
+ DeviceEvent :: Trust ( device) => Some ( AuditEvent :: new (
1760
+ Default :: default ( ) ,
1761
+ EventKind :: TrustDevice ,
1762
+ * self . account_id ( ) ,
1763
+ Some ( AuditData :: Device ( * device. public_key ( ) ) ) ,
1764
+ ) ) ,
1765
+ _ => None ,
1766
+ } )
1767
+ . collect :: < Vec < _ > > ( ) ;
1768
+ if !audit_events. is_empty ( ) {
1769
+ append_audit_events ( audit_events. as_slice ( ) ) . await ?;
1770
+ }
1771
+ }
1772
+
1749
1773
Ok ( ( ) )
1750
1774
}
1751
1775
0 commit comments