openvidu-server: OpenviduConfig checks final parameters in use

pull/391/head
pabloFuente 2020-01-29 12:02:27 +01:00
parent 2cbdcb9251
commit 0a87de0afd
1 changed files with 33 additions and 24 deletions

View File

@ -35,16 +35,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
import org.kurento.jsonrpc.JsonUtils; import org.kurento.jsonrpc.JsonUtils;
@ -53,10 +50,19 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.BuildProperties;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import io.openvidu.java.client.OpenViduRole; import io.openvidu.java.client.OpenViduRole;
import io.openvidu.server.OpenViduServer; import io.openvidu.server.OpenViduServer;
import io.openvidu.server.cdr.CDREventName; import io.openvidu.server.cdr.CDREventName;
@ -186,6 +192,9 @@ public class OpenviduConfig {
public static List<CDREventName> webhookEventsList = new ArrayList<>(); public static List<CDREventName> webhookEventsList = new ArrayList<>();
public static Properties externalizedProperties; public static Properties externalizedProperties;
@Autowired
protected Environment env;
public List<String> getKmsUris() { public List<String> getKmsUris() {
return kmsUrisList; return kmsUrisList;
} }
@ -389,8 +398,8 @@ public class OpenviduConfig {
try { try {
Inet6Address.getByName(inetAddress).getHostAddress(); Inet6Address.getByName(inetAddress).getHostAddress();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
throw new Exception("String value: ''" + inetAddress + "' with key: '" + key + throw new Exception("String value: ''" + inetAddress + "' with key: '" + key
"' is not a valid Internet Address (IP or Domain Name): " + e.getMessage()); + "' is not a valid Internet Address (IP or Domain Name): " + e.getMessage());
} }
} }
} }
@ -573,7 +582,9 @@ public class OpenviduConfig {
case "openvidu.recording.composed-url": case "openvidu.recording.composed-url":
String composedUrl = checkString(parameters, parameter); String composedUrl = checkString(parameters, parameter);
try { try {
if (!composedUrl.isEmpty()) {
checkUrl(composedUrl); checkUrl(composedUrl);
}
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Property 'openvidu.recording.composed-url' not valid. " + e.getMessage()); throw new Exception("Property 'openvidu.recording.composed-url' not valid. " + e.getMessage());
} }
@ -805,21 +816,8 @@ public class OpenviduConfig {
@PostConstruct @PostConstruct
protected void init() { protected void init() {
// Check configuration parameters // Check configuration parameters
Map<String, ?> props = null; Map<String, ?> props = getFinalPropertiesInUse();
if (!this.springConfigLocation.isEmpty()) {
try {
externalizedProperties = this.retrieveExternalizedProperties();
props = (Map) this.externalizedProperties;
} catch (Exception e) {
log.error(e.getMessage());
log.error("Shutting down OpenVidu Server");
System.exit(1);
}
} else {
props = (Map) System.getProperties();
}
try { try {
this.checkConfigurationParameters(props, OPENVIDU_PROPERTIES, true); this.checkConfigurationParameters(props, OPENVIDU_PROPERTIES, true);
@ -895,6 +893,17 @@ public class OpenviduConfig {
} }
protected Map<String, Object> getFinalPropertiesInUse() {
final SortedMap<String, Object> props = new TreeMap<>();
for (final PropertySource<?> propertySource : ((AbstractEnvironment) env).getPropertySources()) {
if (!(propertySource instanceof EnumerablePropertySource))
continue;
for (final String name : ((EnumerablePropertySource<?>) propertySource).getPropertyNames())
props.computeIfAbsent(name, propertySource::getProperty);
}
return props;
}
private String listToQuotedStringifiedArray(List<String> list) { private String listToQuotedStringifiedArray(List<String> list) {
return "[" + list.stream().map(s -> "\"" + s + "\"").collect(Collectors.joining(", ")) + "]"; return "[" + list.stream().map(s -> "\"" + s + "\"").collect(Collectors.joining(", ")) + "]";
} }