-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support environment variables for all supported system properties in a uniform way #126
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
framework-core/src/main/java/org/daisy/pipeline/properties/Properties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.daisy.pipeline.properties; | ||
|
||
import java.util.Map; | ||
|
||
public final class Properties { | ||
|
||
private Properties() { | ||
} | ||
|
||
// System.getProperties() returns an object that is always up to date | ||
private final static java.util.Properties systemProperties = System.getProperties(); | ||
private final static Map<String,String> systemEnv = System.getenv(); | ||
|
||
/** | ||
* Gets the system property or environment variable indicated by the specified key. | ||
* | ||
* If the key starts with "org.daisy.pipeline", the function first looks for an | ||
* environment variable and falls back to a system property. Otherwise it looks only | ||
* for a system property. The name of the environment variable is derived from the | ||
* name of the system property. | ||
* | ||
* For example, if the key is "org.daisy.pipeline.ws.host", an environment variable | ||
* "PIPELINE2_WS_HOST" will have precedence over the system property. | ||
* | ||
* @param key The name of the system property. | ||
* @return The string value of the system property or environment variable, or null if | ||
* there is no property or variable with that key. | ||
*/ | ||
public static String getProperty(String key) { | ||
return getProperty(key, null); | ||
} | ||
|
||
/** | ||
* @param key The name of the system property. | ||
* @param defaultValue A default value. | ||
* @return The string value of the system property or environment variable, or the | ||
* default value if there is no property or variable with that key. | ||
*/ | ||
public static String getProperty(String key, String defaultValue) { | ||
if (key == null) | ||
throw new NullPointerException(); | ||
if (key.startsWith("org.daisy.pipeline.")) { | ||
String envKey = "PIPELINE2_" + key.substring(19).replace('.', '_').toUpperCase(); | ||
if (systemEnv.containsKey(envKey)) | ||
return systemEnv.get(envKey); | ||
} | ||
return systemProperties.getProperty(key, defaultValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 38 additions & 17 deletions
55
webservice-utils/src/main/java/org/daisy/pipeline/webserviceutils/Properties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,43 @@ | ||
package org.daisy.pipeline.webserviceutils; | ||
|
||
public interface Properties { | ||
public static final String MAX_REQUEST_TIME = "org.daisy.pipeline.ws.maxrequesttime"; | ||
public static final String TMPDIR = "org.daisy.pipeline.ws.tmpdir"; | ||
public static final String AUTHENTICATION = "org.daisy.pipeline.ws.authentication"; | ||
public static final String LOCALFS= "org.daisy.pipeline.ws.localfs"; | ||
public static final String FRAMEWORK_VERSION="org.daisy.pipeline.version"; | ||
public static final String JAVA_IO_TMPDIR = "java.io.tmpdir"; | ||
public static final String PORT = "org.daisy.pipeline.ws.port"; | ||
public static final String PATH = "org.daisy.pipeline.ws.path"; | ||
public static final String HOST = "org.daisy.pipeline.ws.host"; | ||
public static final String SSL= "org.daisy.pipeline.ws.ssl"; | ||
public static final String SSL_KEYSTORE= "org.daisy.pipeline.ws.ssl.keystore"; | ||
public static final String SSL_KEYSTOREPASSWORD= "org.daisy.pipeline.ws.ssl.keystorepassword"; | ||
public static final String CLEAN_UP_ON_START_UP = "org.daisy.pipeline.ws.cleanuponstartup"; | ||
public enum Properties { | ||
|
||
public static final String SSL_KEYPASSWORD= "org.daisy.pipeline.ws.ssl.keypassword"; | ||
public static final String CLIENT_KEY= "org.daisy.pipeline.ws.authentication.key"; | ||
public static final String CLIENT_SECRET= "org.daisy.pipeline.ws.authentication.secret"; | ||
MAX_REQUEST_TIME("org.daisy.pipeline.ws.maxrequesttime"), | ||
TMPDIR("org.daisy.pipeline.ws.tmpdir"), | ||
AUTHENTICATION("org.daisy.pipeline.ws.authentication"), | ||
LOCALFS("org.daisy.pipeline.ws.localfs"), | ||
FRAMEWORK_VERSION("org.daisy.pipeline.version"), | ||
PORT("org.daisy.pipeline.ws.port"), | ||
PATH("org.daisy.pipeline.ws.path"), | ||
HOST("org.daisy.pipeline.ws.host"), | ||
SSL("org.daisy.pipeline.ws.ssl"), | ||
SSL_KEYSTORE("org.daisy.pipeline.ws.ssl.keystore"), | ||
SSL_KEYSTOREPASSWORD("org.daisy.pipeline.ws.ssl.keystorepassword"), | ||
CLEAN_UP_ON_START_UP("org.daisy.pipeline.ws.cleanuponstartup"), | ||
SSL_KEYPASSWORD("org.daisy.pipeline.ws.ssl.keypassword"), | ||
CLIENT_KEY("org.daisy.pipeline.ws.authentication.key"), | ||
CLIENT_SECRET("org.daisy.pipeline.ws.authentication.secret"); | ||
|
||
private final String key; | ||
|
||
private Properties(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String get() { | ||
return org.daisy.pipeline.properties.Properties.getProperty(key); | ||
} | ||
|
||
public String get(String defaultValue) { | ||
return org.daisy.pipeline.properties.Properties.getProperty(key, defaultValue); | ||
} | ||
|
||
public String getName() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see API change in the
webservice
module, am I correct that the major change is due to change in the web service payload?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember TBH. Might be a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember now. It's because I changed the
Properties
class into an enum.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!