@@ -75,14 +75,18 @@ public class Args {
7575 private final int port ;
7676 private final Properties vaultPaths ;
7777 private final Properties vaultPasswords ;
78- private final Properties vaultPasswordfiles ;
78+ private final Properties vaultPasswordFiles ;
79+
80+ private boolean hasPasswordOrPasswordFile (Object vaultPath ) {
81+ return vaultPasswords .containsKey (vaultPath ) || vaultPasswordFiles .containsKey (vaultPath );
82+ }
7983
8084 public Args (CommandLine commandLine ) throws ParseException {
8185 this .bindAddr = commandLine .getOptionValue ("bind" , "localhost" );
8286 this .port = Integer .parseInt (commandLine .getOptionValue ("port" , "0" ));
8387 this .vaultPaths = commandLine .getOptionProperties ("vault" );
8488 this .vaultPasswords = commandLine .getOptionProperties ("password" );
85- this .vaultPasswordfiles = commandLine .getOptionProperties ("passwordfile" );
89+ this .vaultPasswordFiles = commandLine .getOptionProperties ("passwordfile" );
8690 }
8791
8892 public String getBindAddr () {
@@ -94,27 +98,23 @@ public int getPort() {
9498 }
9599
96100 public Set <String > getVaultNames () {
97- Set <String > filteredVaults = vaultPaths .keySet ().stream ().filter (vaultPasswords ::containsKey ).map (String .class ::cast ).collect (Collectors .toSet ());
98- filteredVaults .addAll (vaultPaths .keySet ().stream ().filter (vaultPasswordfiles ::containsKey ).map (String .class ::cast ).collect (Collectors .toSet ()));
99- return filteredVaults ;
101+ return vaultPaths .keySet ().stream ().filter (this ::hasPasswordOrPasswordFile ).map (String .class ::cast ).collect (Collectors .toSet ());
100102 }
101103
102104 public String getVaultPath (String vaultName ) {
103105 return vaultPaths .getProperty (vaultName );
104106 }
105107
106- public String getVaultPasswordPath (String vaultName ) { return vaultPasswordfiles .getProperty (vaultName ); }
108+ public String getVaultPasswordPath (String vaultName ) {
109+ return vaultPasswordFiles .getProperty (vaultName );
110+ }
107111
108112 public String getVaultPassword (String vaultName ) {
109113 if (vaultPasswords .getProperty (vaultName ) == null ){
110- Path vaultPasswordPath = Paths .get (vaultPasswordfiles .getProperty (vaultName ));
114+ Path vaultPasswordPath = Paths .get (vaultPasswordFiles .getProperty (vaultName ));
111115 if (Files .isReadable (vaultPasswordPath ) && Files .isRegularFile (vaultPasswordPath )){
112116 try (Stream <String > lines = Files .lines (vaultPasswordPath )) {
113- String vaultPassword = lines .findFirst ().get ().toString ();
114- if (vaultPassword != "" ) {
115- return vaultPassword ;
116- }
117- return null ;
117+ return lines .findFirst ().get ().toString ();
118118 } catch (IOException e ) {
119119 return null ;
120120 }
0 commit comments