From 749cf48f4bf5cc5f7e8cb3f0f8ad53fe151b5839 Mon Sep 17 00:00:00 2001 From: FireMaskterK <20838718+FireMasterK@users.noreply.github.com> Date: Tue, 23 Nov 2021 00:21:18 +0000 Subject: [PATCH] Read properties from environment if available. Closes https://github.com/TeamPiped/Piped/issues/638 --- .../java/me/kavin/piped/consts/Constants.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index 604554b..664fce2 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -55,16 +55,17 @@ public class Constants { YOUTUBE_SERVICE = NewPipe.getService(0); prop.load(new FileReader("config.properties")); - PORT = Integer.parseInt(prop.getProperty("PORT", "8080")); - HTTP_WORKERS = prop.getProperty("HTTP_WORKERS", String.valueOf(Runtime.getRuntime().availableProcessors())); - PROXY_PART = prop.getProperty("PROXY_PART"); - CAPTCHA_BASE_URL = prop.getProperty("CAPTCHA_BASE_URL"); - CAPTCHA_API_KEY = prop.getProperty("CAPTCHA_API_KEY"); - PUBLIC_URL = prop.getProperty("API_URL"); - HTTP_PROXY = prop.getProperty("HTTP_PROXY"); - FRONTEND_URL = prop.getProperty("FRONTEND_URL", "https://pipedapi.kavin.rocks"); - COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(prop.getProperty("COMPROMISED_PASSWORD_CHECK", "true")); - DISABLE_REGISTRATION = Boolean.parseBoolean(prop.getProperty("DISABLE_REGISTRATION", "false")); + PORT = Integer.parseInt(getProperty(prop, "PORT", "8080")); + HTTP_WORKERS = getProperty(prop, "HTTP_WORKERS", + String.valueOf(Runtime.getRuntime().availableProcessors())); + PROXY_PART = getProperty(prop, "PROXY_PART"); + CAPTCHA_BASE_URL = getProperty(prop, "CAPTCHA_BASE_URL"); + CAPTCHA_API_KEY = getProperty(prop, "CAPTCHA_API_KEY"); + PUBLIC_URL = getProperty(prop, "API_URL"); + HTTP_PROXY = getProperty(prop, "HTTP_PROXY"); + FRONTEND_URL = getProperty(prop, "FRONTEND_URL", "https://pipedapi.kavin.rocks"); + COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(getProperty(prop, "COMPROMISED_PASSWORD_CHECK", "true")); + DISABLE_REGISTRATION = Boolean.parseBoolean(getProperty(prop, "DISABLE_REGISTRATION", "false")); prop.forEach((_key, _value) -> { String key = String.valueOf(_key), value = String.valueOf(_value); if (key.startsWith("hibernate")) @@ -85,4 +86,18 @@ public class Constants { throw new RuntimeException(e); } } + + private static final String getProperty(final Properties prop, String key) { + return getProperty(prop, key, null); + } + + private static final String getProperty(final Properties prop, String key, String def) { + + final String envVal = System.getenv(key); + + if (envVal != null) + return envVal; + + return prop.getProperty(key, def); + } }