mirror of
https://github.com/linuxserver/fleet.git
synced 2026-02-20 05:11:08 +08:00
Updated properties loader to cascade through environment
This commit is contained in:
parent
b168d01c3d
commit
44ac92dfcc
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,4 +30,5 @@ out/
|
||||
config/fleet.properties
|
||||
src/main/resources/assets/js/all*.js
|
||||
src/main/resources/assets/css/all*.css
|
||||
src/main/resources/log4j2.xml
|
||||
.gradle/
|
||||
@ -11,7 +11,7 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
version = '1.0.0'
|
||||
version = '1.0.1'
|
||||
|
||||
dependencies {
|
||||
|
||||
|
||||
@ -30,42 +30,62 @@ public class FleetProperties {
|
||||
}
|
||||
|
||||
public String getDatabaseDriverClassName() {
|
||||
return properties.getProperty("fleet.database.driver");
|
||||
return getStringProperty("fleet.database.driver");
|
||||
}
|
||||
|
||||
public String getDatabaseUrl() {
|
||||
return properties.getProperty("fleet.database.url");
|
||||
return getStringProperty("fleet.database.url");
|
||||
}
|
||||
|
||||
public String getDatabaseUsername() {
|
||||
return properties.getProperty("fleet.database.username");
|
||||
return getStringProperty("fleet.database.username");
|
||||
}
|
||||
|
||||
public String getDatabasePassword() {
|
||||
return properties.getProperty("fleet.database.password");
|
||||
return getStringProperty("fleet.database.password");
|
||||
}
|
||||
|
||||
public String getAppUsername() {
|
||||
return properties.getProperty("fleet.admin.username");
|
||||
return getStringProperty("fleet.admin.username");
|
||||
}
|
||||
|
||||
public String getAppPassword() {
|
||||
return properties.getProperty("fleet.admin.password");
|
||||
return getStringProperty("fleet.admin.password");
|
||||
}
|
||||
|
||||
public int getAppPort() {
|
||||
return Integer.parseInt(properties.getProperty("fleet.app.port"));
|
||||
return Integer.parseInt(getStringProperty("fleet.app.port"));
|
||||
}
|
||||
|
||||
public int getRefreshIntervalInMinutes() {
|
||||
return Integer.parseInt(properties.getProperty("fleet.refresh.interval"));
|
||||
return Integer.parseInt(getStringProperty("fleet.refresh.interval"));
|
||||
}
|
||||
|
||||
public DockerHubCredentials getDockerHubCredentials() {
|
||||
|
||||
String username = properties.getProperty("fleet.dockerhub.username");
|
||||
String password = properties.getProperty("fleet.dockerhub.password");
|
||||
String username = getStringProperty("fleet.dockerhub.username");
|
||||
String password = getStringProperty("fleet.dockerhub.password");
|
||||
|
||||
return new DockerHubCredentials(username, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Obtains the property value from three separate sources: first from the config file. If not present, it will look
|
||||
* at the JVM runtime. If that is not present, it will finally check the system environment.
|
||||
* </p>
|
||||
*/
|
||||
private String getStringProperty(String propertyKey) {
|
||||
|
||||
String property = properties.getProperty(propertyKey);
|
||||
if (null == property) {
|
||||
|
||||
property = System.getProperty(propertyKey);
|
||||
if (null == property) {
|
||||
property = System.getenv(propertyKey);
|
||||
}
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,8 @@ class PropertiesLoader extends BaseRuntimeLoader {
|
||||
|
||||
try {
|
||||
|
||||
createConfigFileIfNotProvided();
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.load(new FileInputStream(FleetRuntime.CONFIG_BASE + "/fleet.properties"));
|
||||
|
||||
@ -64,6 +66,23 @@ class PropertiesLoader extends BaseRuntimeLoader {
|
||||
}
|
||||
}
|
||||
|
||||
private void createConfigFileIfNotProvided() {
|
||||
|
||||
try {
|
||||
|
||||
File configFile = new File(FleetRuntime.CONFIG_BASE + "/fleet.properties");
|
||||
if (!configFile.exists()) {
|
||||
|
||||
if (!configFile.createNewFile()) {
|
||||
throw new RuntimeException("Unable to create base config for fleet.");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to create base config for fleet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean createStaticFileDirectory() {
|
||||
|
||||
File staticFilesDir = new File(FleetRuntime.CONFIG_BASE + "/fleet_static");
|
||||
@ -94,7 +113,7 @@ class PropertiesLoader extends BaseRuntimeLoader {
|
||||
* @return
|
||||
* All application properties.
|
||||
*/
|
||||
protected FleetProperties getProperties() {
|
||||
FleetProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +53,9 @@ public class WebServer {
|
||||
path("/admin", configureAuthorisationRoute("/getImage"));
|
||||
|
||||
after("/api/v1/*", (request, response) -> {
|
||||
|
||||
response.header("Access-Control-Allow-Origin", "*");
|
||||
response.header("Access-Control-Allow-Methods", "GET");
|
||||
response.header("Content-Type", "application/json");
|
||||
});
|
||||
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration>
|
||||
|
||||
<Appenders>
|
||||
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} - [%t] - %5p - [%c{1}] - %msg%n" />
|
||||
</Console>
|
||||
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
|
||||
<Logger name="io.linuxserver.fleet" level="INFO" additivity="false">
|
||||
<AppenderRef ref="Console" />
|
||||
</Logger>
|
||||
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
||||
Loading…
x
Reference in New Issue
Block a user