Skip to content

Commit 1d3750b

Browse files
Fix Literal Quotes in Env Vars
Fixes: #503
1 parent 77fff4f commit 1d3750b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/main/java/de/medizininformatikinitiative/torch/config/TorchProperties.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,26 @@ public record TorchProperties(
2525
@NotBlank(message = "DSE mapping tree file path is required") String dseMappingTreeFile,
2626
boolean useCql
2727
) {
28+
private static final String EMPTY_QUOTES = "\"\"";
29+
30+
private static boolean isNotSet(String variable) {
31+
return variable == null || variable.isBlank() || EMPTY_QUOTES.equals(variable);
32+
}
33+
2834
public TorchProperties {
2935
if (!useCql) {
3036
if (flare == null) {
3137
throw new IllegalArgumentException("When useCql is false, flare.url must be a non-empty string");
3238
}
33-
if (flare.url() == null || flare.url().isBlank()) {
39+
if (isNotSet(flare.url())) {
3440
throw new IllegalArgumentException("When useCql is false, flare.url must be a non-empty string");
3541
}
3642
}
3743

3844
if (fhir == null) {
3945
throw new IllegalArgumentException("FHIR URL must not be null or empty");
4046
}
41-
if (fhir.url() == null || fhir.url().isBlank()) {
47+
if (isNotSet(fhir.url())) {
4248
throw new IllegalArgumentException("FHIR URL must not be null or empty");
4349
}
4450
}
@@ -74,8 +80,8 @@ public record Fhir(
7480
String password) {
7581

7682
public Fhir {
77-
if (user == null) user = "";
78-
if (password == null) password = "";
83+
if (isNotSet(user)) user = "";
84+
if (isNotSet(password)) password = "";
7985
if (oauth == null) {
8086
oauth = new Oauth(new Oauth.Issuer(""), new Oauth.Client("", ""));
8187
}
@@ -96,14 +102,14 @@ public record Oauth(@Valid Issuer issuer, @Valid Client client) {
96102

97103
public record Issuer(String uri) {
98104
public Issuer {
99-
if (uri == null) uri = "";
105+
if (isNotSet(uri)) uri = "";
100106
}
101107
}
102108

103109
public record Client(String id, String secret) {
104110
public Client {
105-
if (id == null) id = "";
106-
if (secret == null) secret = "";
111+
if (isNotSet(id)) id = "";
112+
if (isNotSet(secret)) secret = "";
107113
}
108114
}
109115
}

0 commit comments

Comments
 (0)