@@ -79,18 +79,14 @@ pub type Result<T> = std::result::Result<T, Error>;
79
79
#[ derive( Debug ) ]
80
80
pub struct Client {
81
81
connection : Connection ,
82
+
82
83
/// The client's configuration.
83
84
pub config : Config ,
84
85
}
85
86
86
87
/// Configuration for a client.
87
- #[ derive( Debug , Clone , Copy ) ]
88
+ #[ derive( Debug , Clone ) ]
88
89
pub struct Config {
89
- /// Whether to enable the s3 credential chain, which allows s3:// url access.
90
- ///
91
- /// True by default.
92
- pub use_s3_credential_chain : bool ,
93
-
94
90
/// Whether to enable hive partitioning.
95
91
///
96
92
/// False by default.
@@ -100,6 +96,25 @@ pub struct Config {
100
96
///
101
97
/// Disable this to enable geopandas reading, for example.
102
98
pub convert_wkb : bool ,
99
+
100
+ /// Whether to enable the S3 credential chain, which allows s3:// url access.
101
+ ///
102
+ /// True by default.
103
+ pub use_s3_credential_chain : bool ,
104
+
105
+ /// Whether to enable the Azure credential chain, which allows az:// url access.
106
+ ///
107
+ /// True by default.
108
+ pub use_azure_credential_chain : bool ,
109
+
110
+ /// Whether to directly install the httpfs extension.
111
+ pub use_httpfs : bool ,
112
+
113
+ /// Whether to install extensions when creating a new connection.
114
+ pub install_extensions : bool ,
115
+
116
+ /// Use a custom extension repository.
117
+ pub custom_extension_repository : Option < String > ,
103
118
}
104
119
105
120
/// A SQL query.
@@ -167,21 +182,45 @@ impl Client {
167
182
/// use stac_duckdb::{Client, Config};
168
183
///
169
184
/// let config = Config {
170
- /// use_s3_credential_chain: true,
171
185
/// use_hive_partitioning: true,
172
186
/// convert_wkb: true,
187
+ /// use_s3_credential_chain: true,
188
+ /// use_azure_credential_chain: true,
189
+ /// use_httpfs: true,
190
+ /// install_extensions: true,
191
+ /// custom_extension_repository: None,
173
192
/// };
174
193
/// let client = Client::with_config(config);
175
194
/// ```
176
195
pub fn with_config ( config : Config ) -> Result < Client > {
177
196
let connection = Connection :: open_in_memory ( ) ?;
178
- connection. execute ( "INSTALL spatial" , [ ] ) ?;
197
+ if let Some ( ref custom_extension_repository) = config. custom_extension_repository {
198
+ connection. execute (
199
+ "SET custom_extension_repository = '?'" ,
200
+ [ custom_extension_repository] ,
201
+ ) ?;
202
+ }
203
+ if config. install_extensions {
204
+ connection. execute ( "INSTALL spatial" , [ ] ) ?;
205
+ connection. execute ( "INSTALL icu" , [ ] ) ?;
206
+ }
179
207
connection. execute ( "LOAD spatial" , [ ] ) ?;
180
- connection. execute ( "INSTALL icu" , [ ] ) ?;
181
208
connection. execute ( "LOAD icu" , [ ] ) ?;
209
+ if config. use_httpfs && config. install_extensions {
210
+ connection. execute ( "INSTALL httpfs" , [ ] ) ?;
211
+ }
182
212
if config. use_s3_credential_chain {
213
+ if config. install_extensions {
214
+ connection. execute ( "INSTALL aws" , [ ] ) ?;
215
+ }
183
216
connection. execute ( "CREATE SECRET (TYPE S3, PROVIDER CREDENTIAL_CHAIN)" , [ ] ) ?;
184
217
}
218
+ if config. use_azure_credential_chain {
219
+ if config. install_extensions {
220
+ connection. execute ( "INSTALL azure" , [ ] ) ?;
221
+ }
222
+ connection. execute ( "CREATE SECRET (TYPE azure, PROVIDER CREDENTIAL_CHAIN)" , [ ] ) ?;
223
+ }
185
224
Ok ( Client { connection, config } )
186
225
}
187
226
@@ -519,15 +558,19 @@ impl Default for Config {
519
558
fn default ( ) -> Self {
520
559
Config {
521
560
use_hive_partitioning : false ,
522
- use_s3_credential_chain : true ,
523
561
convert_wkb : true ,
562
+ use_s3_credential_chain : true ,
563
+ use_azure_credential_chain : true ,
564
+ use_httpfs : true ,
565
+ install_extensions : true ,
566
+ custom_extension_repository : None ,
524
567
}
525
568
}
526
569
}
527
570
528
571
#[ cfg( test) ]
529
572
mod tests {
530
- use super :: Client ;
573
+ use super :: { Client , Config } ;
531
574
use geo:: Geometry ;
532
575
use rstest:: { fixture, rstest} ;
533
576
use stac:: { Bbox , Validate } ;
@@ -542,6 +585,19 @@ mod tests {
542
585
Client :: new ( ) . unwrap ( )
543
586
}
544
587
588
+ #[ test]
589
+ fn no_install ( ) {
590
+ let _mutex = MUTEX . lock ( ) . unwrap ( ) ;
591
+ let config = Config {
592
+ install_extensions : false ,
593
+ ..Default :: default ( )
594
+ } ;
595
+ let client = Client :: with_config ( config) . unwrap ( ) ;
596
+ client
597
+ . search ( "data/100-sentinel-2-items.parquet" , Search :: default ( ) )
598
+ . unwrap ( ) ;
599
+ }
600
+
545
601
#[ rstest]
546
602
fn search_all ( client : Client ) {
547
603
let item_collection = client
0 commit comments