Skip to content

Commit 6804ff2

Browse files
simplify, undo override
1 parent 3d7a832 commit 6804ff2

File tree

8 files changed

+330
-140
lines changed

8 files changed

+330
-140
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ SteVe is designed to run standalone, a java servlet container / web server (e.g.
7272
7373
3. Configure SteVe **before** building:
7474
75-
The basic configuration is defined in [application.properties](src/main/resources/application.properties):
76-
- You _must_ change [database configuration](src/main/resources/application.properties)
77-
- You _must_ change [the host](src/main/resources/application.properties) to the correct IP address of your server
78-
- You _must_ change [web interface credentials](src/main/resources/application.properties)
79-
- You _can_ access the application via HTTPS, by [enabling it and setting the keystore properties](src/main/resources/application.properties)
75+
The basic configuration is defined in [application-prod.properties](src/main/resources/application-prod.properties):
76+
- You _must_ change [database configuration](src/main/resources/application-prod.properties)
77+
- You _must_ change [the host](src/main/resources/application-prod.properties) to the correct IP address of your server
78+
- You _must_ change [web interface credentials](src/main/resources/application-prod.properties)
79+
- You _can_ access the application via HTTPS, by [enabling it and setting the keystore properties](src/main/resources/application-prod.properties)
8080
8181
For advanced configuration please see the [Configuration wiki](https://github.com/steve-community/steve/wiki/Configuration)
8282
@@ -101,7 +101,7 @@ SteVe is designed to run standalone, a java servlet container / web server (e.g.
101101
If you prefer to build and start this project via docker (you can skip the steps 1, 4 and 5 from above), this can be done as follows: `docker compose up -d`
102102
103103
Because the docker compose file is written to build the project for you, you still have to change the project configuration settings from step 3.
104-
Instead of changing the [application.properties](src/main/resources/application.properties), you have to change the [application-docker.properties](src/main/resources/application-docker.properties). There you have to change all configurations which are described in step 3.
104+
Instead of changing the [application-prod.properties](src/main/resources/application-prod.properties), you have to change the [application-docker.properties](src/main/resources/application-docker.properties). There you have to change all configurations which are described in step 3.
105105
The database password for the user "steve" has to be the same as you have configured it in the docker compose file.
106106
107107
With the default docker compose configuration, the web interface will be accessible at: `http://localhost:8180`

src/main/java/de/rwth/idsg/steve/SteveConfiguration.java

Lines changed: 29 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -62,100 +62,61 @@ public enum SteveConfiguration {
6262
private final Jetty jetty;
6363

6464
SteveConfiguration() {
65-
PropertiesFileLoader p = new PropertiesFileLoader("application.properties");
66-
profile = ApplicationProfile.fromName(p.getString("profile"));
67-
PropertiesFileLoader overriden = new PropertiesFileLoader("application-" + profile.name().toLowerCase() + ".properties");
65+
// Load the profile in order to load the correct application-<profile>.properties file
66+
String profileTemp = new PropertiesFileLoader("application.properties").getString("profile");
67+
68+
PropertiesFileLoader p = new PropertiesFileLoader("application-" + profileTemp.toLowerCase() + ".properties");
6869

69-
contextPath = sanitizeContextPath(getOptionalString("context.path", p, overriden));
70-
steveVersion = getString("steve.version", p, overriden);
71-
gitDescribe = useFallbackIfNotSet(getOptionalString("git.describe", p, overriden), null);
70+
contextPath = sanitizeContextPath(p.getOptionalString("context.path"));
71+
steveVersion = p.getString("steve.version");
72+
gitDescribe = useFallbackIfNotSet(p.getOptionalString("git.describe"), null);
7273

74+
profile = ApplicationProfile.fromName(p.getString("profile"));
7375
System.setProperty("spring.profiles.active", profile.name().toLowerCase());
74-
System.setProperty("logging.config", "classpath:logback-" + profile.name().toLowerCase() + ".xml");
7576

7677
jetty = Jetty.builder()
77-
.serverHost(getString("server.host", p, overriden))
78-
.gzipEnabled(getBoolean("server.gzip.enabled", p, overriden))
79-
.httpEnabled(getBoolean("http.enabled", p, overriden))
80-
.httpPort(getInt("http.port", p, overriden))
81-
.httpsEnabled(getBoolean("https.enabled", p, overriden))
82-
.httpsPort(getInt("https.port", p, overriden))
83-
.keyStorePath(getOptionalString("keystore.path", p, overriden))
84-
.keyStorePassword(getOptionalString("keystore.password", p, overriden))
78+
.serverHost(p.getString("server.host"))
79+
.gzipEnabled(p.getBoolean("server.gzip.enabled"))
80+
.httpEnabled(p.getBoolean("http.enabled"))
81+
.httpPort(p.getInt("http.port"))
82+
.httpsEnabled(p.getBoolean("https.enabled"))
83+
.httpsPort(p.getInt("https.port"))
84+
.keyStorePath(p.getOptionalString("keystore.path"))
85+
.keyStorePassword(p.getOptionalString("keystore.password"))
8586
.build();
8687

8788
db = DB.builder()
88-
.ip(getString("db.ip", p, overriden))
89-
.port(getInt("db.port", p, overriden))
90-
.schema(getString("db.schema", p, overriden))
91-
.userName(getString("db.user", p, overriden))
92-
.password(getString("db.password", p, overriden))
93-
.sqlLogging(getBoolean("db.sql.logging", p, overriden))
89+
.ip(p.getString("db.ip"))
90+
.port(p.getInt("db.port"))
91+
.schema(p.getString("db.schema"))
92+
.userName(p.getString("db.user"))
93+
.password(p.getString("db.password"))
94+
.sqlLogging(p.getBoolean("db.sql.logging"))
9495
.build();
9596

9697
PasswordEncoder encoder = new BCryptPasswordEncoder();
9798

9899
auth = Auth.builder()
99100
.passwordEncoder(encoder)
100-
.userName(getString("auth.user", p, overriden))
101-
.encodedPassword(encoder.encode(getString("auth.password", p, overriden)))
101+
.userName(p.getString("auth.user"))
102+
.encodedPassword(encoder.encode(p.getString("auth.password")))
102103
.build();
103104

104105
webApi = WebApi.builder()
105-
.headerKey(getOptionalString("webapi.key", p, overriden))
106-
.headerValue(getOptionalString("webapi.value", p, overriden))
106+
.headerKey(p.getOptionalString("webapi.key"))
107+
.headerValue(p.getOptionalString("webapi.value"))
107108
.build();
108109

109110
ocpp = Ocpp.builder()
110-
.autoRegisterUnknownStations(getOptionalBoolean("auto.register.unknown.stations", p, overriden))
111-
.chargeBoxIdValidationRegex(getOptionalString("charge-box-id.validation.regex", p, overriden))
111+
.autoRegisterUnknownStations(p.getOptionalBoolean("auto.register.unknown.stations"))
112+
.chargeBoxIdValidationRegex(p.getOptionalString("charge-box-id.validation.regex"))
112113
.wsSessionSelectStrategy(
113-
WsSessionSelectStrategyEnum.fromName(getString("ws.session.select.strategy", p, overriden)))
114+
WsSessionSelectStrategyEnum.fromName(p.getString("ws.session.select.strategy")))
114115
.build();
115116

116117
validate();
117118
}
118119

119-
private static String getOptionalString(String key, PropertiesFileLoader p, PropertiesFileLoader overriden) {
120-
String value = overriden.getOptionalString(key);
121-
if (value == null) {
122-
return p.getOptionalString(key);
123-
}
124-
return value;
125-
}
126-
127-
private static String getString(String key, PropertiesFileLoader p, PropertiesFileLoader overriden) {
128-
String value = overriden.getOptionalString(key);
129-
if (value == null) {
130-
return p.getString(key);
131-
}
132-
return value;
133-
}
134-
135-
private static boolean getOptionalBoolean(String key, PropertiesFileLoader p, PropertiesFileLoader overriden) {
136-
if (overriden.getOptionalString(key) == null) {
137-
return p.getOptionalBoolean(key);
138-
} else {
139-
return overriden.getOptionalBoolean(key);
140-
}
141-
}
142-
143-
private static boolean getBoolean(String key, PropertiesFileLoader p, PropertiesFileLoader overriden) {
144-
if (overriden.getOptionalString(key) == null) {
145-
return p.getBoolean(key);
146-
} else {
147-
return overriden.getOptionalBoolean(key);
148-
}
149-
}
150-
151-
private static int getInt(String key, PropertiesFileLoader p, PropertiesFileLoader overriden) {
152-
if (overriden.getOptionalString(key) == null) {
153-
return p.getInt(key);
154-
} else {
155-
return overriden.getInt(key);
156-
}
157-
}
158-
159120
public String getSteveCompositeVersion() {
160121
if (gitDescribe == null) {
161122
return steveVersion;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
1+
# Just to be backwards compatible with previous versions, this is set to "steve",
2+
# since there might be already configured chargepoints expecting the older path.
3+
# Otherwise, might as well be changed to something else or be left empty.
4+
#
5+
context.path =
6+
7+
# Database configuration
8+
#
9+
db.ip = localhost
10+
db.port = 3306
11+
db.schema = stevedb
12+
db.user = steve
13+
db.password = changeme
14+
15+
# Credentials for Web interface access
16+
#
17+
auth.user = admin
18+
auth.password = 1234
19+
20+
# The header key and value for Web API access using API key authorization.
21+
# Both must be set for Web APIs to be enabled. Otherwise, we will block all calls.
22+
#
23+
webapi.key = STEVE-API-KEY
24+
webapi.value =
25+
26+
# Jetty configuration
27+
#
28+
server.host = 127.0.0.1
29+
server.gzip.enabled = false
30+
31+
# Jetty HTTP configuration
32+
#
33+
http.enabled = true
34+
http.port = 8080
35+
36+
# Jetty HTTPS configuration
37+
#
38+
https.enabled = false
39+
https.port = 8443
40+
keystore.path =
41+
keystore.password =
42+
43+
# When the WebSocket/Json charge point opens more than one WebSocket connection,
44+
# we need a mechanism/strategy to select one of them for outgoing requests.
45+
# For allowed values see de.rwth.idsg.steve.ocpp.ws.custom.WsSessionSelectStrategyEnum.
46+
#
47+
ws.session.select.strategy = ALWAYS_LAST
48+
49+
# if BootNotification messages arrive (SOAP) or WebSocket connection attempts are made (JSON) from unknown charging
50+
# stations, we reject these charging stations, because stations with these chargeBoxIds were NOT inserted into database
51+
# beforehand. by setting this property to true, this behaviour can be modified to automatically insert unknown
52+
# stations into database and accept their requests.
53+
#
54+
# CAUTION: setting this property to true is very dangerous, because we will accept EVERY BootNotification or WebSocket
55+
# connection attempt from ANY sender as long as the sender knows the URL and sends a valid message.
56+
#
57+
auto.register.unknown.stations = false
58+
59+
# if this field is set, it will take precedence over the default regex we are using in
60+
# de.rwth.idsg.steve.web.validation.ChargeBoxIdValidator.REGEX to validate the format of the chargeBoxId values
61+
#
62+
charge-box-id.validation.regex =
63+
164
### DO NOT MODIFY ###
65+
steve.version = ${project.version}
66+
git.describe = ${git.commit.id.describe}
267
db.sql.logging = true
68+
profile = dev
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,68 @@
1+
# Just to be backwards compatible with previous versions, this is set to "steve",
2+
# since there might be already configured chargepoints expecting the older path.
3+
# Otherwise, might as well be changed to something else or be left empty.
4+
#
5+
context.path = steve
6+
17
# Database configuration
28
#
39
db.ip = mariadb
10+
db.port = 3306
11+
db.schema = stevedb
12+
db.user = steve
13+
db.password = changeme
14+
15+
# Credentials for Web interface access
16+
#
17+
auth.user = admin
18+
auth.password = 1234
19+
20+
# The header key and value for Web API access using API key authorization.
21+
# Both must be set for Web APIs to be enabled. Otherwise, we will block all calls.
22+
#
23+
webapi.key = STEVE-API-KEY
24+
webapi.value =
425

526
# Jetty configuration
627
#
728
server.host = 0.0.0.0
29+
server.gzip.enabled = false
830

931
# Jetty HTTP configuration
1032
#
33+
http.enabled = true
1134
http.port = 8180
35+
36+
# Jetty HTTPS configuration
37+
#
38+
https.enabled = false
39+
https.port = 8443
40+
keystore.path =
41+
keystore.password =
42+
43+
# When the WebSocket/Json charge point opens more than one WebSocket connection,
44+
# we need a mechanism/strategy to select one of them for outgoing requests.
45+
# For allowed values see de.rwth.idsg.steve.ocpp.ws.custom.WsSessionSelectStrategyEnum.
46+
#
47+
ws.session.select.strategy = ALWAYS_LAST
48+
49+
# if BootNotification messages arrive (SOAP) or WebSocket connection attempts are made (JSON) from unknown charging
50+
# stations, we reject these charging stations, because stations with these chargeBoxIds were NOT inserted into database
51+
# beforehand. by setting this property to true, this behaviour can be modified to automatically insert unknown
52+
# stations into database and accept their requests.
53+
#
54+
# CAUTION: setting this property to true is very dangerous, because we will accept EVERY BootNotification or WebSocket
55+
# connection attempt from ANY sender as long as the sender knows the URL and sends a valid message.
56+
#
57+
auto.register.unknown.stations = false
58+
59+
# if this field is set, it will take precedence over the default regex we are using in
60+
# de.rwth.idsg.steve.web.validation.ChargeBoxIdValidator.REGEX to validate the format of the chargeBoxId values
61+
#
62+
charge-box-id.validation.regex =
63+
64+
### DO NOT MODIFY ###
65+
steve.version = ${project.version}
66+
git.describe = ${git.commit.id.describe}
67+
db.sql.logging = false
68+
profile = prod

src/main/resources/application-kubernetes.properties

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Just to be backwards compatible with previous versions, this is set to "steve",
2+
# since there might be already configured chargepoints expecting the older path.
3+
# Otherwise, might as well be changed to something else or be left empty.
4+
#
5+
context.path = steve
6+
17
# Database configuration
28
#
39
db.ip=$DB_HOST
@@ -20,7 +26,43 @@ webapi.value=$WEBAPI_VALUE
2026
# Jetty configuration
2127
#
2228
server.host = 0.0.0.0
29+
server.gzip.enabled = false
2330

2431
# Jetty HTTP configuration
2532
#
33+
http.enabled = true
2634
http.port = 8180
35+
36+
# Jetty HTTPS configuration
37+
#
38+
https.enabled = false
39+
https.port = 8443
40+
keystore.path =
41+
keystore.password =
42+
43+
# When the WebSocket/Json charge point opens more than one WebSocket connection,
44+
# we need a mechanism/strategy to select one of them for outgoing requests.
45+
# For allowed values see de.rwth.idsg.steve.ocpp.ws.custom.WsSessionSelectStrategyEnum.
46+
#
47+
ws.session.select.strategy = ALWAYS_LAST
48+
49+
# if BootNotification messages arrive (SOAP) or WebSocket connection attempts are made (JSON) from unknown charging
50+
# stations, we reject these charging stations, because stations with these chargeBoxIds were NOT inserted into database
51+
# beforehand. by setting this property to true, this behaviour can be modified to automatically insert unknown
52+
# stations into database and accept their requests.
53+
#
54+
# CAUTION: setting this property to true is very dangerous, because we will accept EVERY BootNotification or WebSocket
55+
# connection attempt from ANY sender as long as the sender knows the URL and sends a valid message.
56+
#
57+
auto.register.unknown.stations = false
58+
59+
# if this field is set, it will take precedence over the default regex we are using in
60+
# de.rwth.idsg.steve.web.validation.ChargeBoxIdValidator.REGEX to validate the format of the chargeBoxId values
61+
#
62+
charge-box-id.validation.regex =
63+
64+
### DO NOT MODIFY ###
65+
steve.version = ${project.version}
66+
git.describe = ${git.commit.id.describe}
67+
db.sql.logging = false
68+
profile = prod

0 commit comments

Comments
 (0)