@@ -3,14 +3,15 @@ use std::io;
3
3
use std:: io:: ErrorKind ;
4
4
#[ cfg( test) ]
5
5
use std:: panic:: RefUnwindSafe ;
6
+ use std:: sync:: Arc ;
6
7
use std:: time:: Duration ;
7
8
8
9
use crate :: io:: utils:: check_namespace_key_validity;
9
10
use lightning:: util:: persist:: KVStore ;
10
11
use prost:: Message ;
11
12
use rand:: RngCore ;
12
13
use tokio:: runtime:: Runtime ;
13
- use vss_client:: client:: VssClient ;
14
+ use vss_client:: client:: { AuthMethod , VssClient } ;
14
15
use vss_client:: error:: VssError ;
15
16
use vss_client:: types:: {
16
17
DeleteObjectRequest , GetObjectRequest , KeyValue , ListKeyVersionsRequest , PutObjectRequest ,
@@ -35,10 +36,14 @@ pub struct VssStore {
35
36
store_id : String ,
36
37
runtime : Runtime ,
37
38
storable_builder : StorableBuilder < RandEntropySource > ,
39
+ auth_custom : Arc < dyn AuthMethod > ,
38
40
}
39
41
40
42
impl VssStore {
41
- pub ( crate ) fn new ( base_url : String , store_id : String , data_encryption_key : [ u8 ; 32 ] ) -> Self {
43
+ pub ( crate ) fn new (
44
+ base_url : String , store_id : String , data_encryption_key : [ u8 ; 32 ] ,
45
+ auth_custom : impl AuthMethod + ' static ,
46
+ ) -> Self {
42
47
let runtime = tokio:: runtime:: Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ;
43
48
let storable_builder = StorableBuilder :: new ( data_encryption_key, RandEntropySource ) ;
44
49
let retry_policy = ExponentialBackoffRetryPolicy :: new ( Duration :: from_millis ( 100 ) )
@@ -55,7 +60,7 @@ impl VssStore {
55
60
} ) as _ ) ;
56
61
57
62
let client = VssClient :: new ( & base_url, retry_policy) ;
58
- Self { client, store_id, runtime, storable_builder }
63
+ Self { client, store_id, runtime, storable_builder, auth_custom : Arc :: new ( auth_custom ) }
59
64
}
60
65
61
66
fn build_key (
@@ -118,18 +123,19 @@ impl KVStore for VssStore {
118
123
key : self . build_key ( primary_namespace, secondary_namespace, key) ?,
119
124
} ;
120
125
121
- let resp =
122
- tokio:: task:: block_in_place ( || self . runtime . block_on ( self . client . get_object ( & request) ) )
123
- . map_err ( |e| {
124
- let msg = format ! (
125
- "Failed to read from key {}/{}/{}: {}" ,
126
- primary_namespace, secondary_namespace, key, e
127
- ) ;
128
- match e {
129
- VssError :: NoSuchKeyError ( ..) => Error :: new ( ErrorKind :: NotFound , msg) ,
130
- _ => Error :: new ( ErrorKind :: Other , msg) ,
131
- }
132
- } ) ?;
126
+ let resp = tokio:: task:: block_in_place ( || {
127
+ self . runtime . block_on ( self . client . get_object ( & request, self . auth_custom . clone ( ) ) )
128
+ } )
129
+ . map_err ( |e| {
130
+ let msg = format ! (
131
+ "Failed to read from key {}/{}/{}: {}" ,
132
+ primary_namespace, secondary_namespace, key, e
133
+ ) ;
134
+ match e {
135
+ VssError :: NoSuchKeyError ( ..) => Error :: new ( ErrorKind :: NotFound , msg) ,
136
+ _ => Error :: new ( ErrorKind :: Other , msg) ,
137
+ }
138
+ } ) ?;
133
139
// unwrap safety: resp.value must be always present for a non-erroneous VSS response, otherwise
134
140
// it is an API-violation which is converted to [`VssError::InternalServerError`] in [`VssClient`]
135
141
let storable = Storable :: decode ( & resp. value . unwrap ( ) . value [ ..] ) ?;
0 commit comments