Skip to content

Commit 78f2d74

Browse files
committed
requested changes to last commit
1 parent 409c69a commit 78f2d74

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/main/java/org/cryptomator/cli/Args.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main/java/org/cryptomator/cli/CryptomatorCli.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ private static void validate(Args args) throws IllegalArgumentException {
4949

5050
for (String vaultName : args.getVaultNames()) {
5151
Path vaultPath = Paths.get(args.getVaultPath(vaultName));
52-
if ((args.getVaultPasswordPath(vaultName) != null) && args.getVaultPassword(vaultName) == null)
53-
{
52+
if ((args.getVaultPasswordPath(vaultName) != null) && args.getVaultPassword(vaultName) == null) {
5453
throw new IllegalArgumentException("Cannot read password from file: " + Paths.get(args.getVaultPasswordPath(vaultName)));
5554
}
5655
if (!Files.isDirectory(vaultPath)) {

0 commit comments

Comments
 (0)