Add dotenv path to allow updating file when restart

pull/431/head
micaelgallego 2020-04-09 17:14:37 +02:00
parent 0a36927836
commit 8c1703aa54
3 changed files with 240 additions and 239 deletions

View File

@ -18,7 +18,6 @@
package io.openvidu.server.config;
import java.io.File;
import java.io.IOException;
import java.net.Inet6Address;
import java.net.MalformedURLException;
import java.net.URI;
@ -51,7 +50,6 @@ import com.google.gson.JsonSyntaxException;
import io.openvidu.java.client.OpenViduRole;
import io.openvidu.server.OpenViduServer;
import io.openvidu.server.cdr.CDREventName;
import io.openvidu.server.config.Dotenv.DotenvFormatException;
import io.openvidu.server.recording.RecordingNotification;
@Component
@ -105,8 +103,6 @@ public class OpenviduConfig {
@Autowired
protected Environment env;
protected Dotenv dotenv;
@Value("#{'${spring.profiles.active:}'.length() > 0 ? '${spring.profiles.active:}'.split(',') : \"default\"}")
protected String springProfile;
@ -172,6 +168,8 @@ public class OpenviduConfig {
protected int openviduSessionsGarbageThreshold;
private String dotenvPath;
// Derived properties
public static String finalUrl;
@ -290,6 +288,10 @@ public class OpenviduConfig {
return openviduSessionsGarbageThreshold;
}
public String getDotenvPath() {
return dotenvPath;
}
// Derived properties methods
public String getSpringProfile() {
@ -371,13 +373,9 @@ public class OpenviduConfig {
Object valueObj = propertiesSource.get(property);
if (valueObj != null) {
if(valueObj instanceof Iterable) {
value = JsonUtils.toJson(valueObj);
} else {
value = valueObj.toString();
}
}
}
if (value == null) {
value = env.getProperty(property);
@ -410,16 +408,6 @@ public class OpenviduConfig {
@PostConstruct
public void checkConfiguration() {
dotenv = new Dotenv();
try {
dotenv.read();
} catch (IOException e) {
log.warn("Exception reading .env file. " + e.getClass() + ":" + e.getMessage());
} catch (DotenvFormatException e) {
log.warn("Format error in .env file. " + e.getClass() + ":" + e.getMessage());
}
try {
this.checkConfigurationProperties();
} catch (Exception e) {
@ -441,6 +429,8 @@ public class OpenviduConfig {
protected void checkConfigurationProperties() {
serverPort = getValue("server.port");
coturnRedisDbname = getValue("coturn.redis.dbname");
@ -484,6 +474,7 @@ public class OpenviduConfig {
checkCertificateType();
dotenvPath = getValue("dotenv.path");
}
private void checkCertificateType() {

View File

@ -1,5 +1,4 @@
{
"properties": [
{"properties": [
{
"name": "kms.uris",
"type": "java.lang.String",
@ -213,6 +212,15 @@
"type": "java.lang.Long",
"description": "Maximum number of websocket sessions that openvidu-server will be able to hold",
"defaultValue": 9223372036854775807
},
{
"name": "certificate.type",
"type": "java.lang.String",
"description": "A description for 'certificate.type'"
},
{
"name": "dotenvpath",
"type": "java.lang.String",
"description": "A description for 'dotenvpath'"
}
]
}
]}

View File

@ -44,3 +44,5 @@ coturn.redis.ip=127.0.0.1
coturn.redis.dbname=0
coturn.redis.password=turn
coturn.redis.connect-timeout=30
dotenv.path=.