-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor secret key file reader into separate class and add cli utility…
… to generate value used
- Loading branch information
1 parent
4fc6683
commit 33c15fa
Showing
3 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
fgpJava org.gusdb.wdk.model.config.SecretKeyReader $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Model/src/main/java/org/gusdb/wdk/model/config/SecretKeyReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.gusdb.wdk.model.config; | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Optional; | ||
|
||
import org.gusdb.fgputil.EncryptionUtil; | ||
import org.gusdb.fgputil.IoUtil; | ||
|
||
public class SecretKeyReader { | ||
|
||
public static void main(String[] args) { | ||
if (args.length != 1) { | ||
System.err.println("USAGE: readSecretKey <path-to-secret-key-file>"); | ||
System.exit(1); | ||
} | ||
Path path = Paths.get(args[0]); | ||
try { | ||
System.out.print(readSecretKey(Optional.of(path))); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(System.err); | ||
System.exit(2); | ||
} | ||
} | ||
|
||
public static String readSecretKey(Optional<Path> secretKeyFile) throws IOException { | ||
try (FileReader in = new FileReader(secretKeyFile.get().toFile())) { | ||
return EncryptionUtil.md5(IoUtil.readAllChars(in).strip()); | ||
} | ||
} | ||
|
||
} |