Skip to content

Commit

Permalink
Update Configuration File Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Sep 29, 2022
1 parent 6c940c2 commit 2b3577a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 8 deletions.
Binary file modified Data Engine/Documents/Internal Manual/Packet Spreadsheet.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class Config {
static {
properties = new HashMap<String, Properties>();

String[] files = new File("config").list();
String[] files = new File("src/main/resources/config").list();

for(String file : files) {
if(file.lastIndexOf(".properties") == file.length() - 11) {
String name = file.substring(0, file.length() - 11);
properties.put(name, new Properties());

try (FileInputStream in = new FileInputStream("config/" + file)) {
try (FileInputStream in = new FileInputStream("src/main/resources/config/" + file)) {
properties.get(name).load(in);
} catch(Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void defineRequestTypes() {
public String getHash(String data) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] bytes = md.digest(("salt" + System.currentTimeMillis() + data).getBytes());
byte[] bytes = md.digest(("salt" + data).getBytes());
BigInteger signum = new BigInteger(1, bytes);
String hashed = signum.toString(16);
while(hashed.length() < 32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ mongodb.database.main=main-db
mongodb.auth.collection=auth-collection

# query delim
mongodb.query.delim=,
mongodb.query.delim=,

# === POLYGON PROPERTIES ===

# request delim
polygon.request.delim=-
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class Config {
static {
properties = new HashMap<String, Properties>();

String[] files = new File("config").list();
String[] files = new File("src/main/resources/config").list();

for(String file : files) {
if(file.lastIndexOf(".properties") == file.length() - 11) {
String name = file.substring(0, file.length() - 11);
properties.put(name, new Properties());

try (FileInputStream in = new FileInputStream("config/" + file)) {
try (FileInputStream in = new FileInputStream("src/main/resources/config/" + file)) {
properties.get(name).load(in);
} catch(Exception e) {
e.printStackTrace();
Expand All @@ -39,15 +39,20 @@ public static final String getProperty(String name, String property) {
return properties.get(name).getProperty(property);
}

public static final void setProperty(String name, String property, String value) {
validate(name, property);
properties.get(name).setProperty(property, value);
}

public static final void validate(String name, String... keys) {
if(!properties.containsKey(name)) {
System.err.println(String.format("Property file <%s> does not exist. Program terminating.", name));
new IllegalArgumentException(String.format("Property file <%s> does not exist. Program terminating.", name)).printStackTrace();
System.exit(1);
}

for(String key : keys)
if(!properties.get(name).containsKey(key)) {
System.err.println(String.format("Missing property <%s> in file <%s>. Program terminating.", key, name));
new IllegalArgumentException(String.format("Missing property <%s> in file <%s>. Program terminating.", key, name)).printStackTrace();
System.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void run() {
System.out.println("INIT RESPONSE: " + request("http://localhost:8080/defi/v1/rest/initialize?source=external_template&auth_data=key"));
System.out.println("STREAM_EXISTS RESPONSE: " + request("http://localhost:8080/defi/v1/rest/stream_exists?key=key"));
System.out.println("IS_AUTHORIZED RESPONSE: " + request("http://localhost:8080/defi/v1/rest/is_authorized?key=key"));

System.out.println("RQST RESPONSE: " + request(
String.format("http://localhost:8080/defi/v1/rest/request_dated?destination=%s"
+ "&key=key"
Expand Down

0 comments on commit 2b3577a

Please sign in to comment.