2020-02-06 22:17:14 +01:00
|
|
|
package envoy.client.data;
|
2019-10-30 06:26:50 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
2020-02-06 22:17:14 +01:00
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.util.function.Function;
|
2019-12-21 11:35:01 +01:00
|
|
|
import java.util.logging.Level;
|
2019-10-30 06:26:50 +01:00
|
|
|
|
2020-03-05 14:27:40 +01:00
|
|
|
import envoy.data.Config;
|
|
|
|
import envoy.data.ConfigItem;
|
2020-02-06 22:17:14 +01:00
|
|
|
import envoy.data.LoginCredentials;
|
2019-12-13 08:50:15 +01:00
|
|
|
|
2019-10-30 06:26:50 +01:00
|
|
|
/**
|
2020-03-05 14:27:40 +01:00
|
|
|
* Implements a configuration specific to the Envoy Client with default values
|
|
|
|
* and convenience methods.<br>
|
2019-12-20 20:25:54 +01:00
|
|
|
* <br>
|
2019-10-30 06:26:50 +01:00
|
|
|
* Project: <strong>envoy-client</strong><br>
|
2020-03-05 14:27:40 +01:00
|
|
|
* File: <strong>ClientConfig.java</strong><br>
|
|
|
|
* Created: <strong>01.03.2020</strong><br>
|
2019-12-20 20:25:54 +01:00
|
|
|
*
|
2019-10-30 06:26:50 +01:00
|
|
|
* @author Kai S. K. Engelbart
|
2020-03-05 14:27:40 +01:00
|
|
|
* @since Envoy v0.1-beta
|
2019-10-30 06:26:50 +01:00
|
|
|
*/
|
2020-03-05 14:27:40 +01:00
|
|
|
public class ClientConfig extends Config {
|
2019-10-30 06:26:50 +01:00
|
|
|
|
2020-03-05 14:27:40 +01:00
|
|
|
private static ClientConfig config;
|
2019-11-09 14:23:26 +01:00
|
|
|
|
2020-03-05 14:27:40 +01:00
|
|
|
/**
|
|
|
|
* @return the singleton instance of the client config
|
|
|
|
* @since Envoy v0.1-beta
|
|
|
|
*/
|
|
|
|
public static ClientConfig getInstance() {
|
|
|
|
if (config == null) config = new ClientConfig();
|
|
|
|
return config;
|
|
|
|
}
|
2019-11-09 14:23:26 +01:00
|
|
|
|
2020-03-05 14:27:40 +01:00
|
|
|
private ClientConfig() {
|
2020-02-06 22:17:14 +01:00
|
|
|
items.put("server", new ConfigItem<>("server", "s", Function.identity(), null, true));
|
|
|
|
items.put("port", new ConfigItem<>("port", "p", Integer::parseInt, null, true));
|
|
|
|
items.put("localDB", new ConfigItem<>("localDB", "db", File::new, new File("localDB"), true));
|
|
|
|
items.put("ignoreLocalDB", new ConfigItem<>("ignoreLocalDB", "nodb", Boolean::parseBoolean, false, false));
|
|
|
|
items.put("homeDirectory", new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy"), true));
|
|
|
|
items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.CONFIG, true));
|
|
|
|
items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINEST, true));
|
|
|
|
items.put("user", new ConfigItem<>("user", "u", Function.identity()));
|
|
|
|
items.put("password", new ConfigItem<>("password", "pw", String::toCharArray));
|
2019-12-21 11:35:01 +01:00
|
|
|
}
|
2019-11-09 14:23:26 +01:00
|
|
|
|
2019-10-30 06:26:50 +01:00
|
|
|
/**
|
2019-10-30 17:01:55 +01:00
|
|
|
* @return the host name of the Envoy server
|
2019-10-30 06:26:50 +01:00
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public String getServer() { return (String) items.get("server").get(); }
|
2019-10-30 06:26:50 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-30 17:01:55 +01:00
|
|
|
* @return the port at which the Envoy server is located on the host
|
2019-10-30 06:26:50 +01:00
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2020-02-01 10:20:06 +01:00
|
|
|
public Integer getPort() { return (Integer) items.get("port").get(); }
|
2019-10-30 06:26:50 +01:00
|
|
|
|
2019-10-30 07:45:33 +01:00
|
|
|
/**
|
2019-10-30 17:01:55 +01:00
|
|
|
* @return the local database specific to the client user
|
|
|
|
* @since Envoy v0.1-alpha
|
2019-12-21 12:36:26 +01:00
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public File getLocalDB() { return (File) items.get("localDB").get(); }
|
2019-11-09 14:23:26 +01:00
|
|
|
|
2020-02-03 21:52:48 +01:00
|
|
|
/**
|
|
|
|
* @return {@code true} if the local database is to be ignored
|
|
|
|
* @since Envoy v0.3-alpha
|
|
|
|
*/
|
|
|
|
public Boolean isIgnoreLocalDB() { return (Boolean) items.get("ignoreLocalDB").get(); }
|
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* @return the directory in which all local files are saves
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public File getHomeDirectory() { return (File) items.get("homeDirectory").get(); }
|
2019-12-21 18:19:10 +01:00
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* @return the minimal {@link Level} to log inside the log file
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public Level getFileLevelBarrier() { return (Level) items.get("fileLevelBarrier").get(); }
|
2019-12-21 18:19:10 +01:00
|
|
|
|
2019-12-21 12:20:23 +01:00
|
|
|
/**
|
|
|
|
* @return the minimal {@link Level} to log inside the console
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
2019-12-21 11:35:01 +01:00
|
|
|
public Level getConsoleLevelBarrier() { return (Level) items.get("consoleLevelBarrier").get(); }
|
2020-02-06 22:17:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the user name
|
|
|
|
* @since Envoy v0.3-alpha
|
|
|
|
*/
|
|
|
|
public String getUser() { return (String) items.get("user").get(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the password
|
|
|
|
* @since Envoy v0.3-alpha
|
|
|
|
*/
|
|
|
|
public char[] getPassword() { return (char[]) items.get("password").get(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {@code true} if user name and password are set
|
|
|
|
* @since Envoy v0.3-alpha
|
|
|
|
*/
|
|
|
|
public boolean hasLoginCredentials() { return getUser() != null && getPassword() != null; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return login credentials for the specified user name and password, without
|
|
|
|
* the registration option
|
|
|
|
* @since Envoy v0.3-alpha
|
|
|
|
*/
|
|
|
|
public LoginCredentials getLoginCredentials() {
|
|
|
|
try {
|
|
|
|
return new LoginCredentials(getUser(), getPassword(), false);
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 14:27:40 +01:00
|
|
|
}
|