Skip to content

Commit

Permalink
Better resilience for env flags parse (#338)
Browse files Browse the repository at this point in the history
* Accepting true case insensitive as a valid flag and documenting it

* Testing

* release notes

* [Gradle Release Plugin] - new version commit:  '3.8.0'.
  • Loading branch information
mageddo authored Mar 4, 2023
1 parent 080e453 commit cf73fe8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ or via docker looking at [Dockerhub images][3].

Basic running it on Linux or Mac
```bash
$ curl -s -L https://github.com/mageddo/dns-proxy-server/releases/download/3.7.0/dns-proxy-server-linux-amd64-3.7.0.tgz | tar -vzx &&\
$ curl -s -L https://github.com/mageddo/dns-proxy-server/releases/download/3.8.0/dns-proxy-server-linux-amd64-3.8.0.tgz | tar -vzx &&\
sudo ./dns-proxy-server
```

Expand Down
5 changes: 4 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### 3.8.0
* Now you're able to activate flags by using `1` or `true` (case insenstive), [see the docs](http://mageddo.github.io/dns-proxy-server/latest/en/3-configuration/#environment-variable-configuration).

### 3.7.0
* Support to configure DPS as default DNS Server on MacOS, [see the docs]()
* Support to configure DPS as default DNS Server on MacOS, [see the docs](http://mageddo.github.io/dns-proxy-server/latest/en/1-getting-started/running-it/#running-on-mac)

### 3.6.0
* Configure DPS at system-resolved with a custom port when is necessary
Expand Down
6 changes: 5 additions & 1 deletion docs/content/3-configuration/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ __Version 1__

### Environment variable configuration

Boolean values
> You can use `1` or `true` (case insensitive) to specify which the flag is activated, any other
value will be considered false.

| VARIBLE | DESCRIPTION | DEFAULT VALUE |
|-----------------------------|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| MG_RESOLVCONF | Linux resolvconf path to set DPS as default DNS | /host/etc/systemd/resolved.conf,/host/etc/resolv.conf,/etc/systemd/resolved.conf,/etc/resolv.conf |
| MG_RESOLVCONF | Linux resolvconf or systemd-resolved path to set DPS as default DNS | /host/etc/systemd/resolved.conf,/host/etc/resolv.conf,/etc/systemd/resolved.conf,/etc/resolv.conf |
| MG_LOG_LEVEL | | INFO |
| MG_LOG_FILE | Path where to logs will be stored | console |
| MG_REGISTER_CONTAINER_NAMES | if should register container name / service name as a hostname | false |
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.7.0
version=3.8.0
quarkusPluginId=io.quarkus
quarkusPluginVersion=2.16.0.Final
quarkusPlatformGroupId=io.quarkus.platform
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/mageddo/dnsproxyserver/utils/Envs.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ public static String getStringOrNull(String env) {

public static Boolean getBooleanOrNull(String env) {
final var v = StringUtils.trimToEmpty(System.getenv(env));
return parseBoolean(v);
}

static Boolean parseBoolean(String v) {
if(StringUtils.isBlank(v)){
return null;
}
return Objects.equals(v, "1");
return Objects.equals(v, "1") || StringUtils.equalsIgnoreCase(v, "true");
}

public static String getStringOrDefault(String env, String def) {
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/com/mageddo/dnsproxyserver/utils/EnvsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mageddo.dnsproxyserver.utils;

import org.junit.jupiter.api.Test;

import static com.mageddo.dnsproxyserver.utils.Envs.parseBoolean;
import static org.junit.jupiter.api.Assertions.*;

class EnvsTest {

@Test
void mustParseAsTrue(){
// arrange

// act
// assert
assertTrue(parseBoolean("true"));
assertTrue(parseBoolean("TRUE"));
assertTrue(parseBoolean("TRuE"));
assertTrue(parseBoolean("1"));
}

@Test
void mustParseAsFalse(){
// arrange

// act
// assert
assertFalse(parseBoolean("dps"));
assertFalse(parseBoolean("0"));
assertFalse(parseBoolean("!"));
assertFalse(parseBoolean("FALSE"));
assertFalse(parseBoolean("false"));
}

@Test
void mustParseAsNull(){
// arrange

// act
// assert
assertNull(parseBoolean(""));
}
}

0 comments on commit cf73fe8

Please sign in to comment.