This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropertiesManager.java
88 lines (72 loc) · 2.89 KB
/
PropertiesManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package utility;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
/**
* Utility class for config.properties management
*/
public class PropertiesManager {
private final static String PROPERTIES_PATH = "config.properties";
private final static int MISSING_PROPERTIES_FILE_ERROR_CODE = 15;
// singleton instance: no need to reload file at each call
private static PropertiesManager singletonInstance = null;
private Properties properties = null;
/**
* Property keys
*/
public static final String DOCKER_COMPOSE_DIR = "docker_compose_dir";
public static final String MYSQL_IP = "mysql_ip";
public static final String MYSQL_PORT = "mysql_port";
public static final String MYSQL_USR = "mysql_user";
public static final String MYSQL_PASS = "mysql_password";
public static final String MYSQL_DB = "mysql_dbname";
public static final String INFLUX_IP = "influx_ip";
public static final String INFLUX_PORT = "influx_port";
public static final String INFLUX_USR = "influx_user";
public static final String INFLUX_PASS = "influx_password";
public static final String INFLUX_DB = "influx_dbname";
public static final String GOOGLE_CONTAINER = "google_cloud_cli_container_name";
public static final String GOOGLE_STAGE_BUCKET = "google_cloud_stage_bucket";
public static final String GOOGLE_AUTH_JSON = "google_cloud_auth_json_path";
public static final String AWS_AUTH_CONFIG = "aws_auth_folder_path";
public static final String AWS_LAMBDA_EXEC_ROLE = "aws_lambda_execution_role";
public static final String AWS_STEP_FUNCTIONS_EXEC_ROLE = "aws_step_functions_execution_role";
public static final String GOOGLE_HANDLER_PATH = "google_handler_function_path";
public static final String AWS_HANDLER_PATH = "aws_handler_function_path";
public static final String OPENWHISK_HOST = "openwhisk_host";
public static final String OPENWHISK_AUTH = "openwhisk_auth";
public static final String OPENWHISK_SSL_IGNORE = "openwhisk_ignore_ssl";
/**
* Singleton instance getter
* @return PropertyManager run-wide unique instance
*/
public static PropertiesManager getInstance() {
if (singletonInstance == null) {
singletonInstance = new PropertiesManager();
}
return singletonInstance;
}
/**
* Private default constructor. Only getInstance() method can access it
*/
private PropertiesManager() {
}
/**
* Getter for property value
* @param propertyKey property key associated to the property of interest
* @return property value of interest
*/
public String getProperty(String propertyKey) {
try {
if (properties == null) {
properties = new Properties();
properties.load(new FileReader(PROPERTIES_PATH));
}
return properties.getProperty(propertyKey);
} catch (IOException ignored) {
System.err.println("Error in configuration file! Please check " + PROPERTIES_PATH);
System.exit(MISSING_PROPERTIES_FILE_ERROR_CODE);
return "";
}
}
}