mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
Merge pull request #5720 from gdicristofaro/6171-warningsOnAbsentSettings
6171 don't raise warning if settings not located
This commit is contained in:
commit
78f35401da
@ -63,9 +63,21 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
|
|
||||||
private CentralRepoPostgresSettingsUtil() {}
|
private CentralRepoPostgresSettingsUtil() {}
|
||||||
|
|
||||||
private void logException(TryHandler handler) {
|
/**
|
||||||
|
* Uses setter object to set a value as specified by 'value'. In the event that 'value'
|
||||||
|
* is null, the setter will not be called. Exceptions that are raised from the setter will
|
||||||
|
* be logged.
|
||||||
|
*
|
||||||
|
* @param setter The setter to call.
|
||||||
|
* @param value The value to use with the setter.
|
||||||
|
*/
|
||||||
|
private void setValOrLog(ValueSetter setter, String value) {
|
||||||
|
// ignore null values as they indicate a setting that is not set yet
|
||||||
|
if (value == null || value.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
handler.operation();
|
setter.set(value);
|
||||||
}
|
}
|
||||||
catch (CentralRepoException | NumberFormatException e) {
|
catch (CentralRepoException | NumberFormatException e) {
|
||||||
LOGGER.log(Level.WARNING, "There was an error in converting central repo postgres settings", e);
|
LOGGER.log(Level.WARNING, "There was an error in converting central repo postgres settings", e);
|
||||||
@ -73,10 +85,10 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface represents an action that potentially throws an exception.
|
* This interface represents a setter that potentially throws an exception.
|
||||||
*/
|
*/
|
||||||
private interface TryHandler {
|
private interface ValueSetter {
|
||||||
void operation() throws CentralRepoException, NumberFormatException;
|
void set(String value) throws CentralRepoException, NumberFormatException;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,15 +108,12 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
logException(() -> settings.setHost(muConn.getHost()));
|
setValOrLog((v) -> settings.setHost(v), muConn.getHost());
|
||||||
logException(() -> settings.setDbName(PostgresConnectionSettings.DEFAULT_DBNAME));
|
setValOrLog((v) -> settings.setUserName(v), muConn.getUserName());
|
||||||
logException(() -> settings.setUserName(muConn.getUserName()));
|
setValOrLog((v) -> settings.setPassword(v), muConn.getPassword());
|
||||||
|
|
||||||
logException(() -> settings.setPort(Integer.parseInt(muConn.getPort())));
|
|
||||||
logException(() -> settings.setBulkThreshold(RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD));
|
|
||||||
|
|
||||||
logException(() -> settings.setPassword(muConn.getPassword()));
|
|
||||||
|
|
||||||
|
setValOrLog((v) -> settings.setPort(Integer.parseInt(v)), muConn.getPort());
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,24 +129,27 @@ public class CentralRepoPostgresSettingsUtil {
|
|||||||
Map<String, String> keyVals = ModuleSettings.getConfigSettings(MODULE_KEY);
|
Map<String, String> keyVals = ModuleSettings.getConfigSettings(MODULE_KEY);
|
||||||
|
|
||||||
|
|
||||||
logException(() -> settings.setHost(keyVals.get(HOST_KEY)));
|
setValOrLog((v) -> settings.setHost(v), keyVals.get(HOST_KEY));
|
||||||
logException(() -> settings.setDbName(keyVals.get(DBNAME_KEY)));
|
setValOrLog((v) -> settings.setDbName(v), keyVals.get(DBNAME_KEY));
|
||||||
logException(() -> settings.setUserName(keyVals.get(USER_KEY)));
|
setValOrLog((v) -> settings.setUserName(v), keyVals.get(USER_KEY));
|
||||||
|
|
||||||
logException(() -> settings.setPort(Integer.parseInt(keyVals.get(PORT_KEY))));
|
setValOrLog((v) -> settings.setPort(Integer.parseInt(v)), keyVals.get(PORT_KEY));
|
||||||
logException(() -> settings.setBulkThreshold(Integer.parseInt(keyVals.get((BULK_THRESHOLD_KEY)))));
|
setValOrLog((v) -> settings.setBulkThreshold(Integer.parseInt(v)), keyVals.get((BULK_THRESHOLD_KEY)));
|
||||||
|
|
||||||
String passwordHex = keyVals.get(PASSWORD_KEY);
|
String passwordHex = keyVals.get(PASSWORD_KEY);
|
||||||
String password;
|
if (passwordHex != null) {
|
||||||
try {
|
String password;
|
||||||
password = TextConverter.convertHexTextToText(passwordHex);
|
try {
|
||||||
} catch (TextConverterException ex) {
|
password = TextConverter.convertHexTextToText(passwordHex);
|
||||||
LOGGER.log(Level.WARNING, "Failed to convert password from hex text to text.", ex);
|
} catch (TextConverterException ex) {
|
||||||
password = null;
|
LOGGER.log(Level.WARNING, "Failed to convert password from hex text to text.", ex);
|
||||||
|
password = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String finalPassword = password;
|
||||||
|
setValOrLog((v) -> settings.setPassword(v), finalPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String finalPassword = password;
|
|
||||||
logException(() -> settings.setPassword(finalPassword));
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user