@@ -5,7 +5,8 @@ cfg_core! {
5
5
use super :: DbType ;
6
6
use crate :: { Database , Result } ;
7
7
8
- pub use crate :: sync:: EncryptionContext ;
8
+ #[ cfg( any( feature = "remote" , feature = "sync" ) ) ]
9
+ pub use crate :: database:: EncryptionContext ;
9
10
10
11
/// A builder for [`Database`]. This struct can be used to build
11
12
/// all variants of [`Database`]. These variants include:
@@ -52,8 +53,6 @@ impl Builder<()> {
52
53
path: impl AsRef <std:: path:: Path >,
53
54
url: String ,
54
55
auth_token: String ,
55
- #[ cfg( feature = "sync" ) ]
56
- remote_encryption: Option <crate :: sync:: EncryptionContext >,
57
56
) -> Builder <RemoteReplica > {
58
57
Builder {
59
58
inner: RemoteReplica {
@@ -64,6 +63,8 @@ impl Builder<()> {
64
63
connector: None ,
65
64
version: None ,
66
65
namespace: None ,
66
+ #[ cfg( any( feature = "remote" , feature = "sync" ) ) ]
67
+ remote_encryption: None ,
67
68
} ,
68
69
encryption_config: None ,
69
70
read_your_writes: true ,
@@ -73,7 +74,7 @@ impl Builder<()> {
73
74
#[ cfg( feature = "sync" ) ]
74
75
sync_protocol: Default :: default ( ) ,
75
76
#[ cfg( feature = "sync" ) ]
76
- remote_encryption,
77
+ remote_encryption: None
77
78
} ,
78
79
}
79
80
}
@@ -98,7 +99,6 @@ impl Builder<()> {
98
99
path: impl AsRef <std:: path:: Path >,
99
100
url: String ,
100
101
auth_token: String ,
101
- remote_encryption: Option <EncryptionContext >,
102
102
) -> Builder <SyncedDatabase > {
103
103
Builder {
104
104
inner: SyncedDatabase {
@@ -110,13 +110,14 @@ impl Builder<()> {
110
110
connector: None ,
111
111
version: None ,
112
112
namespace: None ,
113
+ remote_encryption: None ,
113
114
} ,
114
115
connector: None ,
115
116
read_your_writes: true ,
116
117
remote_writes: false ,
117
118
push_batch_size: 0 ,
118
119
sync_interval: None ,
119
- remote_encryption,
120
+ remote_encryption: None ,
120
121
} ,
121
122
}
122
123
}
@@ -132,6 +133,7 @@ impl Builder<()> {
132
133
connector: None ,
133
134
version: None ,
134
135
namespace: None ,
136
+ remote_encryption: None ,
135
137
} ,
136
138
}
137
139
}
@@ -146,6 +148,8 @@ cfg_replication_or_remote_or_sync! {
146
148
connector: Option <crate :: util:: ConnectorService >,
147
149
version: Option <String >,
148
150
namespace: Option <String >,
151
+ #[ cfg( any( feature = "remote" , feature = "sync" ) ) ]
152
+ remote_encryption: Option <EncryptionContext >,
149
153
}
150
154
}
151
155
@@ -238,7 +242,7 @@ cfg_replication! {
238
242
#[ cfg( feature = "sync" ) ]
239
243
sync_protocol: super :: SyncProtocol ,
240
244
#[ cfg( feature = "sync" ) ]
241
- remote_encryption: Option <crate :: sync :: EncryptionContext >,
245
+ remote_encryption: Option <EncryptionContext >,
242
246
}
243
247
244
248
/// Local replica configuration type in [`Builder`].
@@ -300,6 +304,13 @@ cfg_replication! {
300
304
self
301
305
}
302
306
307
+ /// Set the encryption context if the database is encrypted in remote server.
308
+ #[ cfg( feature = "sync" ) ]
309
+ pub fn remote_encryption( mut self , encryption_context: Option <EncryptionContext >) -> Builder <RemoteReplica > {
310
+ self . inner. remote_encryption = encryption_context;
311
+ self
312
+ }
313
+
303
314
pub fn http_request_callback<F >( mut self , f: F ) -> Builder <RemoteReplica >
304
315
where
305
316
F : Fn ( & mut http:: Request <( ) >) + Send + Sync + ' static
@@ -347,6 +358,7 @@ cfg_replication! {
347
358
connector,
348
359
version,
349
360
namespace,
361
+ ..
350
362
} ,
351
363
encryption_config,
352
364
read_your_writes,
@@ -415,10 +427,11 @@ cfg_replication! {
415
427
416
428
if res. status( ) . is_success( ) {
417
429
tracing:: trace!( "Using sync protocol v2 for {}" , url) ;
418
- let builder = Builder :: new_synced_database( path, url, auth_token, remote_encryption )
430
+ let builder = Builder :: new_synced_database( path, url, auth_token)
419
431
. connector( connector)
420
432
. remote_writes( true )
421
- . read_your_writes( read_your_writes) ;
433
+ . read_your_writes( read_your_writes)
434
+ . remote_encryption( remote_encryption) ;
422
435
423
436
let builder = if let Some ( sync_interval) = sync_interval {
424
437
builder. sync_interval( sync_interval)
@@ -475,7 +488,10 @@ cfg_replication! {
475
488
476
489
477
490
Ok ( Database {
478
- db_type: DbType :: Sync { db, encryption_config } ,
491
+ db_type: DbType :: Sync {
492
+ db,
493
+ encryption_config,
494
+ } ,
479
495
max_write_replication_index: Default :: default ( ) ,
480
496
} )
481
497
}
@@ -515,6 +531,7 @@ cfg_replication! {
515
531
connector,
516
532
version,
517
533
namespace,
534
+ ..
518
535
} ) = remote
519
536
{
520
537
let connector = if let Some ( connector) = connector {
@@ -565,7 +582,7 @@ cfg_sync! {
565
582
read_your_writes: bool ,
566
583
push_batch_size: u32 ,
567
584
sync_interval: Option <std:: time:: Duration >,
568
- remote_encryption: Option <crate :: sync :: EncryptionContext >,
585
+ remote_encryption: Option <EncryptionContext >,
569
586
}
570
587
571
588
impl Builder <SyncedDatabase > {
@@ -598,6 +615,12 @@ cfg_sync! {
598
615
self
599
616
}
600
617
618
+ /// Set the encryption context if the database is encrypted in remote server.
619
+ pub fn remote_encryption( mut self , encryption_context: Option <EncryptionContext >) -> Builder <SyncedDatabase > {
620
+ self . inner. remote_encryption = encryption_context;
621
+ self
622
+ }
623
+
601
624
/// Provide a custom http connector that will be used to create http connections.
602
625
pub fn connector<C >( mut self , connector: C ) -> Builder <SyncedDatabase >
603
626
where
@@ -624,6 +647,7 @@ cfg_sync! {
624
647
connector: _,
625
648
version: _,
626
649
namespace: _,
650
+ ..
627
651
} ,
628
652
connector,
629
653
remote_writes,
@@ -759,6 +783,12 @@ cfg_remote! {
759
783
self
760
784
}
761
785
786
+ /// Set the encryption context if the database is encrypted in remote server.
787
+ pub fn remote_encryption( mut self , encryption_context: Option <EncryptionContext >) -> Builder <Remote > {
788
+ self . inner. remote_encryption = encryption_context;
789
+ self
790
+ }
791
+
762
792
/// Build the remote database client.
763
793
pub async fn build( self ) -> Result <Database > {
764
794
let Remote {
@@ -767,6 +797,7 @@ cfg_remote! {
767
797
connector,
768
798
version,
769
799
namespace,
800
+ remote_encryption,
770
801
} = self . inner;
771
802
772
803
let connector = if let Some ( connector) = connector {
@@ -789,6 +820,7 @@ cfg_remote! {
789
820
connector,
790
821
version,
791
822
namespace,
823
+ remote_encryption
792
824
} ,
793
825
max_write_replication_index: Default :: default ( ) ,
794
826
} )
0 commit comments