7
7
import io .scalecube .config .ConfigSourceNotAvailableException ;
8
8
import io .scalecube .config .source .ConfigSource ;
9
9
import io .scalecube .config .source .LoadedConfigProperty ;
10
+ import java .util .ArrayList ;
11
+ import java .util .Arrays ;
12
+ import java .util .HashMap ;
13
+ import java .util .List ;
10
14
import java .util .Map ;
11
15
import java .util .Objects ;
12
16
import java .util .function .Function ;
@@ -27,31 +31,35 @@ public class VaultConfigSource implements ConfigSource {
27
31
private static final String VAULT_SECRETS_PATH = "VAULT_SECRETS_PATH" ;
28
32
29
33
private final VaultInvoker vault ;
30
- private final String secretsPath ;
34
+ private final List < String > secretsPath ;
31
35
32
36
/**
33
37
* Create a new {@link VaultConfigSource}.
34
- *
35
- * @param vault vault invoker.
36
- * @param secretsPath secret path.
38
+ * @param vault vault invoker.
39
+ * @param secretsPaths secret path-s.
37
40
*/
38
- private VaultConfigSource (VaultInvoker vault , String secretsPath ) {
41
+ private VaultConfigSource (VaultInvoker vault , List < String > secretsPaths ) {
39
42
this .vault = vault ;
40
- this .secretsPath = secretsPath ;
43
+ this .secretsPath = secretsPaths ;
41
44
}
42
45
43
46
@ Override
44
47
public Map <String , ConfigProperty > loadConfig () {
45
- try {
46
- LogicalResponse response = vault .invoke (vault -> vault .logical ().read (secretsPath ));
47
- return response .getData ().entrySet ().stream ()
48
- .map (LoadedConfigProperty ::withNameAndValue )
49
- .map (LoadedConfigProperty .Builder ::build )
50
- .collect (Collectors .toMap (LoadedConfigProperty ::name , Function .identity ()));
51
- } catch (Exception ex ) {
52
- LOGGER .warn ("unable to load config properties" , ex );
53
- throw new ConfigSourceNotAvailableException (ex );
48
+ Map <String , ConfigProperty > result = new HashMap <>();
49
+ for (String path : secretsPath ) {
50
+ try {
51
+ LogicalResponse response = vault .invoke (vault -> vault .logical ().read (path ));
52
+ final Map <String , LoadedConfigProperty > pathProps = response .getData ().entrySet ().stream ()
53
+ .map (LoadedConfigProperty ::withNameAndValue )
54
+ .map (LoadedConfigProperty .Builder ::build )
55
+ .collect (Collectors .toMap (LoadedConfigProperty ::name , Function .identity ()));
56
+ result .putAll (pathProps );
57
+ } catch (Exception ex ) {
58
+ LOGGER .warn ("unable to load config properties from {}" ,path , ex );
59
+ throw new ConfigSourceNotAvailableException (ex );
60
+ }
54
61
}
62
+ return result ;
55
63
}
56
64
57
65
/**
@@ -87,12 +95,12 @@ public static final class Builder {
87
95
private Function <VaultInvoker .Builder , VaultInvoker .Builder > vault = Function .identity ();
88
96
private VaultInvoker invoker ;
89
97
private EnvironmentLoader environmentLoader = VaultInvoker .Builder .ENVIRONMENT_LOADER ;
90
- private String secretsPath ;
98
+ private List < String > secretsPaths = new ArrayList <>() ;
91
99
92
100
private Builder () {}
93
101
94
102
public Builder secretsPath (String secretsPath ) {
95
- this .secretsPath = secretsPath ;
103
+ this .secretsPaths . add ( secretsPath ) ;
96
104
return this ;
97
105
}
98
106
@@ -126,13 +134,13 @@ public VaultConfigSource build() {
126
134
invoker != null
127
135
? invoker
128
136
: vault .apply (new VaultInvoker .Builder (environmentLoader )).build ();
129
- secretsPath =
130
- Objects . requireNonNull (
131
- secretsPath != null
132
- ? secretsPath
133
- : environmentLoader . loadVariable ( VAULT_SECRETS_PATH ),
134
- "Missing secretsPath" );
135
- return new VaultConfigSource (vaultInvoker , secretsPath );
137
+ if ( secretsPaths . isEmpty ()) {
138
+ String envSecretPath = Objects
139
+ . requireNonNull ( environmentLoader . loadVariable ( VAULT_SECRETS_PATH ),
140
+ "Missing secretsPath" );
141
+ secretsPaths = Arrays . asList ( envSecretPath . split ( ":" ));
142
+ }
143
+ return new VaultConfigSource (vaultInvoker , secretsPaths );
136
144
}
137
145
}
138
146
}
0 commit comments