@@ -74,7 +74,13 @@ pub struct SettingsInput {
7474impl SettingsInput {
7575 pub ( crate ) fn new ( input : impl Into < String > ) -> Self {
7676 let input = input. into ( ) ;
77- let parsed_url = Url :: parse ( & input) . ok ( ) ;
77+ let parsed_url = match Url :: parse ( & input) {
78+ Ok ( url) => Some ( url) ,
79+ Err ( err) => {
80+ log:: debug!( "URL parse failed for '{}': {}" , input, err) ;
81+ None
82+ }
83+ } ;
7884 SettingsInput { input, parsed_url }
7985 }
8086}
@@ -89,39 +95,33 @@ where
8995 resolver. resolve ( ) . await . context ( ResolverFailureSnafu )
9096}
9197
98+ /// Macro to try multiple settings resolver types in sequence, returning the first one that succeeds.
99+ macro_rules! try_resolvers {
100+ ( $input: expr, $( $resolver_type: ty) ,+ $( , ) ?) => {
101+ $(
102+ if let Ok ( r) = <$resolver_type>:: try_from( $input) {
103+ log:: debug!( "select_resolver: picked {}" , stringify!( $resolver_type) ) ;
104+ return Ok ( Box :: new( r) ) ;
105+ }
106+ ) +
107+ } ;
108+ }
109+
92110/// Choose which UriResolver applies to `input` (stdin, file://, http(s)://, s3://, secretsmanager://, and ssm://).
93111fn select_resolver ( input : & SettingsInput ) -> Result < Box < dyn crate :: uri_resolver:: UriResolver > > {
94- use crate :: uri_resolver;
95-
96- // stdin ("-")
97- if let Ok ( r) = uri_resolver:: StdinUri :: try_from ( input) {
98- return Ok ( Box :: new ( r) ) ;
99- }
100-
101- // file://
102- if let Ok ( r) = uri_resolver:: FileUri :: try_from ( input) {
103- return Ok ( Box :: new ( r) ) ;
104- }
105-
106- // http(s)://
107- if let Ok ( r) = uri_resolver:: HttpUri :: try_from ( input) {
108- return Ok ( Box :: new ( r) ) ;
109- }
110-
111- // s3://
112- if let Ok ( r) = uri_resolver:: S3Uri :: try_from ( input) {
113- return Ok ( Box :: new ( r) ) ;
114- }
115-
116- // secretsmanager://
117- if let Ok ( r) = uri_resolver:: SecretsManagerUri :: try_from ( input) {
118- return Ok ( Box :: new ( r) ) ;
119- }
120-
121- // ssm://
122- if let Ok ( r) = uri_resolver:: SsmUri :: try_from ( input) {
123- return Ok ( Box :: new ( r) ) ;
124- }
112+ use crate :: uri_resolver:: * ;
113+
114+ try_resolvers ! (
115+ input,
116+ StdinUri ,
117+ FileUri ,
118+ HttpUri ,
119+ S3Uri ,
120+ SecretsManagerArn ,
121+ SecretsManagerUri ,
122+ SsmArn ,
123+ SsmUri ,
124+ ) ;
125125
126126 error:: NoResolverSnafu {
127127 input_source : input. input . clone ( ) ,
@@ -266,13 +266,15 @@ mod resolver_selection_tests {
266266 use std:: any:: { Any , TypeId } ;
267267 use test_case:: test_case;
268268
269- #[ test_case( "-" , TypeId :: of:: <crate :: uri_resolver:: StdinUri >( ) ; "stdin" ) ]
270- #[ test_case( "file:///tmp/folder" , TypeId :: of:: <crate :: uri_resolver:: FileUri >( ) ; "file" ) ]
271- #[ test_case( "http://amazon.com" , TypeId :: of:: <crate :: uri_resolver:: HttpUri >( ) ; "http" ) ]
272- #[ test_case( "https://amazon.com" , TypeId :: of:: <crate :: uri_resolver:: HttpUri >( ) ; "https" ) ]
273- #[ test_case( "s3://mybucket/path" , TypeId :: of:: <crate :: uri_resolver:: S3Uri >( ) ; "s3" ) ]
274- #[ test_case( "secretsmanager://sec" , TypeId :: of:: <crate :: uri_resolver:: SecretsManagerUri >( ) ; "secrets" ) ]
275- #[ test_case( "ssm://param" , TypeId :: of:: <crate :: uri_resolver:: SsmUri >( ) ; "ssm" ) ]
269+ #[ test_case( "-" , TypeId :: of:: <crate :: uri_resolver:: StdinUri >( ) ; "stdin" ) ]
270+ #[ test_case( "file:///tmp/folder" , TypeId :: of:: <crate :: uri_resolver:: FileUri >( ) ; "file" ) ]
271+ #[ test_case( "http://amazon.com" , TypeId :: of:: <crate :: uri_resolver:: HttpUri >( ) ; "http" ) ]
272+ #[ test_case( "https://amazon.com" , TypeId :: of:: <crate :: uri_resolver:: HttpUri >( ) ; "https" ) ]
273+ #[ test_case( "s3://mybucket/path" , TypeId :: of:: <crate :: uri_resolver:: S3Uri >( ) ; "s3" ) ]
274+ #[ test_case( "secretsmanager://sec" , TypeId :: of:: <crate :: uri_resolver:: SecretsManagerUri >( ) ; "secrets" ) ]
275+ #[ test_case( "ssm://param" , TypeId :: of:: <crate :: uri_resolver:: SsmUri >( ) ; "ssmUri" ) ]
276+ #[ test_case( "arn:aws:ssm:<region>:<account_id>:parameter/<name>" , TypeId :: of:: <crate :: uri_resolver:: SsmArn >( ) ; "ssmArn" ) ]
277+ #[ test_case( "arn:aws:secretsmanager:<region>:<account-id>:secret:<secret-id>" , TypeId :: of:: <crate :: uri_resolver:: SecretsManagerArn >( ) ; "secretsmanagerArn" ) ]
276278
277279 fn resolver_selection ( input : & str , expected : std:: any:: TypeId ) {
278280 let settings = SettingsInput :: new ( input) ;
0 commit comments