@@ -27,7 +27,8 @@ pub fn search(
2727 } else {
2828 search. limit = None ;
2929 } ;
30- let client = Client :: new ( ) ?;
30+ let config = Config :: from_href ( href) ;
31+ let client = Client :: with_config ( config) ?;
3132 client. search_to_json ( href, search)
3233}
3334
@@ -163,6 +164,26 @@ pub struct Extension {
163164 pub installed_from : Option < String > ,
164165}
165166
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+
166187impl Client {
167188 /// Creates a new client with no data sources.
168189 ///
@@ -199,33 +220,42 @@ impl Client {
199220 pub fn with_config ( config : Config ) -> Result < Client > {
200221 let connection = Connection :: open_in_memory ( ) ?;
201222 if let Some ( ref custom_extension_repository) = config. custom_extension_repository {
223+ log:: debug!( "setting custom extension repository: {custom_extension_repository}" ) ;
202224 connection. execute (
203225 "SET custom_extension_repository = ?" ,
204226 [ custom_extension_repository] ,
205227 ) ?;
206228 }
207229 if let Some ( ref extension_directory) = config. extension_directory {
230+ log:: debug!( "setting extension directory: {extension_directory}" ) ;
208231 connection. execute ( "SET extension_directory = ?" , [ extension_directory] ) ?;
209232 }
210233 if config. install_extensions {
234+ log:: debug!( "installing spatial" ) ;
211235 connection. execute ( "INSTALL spatial" , [ ] ) ?;
236+ log:: debug!( "installing icu" ) ;
212237 connection. execute ( "INSTALL icu" , [ ] ) ?;
213238 }
214239 connection. execute ( "LOAD spatial" , [ ] ) ?;
215240 connection. execute ( "LOAD icu" , [ ] ) ?;
216241 if config. use_httpfs && config. install_extensions {
242+ log:: debug!( "installing httpfs" ) ;
217243 connection. execute ( "INSTALL httpfs" , [ ] ) ?;
218244 }
219245 if config. use_s3_credential_chain {
220246 if config. install_extensions {
247+ log:: debug!( "installing aws" ) ;
221248 connection. execute ( "INSTALL aws" , [ ] ) ?;
222249 }
250+ log:: debug!( "creating s3 secret" ) ;
223251 connection. execute ( "CREATE SECRET (TYPE S3, PROVIDER CREDENTIAL_CHAIN)" , [ ] ) ?;
224252 }
225253 if config. use_azure_credential_chain {
226254 if config. install_extensions {
255+ log:: debug!( "installing azure" ) ;
227256 connection. execute ( "INSTALL azure" , [ ] ) ?;
228257 }
258+ log:: debug!( "creating azure secret" ) ;
229259 connection. execute ( "CREATE SECRET (TYPE azure, PROVIDER CREDENTIAL_CHAIN)" , [ ] ) ?;
230260 }
231261 Ok ( Client { connection, config } )
@@ -566,9 +596,9 @@ impl Default for Config {
566596 Config {
567597 use_hive_partitioning : false ,
568598 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 ,
572602 install_extensions : true ,
573603 custom_extension_repository : None ,
574604 extension_directory : None ,
0 commit comments