@@ -27,7 +27,8 @@ pub fn search(
27
27
} else {
28
28
search. limit = None ;
29
29
} ;
30
- let client = Client :: new ( ) ?;
30
+ let config = Config :: from_href ( href) ;
31
+ let client = Client :: with_config ( config) ?;
31
32
client. search_to_json ( href, search)
32
33
}
33
34
@@ -163,6 +164,26 @@ pub struct Extension {
163
164
pub installed_from : Option < String > ,
164
165
}
165
166
167
+ impl Config {
168
+ /// Creates a configuration from an href.
169
+ ///
170
+ /// Use this to, e.g., autodetect s3 urls.
171
+ ///
172
+ /// # Examples
173
+ ///
174
+ /// ```
175
+ /// use stac_duckdb::Config;
176
+ /// let config = Config::from_href("s3://bucket/item.json");
177
+ /// assert!(config.use_s3_credential_chain);
178
+ /// ```
179
+ pub fn from_href ( s : & str ) -> Config {
180
+ Config {
181
+ use_s3_credential_chain : s. starts_with ( "s3://" ) ,
182
+ ..Default :: default ( )
183
+ }
184
+ }
185
+ }
186
+
166
187
impl Client {
167
188
/// Creates a new client with no data sources.
168
189
///
@@ -199,33 +220,42 @@ impl Client {
199
220
pub fn with_config ( config : Config ) -> Result < Client > {
200
221
let connection = Connection :: open_in_memory ( ) ?;
201
222
if let Some ( ref custom_extension_repository) = config. custom_extension_repository {
223
+ log:: debug!( "setting custom extension repository: {custom_extension_repository}" ) ;
202
224
connection. execute (
203
225
"SET custom_extension_repository = ?" ,
204
226
[ custom_extension_repository] ,
205
227
) ?;
206
228
}
207
229
if let Some ( ref extension_directory) = config. extension_directory {
230
+ log:: debug!( "setting extension directory: {extension_directory}" ) ;
208
231
connection. execute ( "SET extension_directory = ?" , [ extension_directory] ) ?;
209
232
}
210
233
if config. install_extensions {
234
+ log:: debug!( "installing spatial" ) ;
211
235
connection. execute ( "INSTALL spatial" , [ ] ) ?;
236
+ log:: debug!( "installing icu" ) ;
212
237
connection. execute ( "INSTALL icu" , [ ] ) ?;
213
238
}
214
239
connection. execute ( "LOAD spatial" , [ ] ) ?;
215
240
connection. execute ( "LOAD icu" , [ ] ) ?;
216
241
if config. use_httpfs && config. install_extensions {
242
+ log:: debug!( "installing httpfs" ) ;
217
243
connection. execute ( "INSTALL httpfs" , [ ] ) ?;
218
244
}
219
245
if config. use_s3_credential_chain {
220
246
if config. install_extensions {
247
+ log:: debug!( "installing aws" ) ;
221
248
connection. execute ( "INSTALL aws" , [ ] ) ?;
222
249
}
250
+ log:: debug!( "creating s3 secret" ) ;
223
251
connection. execute ( "CREATE SECRET (TYPE S3, PROVIDER CREDENTIAL_CHAIN)" , [ ] ) ?;
224
252
}
225
253
if config. use_azure_credential_chain {
226
254
if config. install_extensions {
255
+ log:: debug!( "installing azure" ) ;
227
256
connection. execute ( "INSTALL azure" , [ ] ) ?;
228
257
}
258
+ log:: debug!( "creating azure secret" ) ;
229
259
connection. execute ( "CREATE SECRET (TYPE azure, PROVIDER CREDENTIAL_CHAIN)" , [ ] ) ?;
230
260
}
231
261
Ok ( Client { connection, config } )
@@ -566,9 +596,9 @@ impl Default for Config {
566
596
Config {
567
597
use_hive_partitioning : false ,
568
598
convert_wkb : true ,
569
- use_s3_credential_chain : true ,
570
- use_azure_credential_chain : true ,
571
- use_httpfs : true ,
599
+ use_s3_credential_chain : false ,
600
+ use_azure_credential_chain : false ,
601
+ use_httpfs : false ,
572
602
install_extensions : true ,
573
603
custom_extension_repository : None ,
574
604
extension_directory : None ,
0 commit comments