Update config properties management to support OpenViduPro

pull/431/head
micaelgallego 2020-04-06 18:00:48 +02:00
parent 92464bc25c
commit 5dfe8ff601
2 changed files with 40 additions and 22 deletions

View File

@ -221,7 +221,7 @@ public class OpenViduServer implements JsonRpcConfigurer {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
checkConfigProperties(); checkConfigProperties(OpenviduConfig.class);
log.info("Using /dev/urandom for secure random generation"); log.info("Using /dev/urandom for secure random generation");
System.setProperty("java.security.egd", "file:/dev/./urandom"); System.setProperty("java.security.egd", "file:/dev/./urandom");
@ -229,9 +229,9 @@ public class OpenViduServer implements JsonRpcConfigurer {
} }
private static void checkConfigProperties() throws InterruptedException { public static <T> void checkConfigProperties(Class<T> configClass) throws InterruptedException {
ConfigurableApplicationContext app = SpringApplication.run(OpenviduConfig.class, ConfigurableApplicationContext app = SpringApplication.run(configClass,
new String[] { "--spring.main.web-application-type=none" }); new String[] { "--spring.main.web-application-type=none" });
OpenviduConfig config = app.getBean(OpenviduConfig.class); OpenviduConfig config = app.getBean(OpenviduConfig.class);
List<Error> errors = config.getConfigErrors(); List<Error> errors = config.getConfigErrors();

View File

@ -381,13 +381,18 @@ public class OpenviduConfig {
} }
userConfigProps = new ArrayList<>(configProps.keySet()); userConfigProps = new ArrayList<>(configProps.keySet());
userConfigProps.removeAll(Arrays.asList("coturn.ip", "coturn.redis.ip", "kms.uris", "server.port",
"coturn.redis.dbname", "coturn.redis.password", "coturn.redis.connect-timeout")); userConfigProps.removeAll(getNonUserProperties());
}
protected List<String> getNonUserProperties() {
return Arrays.asList("coturn.ip", "coturn.redis.ip", "kms.uris", "server.port",
"coturn.redis.dbname", "coturn.redis.password", "coturn.redis.connect-timeout");
} }
// Properties // Properties
public void checkConfigurationParameters() throws Exception { protected void checkConfigurationParameters() {
serverPort = getConfigValue("server.port"); serverPort = getConfigValue("server.port");
@ -429,6 +434,9 @@ public class OpenviduConfig {
checkCertificateType(); checkCertificateType();
openviduSessionsGarbageInterval = asNonNegativeInteger("openvidu.sessions.garbage.interval");
openviduSessionsGarbageThreshold = asNonNegativeInteger("openvidu.sessions.garbage.threshold");
} }
private void checkCertificateType() { private void checkCertificateType() {
@ -453,7 +461,6 @@ public class OpenviduConfig {
try { try {
this.coturnIp = new URL(this.getFinalUrl()).getHost(); this.coturnIp = new URL(this.getFinalUrl()).getHost();
log.info("Coturn IP: " + coturnIp);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
log.error("Can't get Domain name from OpenVidu public Url: " + e.getMessage()); log.error("Can't get Domain name from OpenVidu public Url: " + e.getMessage());
} }
@ -461,7 +468,7 @@ public class OpenviduConfig {
} }
private void checkWebhook() throws Exception { private void checkWebhook() {
openviduWebhookEnabled = asBoolean("openvidu.webhook"); openviduWebhookEnabled = asBoolean("openvidu.webhook");
openviduWebhookEndpoint = asOptionalURL("openvidu.webhook.endpoint"); openviduWebhookEndpoint = asOptionalURL("openvidu.webhook.endpoint");
@ -474,7 +481,7 @@ public class OpenviduConfig {
} }
} }
private void checkOpenviduRecordingNotification() throws Exception { private void checkOpenviduRecordingNotification() {
String recordingNotif = asNonEmptyString("openvidu.recording.notification"); String recordingNotif = asNonEmptyString("openvidu.recording.notification");
try { try {
@ -485,7 +492,7 @@ public class OpenviduConfig {
} }
} }
private void checkOpenviduPublicurl() throws Exception { private void checkOpenviduPublicurl() {
final String property = "openvidu.domain.or.public.ip"; final String property = "openvidu.domain.or.public.ip";
@ -551,10 +558,6 @@ public class OpenviduConfig {
} else if (publicUrl.startsWith("http://")) { } else if (publicUrl.startsWith("http://")) {
OpenViduServer.wsUrl = publicUrl.replace("http://", "wss://"); OpenViduServer.wsUrl = publicUrl.replace("http://", "wss://");
} }
if (!publicUrl.startsWith("wss://")) {
OpenViduServer.wsUrl = "wss://" + publicUrl;
}
} }
if (OpenViduServer.wsUrl == null) { if (OpenViduServer.wsUrl == null) {
@ -654,7 +657,7 @@ public class OpenviduConfig {
// Format Checkers // Format Checkers
// ------------------------------------------------------- // -------------------------------------------------------
private String asOptionalURL(String property) { protected String asOptionalURL(String property) {
String optionalUrl = getConfigValue(property); String optionalUrl = getConfigValue(property);
try { try {
@ -668,7 +671,7 @@ public class OpenviduConfig {
} }
} }
public String asNonEmptyString(String property) { protected String asNonEmptyString(String property) {
String stringValue = getConfigValue(property); String stringValue = getConfigValue(property);
@ -680,7 +683,11 @@ public class OpenviduConfig {
} }
} }
public boolean asBoolean(String property) { protected String asOptionalString(String property) {
return getConfigValue(property);
}
protected boolean asBoolean(String property) {
String value = getConfigValue(property); String value = getConfigValue(property);
@ -697,7 +704,7 @@ public class OpenviduConfig {
} }
} }
public Integer asNonNegativeInteger(String property) { protected Integer asNonNegativeInteger(String property) {
try { try {
Integer integerValue = Integer.parseInt(getConfigValue(property)); Integer integerValue = Integer.parseInt(getConfigValue(property));
@ -714,7 +721,7 @@ public class OpenviduConfig {
/* /*
* This method checks all types of internet addresses (IPv4, IPv6 and Domains) * This method checks all types of internet addresses (IPv4, IPv6 and Domains)
*/ */
public String asOptionalInetAddress(String property) { protected String asOptionalInetAddress(String property) {
String inetAddress = getConfigValue(property); String inetAddress = getConfigValue(property);
if (inetAddress != null && !inetAddress.isEmpty()) { if (inetAddress != null && !inetAddress.isEmpty()) {
try { try {
@ -726,7 +733,7 @@ public class OpenviduConfig {
return inetAddress; return inetAddress;
} }
public String asFileSystemPath(String property) { protected String asFileSystemPath(String property) {
try { try {
String stringPath = this.asNonEmptyString(property); String stringPath = this.asNonEmptyString(property);
Paths.get(stringPath); Paths.get(stringPath);
@ -740,7 +747,7 @@ public class OpenviduConfig {
} }
} }
public List<String> asJsonStringsArray(String property) { protected List<String> asJsonStringsArray(String property) {
try { try {
@ -758,6 +765,17 @@ public class OpenviduConfig {
} }
} }
protected <E extends Enum<E>> E asEnumValue(String property, Class<E> enumType) {
String value = this.getConfigValue(property);
try {
return Enum.valueOf(enumType, value);
} catch (IllegalArgumentException e) {
addError(property, "Must be one of " + Arrays.asList(enumType.getEnumConstants()));
return null;
}
}
public URI checkWebsocketUri(String uri) throws Exception { public URI checkWebsocketUri(String uri) throws Exception {
try { try {
if (!uri.startsWith("ws://") || uri.startsWith("wss://")) { if (!uri.startsWith("ws://") || uri.startsWith("wss://")) {
@ -771,7 +789,7 @@ public class OpenviduConfig {
} }
} }
public void checkUrl(String url) throws Exception { protected void checkUrl(String url) throws Exception {
try { try {
new URL(url).toURI(); new URL(url).toURI();
} catch (MalformedURLException | URISyntaxException e) { } catch (MalformedURLException | URISyntaxException e) {